Templates 云计算模板执行顺序?
我正在尝试创建一个cloudformation模板,安装puppet和aws puppet模块。我可以用puppet创建我的实例,定义安全组等,它似乎工作得很好,但我还想安装aws puppet模块作为模板的一部分。 这是我的puppet实例的代码Templates 云计算模板执行顺序?,templates,amazon-web-services,puppet,amazon-cloudformation,Templates,Amazon Web Services,Puppet,Amazon Cloudformation,我正在尝试创建一个cloudformation模板,安装puppet和aws puppet模块。我可以用puppet创建我的实例,定义安全组等,它似乎工作得很好,但我还想安装aws puppet模块作为模板的一部分。 这是我的puppet实例的代码 "PuppetMasterInstance" : { "Type" : "AWS::EC2::Instance", "Metadata" : { "AWS::CloudFormation::Init" : { "c
"PuppetMasterInstance" : {
"Type" : "AWS::EC2::Instance",
"Metadata" : {
"AWS::CloudFormation::Init" : {
"config" : {
"packages" : {
"yum" : {
"puppet3" : [],
"puppet3-server" : [],
"ruby-devel" : [],
"gcc" : [],
"make" : [],
"rubygems" : []
},
"rubygems" : {
"json" : []
}
},
"files": {
"/etc/yum.repos.d/epel.repo": {
"source": "https://s3.amazonaws.com/cloudformation-examples/enable-epel-on-amazon-linux-ami",
"mode": "000644",
"owner": "root",
"group": "root"
},
"/etc/puppet/autosign.conf": {
"content": "*.internal\n",
"mode": "100644",
"owner": "root",
"group": "wheel"
},
"/etc/puppet/fileserver.conf": {
"content": "[modules]\n allow *.internal\n",
"mode": "100644",
"owner": "root",
"group": "wheel"
},
"/etc/puppet/puppet.conf": {
"content": {
"Fn::Join": [
"",
[
"[main]\n",
" logdir=/var/log/puppet\n",
" rundir=/var/run/puppet\n",
" ssldir=$vardir/ssl\n",
" pluginsync=true\n",
"[agent]\n",
" classfile=$vardir/classes.txt\n",
" localconfig=$vardir/localconfig\n"
]
]
},
"mode": "000644",
"owner": "root",
"group": "root"
},
"/etc/puppet/modules/cfn/manifests/init.pp": {
"content": "class cfn {}",
"mode": "100644",
"owner": "root",
"group": "wheel"
},
"/etc/puppet/modules/cfn/lib/facter/cfn.rb": {
"source": "https://s3.amazonaws.com/cloudformation-examples/cfn-facter-plugin.rb",
"mode": "100644",
"owner": "root",
"group": "wheel"
}
},
"services": {
"sysvinit": {
"puppetmaster": {
"enabled": "true",
"ensureRunning": "true"
}
}
}
}
}
},
"Properties": {
"InstanceType": {
"Ref": "InstanceType"
},
"SecurityGroups": [
{
"Ref": "PuppetGroup"
}
],
"ImageId": {
"Ref": "AmiID"
},
"KeyName": {
"Ref": "KeyName"
},
"UserData": {
"Fn::Base64": {
"Fn::Join": [
"",
[
"#!/bin/bash\n",
"yum update -y \n",
"/opt/aws/bin/cfn-init --region ",
{
"Ref": "AWS::Region"
},
" -s ",
{
"Ref": "AWS::StackName"
},
" -r PuppetMasterInstance ",
" --access-key ",
{
"Ref": "CFNKeys"
},
" --secret-key ",
{
"Fn::GetAtt": [
"CFNKeys",
"SecretAccessKey"
]
},
"\n",
"/opt/aws/bin/cfn-signal -e $? '",
{
"Ref": "PuppetMasterWaitHandle"
},
"'\n"
]
]
}
}
}
}
这很好,但是我希望在安装puppet后执行以下命令:
"gem install aws-sdk-core",
"gem install retries",
"export AWS_ACCESS_KEY_ID=my_key",
"export AWS_SECRET_ACCESS_KEY=my_secret",
"puppet module install puppetlabs-aws"
我尝试在“文件:”之前使用“命令:”标记,但模板失败。我试图将代码放入“UserData”中:但再次失败。我在模板中找不到关于不同部分的执行顺序的信息,我假设失败是由于执行顺序错误(在命令运行时未安装puppet和ruby)
任何帮助都将不胜感激 我在aws论坛上找到了一篇关于执行顺序的内容丰富的帖子。AWS::CloudFormation::Init按以下顺序执行: 包->组->用户->源->文件->命令->服务 资料来源: 我解决问题的方法可能远不理想,但它是有效的:
"PuppetMasterInstance" : {
"Type" : "AWS::EC2::Instance",
"Metadata" : {
"AWS::CloudFormation::Init" : {
"configSets" : {
"ascending" : [ "config" , "config2" ],
"descending" : [ "config2" , "config" ]
},
"config" : {
"packages" : {
"yum" : {
"puppet3" : [],
"puppet3-server" : [],
"ruby-devel" : [],
"gcc" : [],
"make" : [],
"rubygems" : []
},
"rubygems" : {
"json" : []
}
},
"files": {
"/etc/yum.repos.d/epel.repo": {
"source": "https://s3.amazonaws.com/cloudformation-examples/enable-epel-on-amazon-linux-ami",
"mode": "000644",
"owner": "root",
"group": "root"
},
"/etc/puppet/autosign.conf": {
"content": "*.internal\n",
"mode": "100644",
"owner": "root",
"group": "wheel"
},
"/etc/puppet/fileserver.conf": {
"content": "[modules]\n allow *.internal\n",
"mode": "100644",
"owner": "root",
"group": "wheel"
},
"/etc/puppet/puppet.conf": {
"content": {
"Fn::Join": [
"",
[
"[main]\n",
" logdir=/var/log/puppet\n",
" rundir=/var/run/puppet\n",
" ssldir=$vardir/ssl\n",
" pluginsync=true\n",
"[agent]\n",
" classfile=$vardir/classes.txt\n",
" localconfig=$vardir/localconfig\n"
]
]
},
"mode": "000644",
"owner": "root",
"group": "root"
},
"/etc/puppet/modules/cfn/manifests/init.pp": {
"content": "class cfn {}",
"mode": "100644",
"owner": "root",
"group": "wheel"
},
"/etc/puppet/modules/cfn/lib/facter/cfn.rb": {
"source": "https://s3.amazonaws.com/cloudformation-examples/cfn-facter-plugin.rb",
"mode": "100644",
"owner": "root",
"group": "wheel"
}
},
"services": {
"sysvinit": {
"puppetmaster": {
"enabled": "true",
"ensureRunning": "true"
}
}
}
},
"config2" : {
"commands" : {
"1" : {
"command" : "gem install aws-sdk-core"
},
"2" : {
"command" : "gem install retries"
},
"3" : {
"command" : "export _MYAWSKEY_"
},
"4" : {
"command" : "export MY_AWS_SECRET_"
},
"5" : {
"command" : "puppet module install puppetlabs-aws"
}
}
}
}
},
"Properties": {
"InstanceType": {
"Ref": "InstanceType"
},
"SecurityGroups": [
{
"Ref": "PuppetGroup"
}
],
"ImageId": {
"Ref": "AmiID"
},
"KeyName": {
"Ref": "KeyName"
},
"UserData": {
"Fn::Base64": {
"Fn::Join": [
"",
[
"#!/bin/bash\n",
"yum update -y \n",
"/opt/aws/bin/cfn-init -c ascending --region ",
{
"Ref": "AWS::Region"
},
" -s ",
{
"Ref": "AWS::StackName"
},
" -r PuppetMasterInstance ",
" --access-key ",
{
"Ref": "CFNKeys"
},
" --secret-key ",
{
"Fn::GetAtt": [
"CFNKeys",
"SecretAccessKey"
]
},
"\n",
"/opt/aws/bin/cfn-signal -e $? '",
{
"Ref": "PuppetMasterWaitHandle"
},
"'\n"
]
]
}
}
}
}
通过指定配置集的执行顺序,我可以运行安装和配置puppet所需的一切,然后运行命令来安装插件 我没有时间写一个这样的例子,但我的第一个想法是写一点shell脚本,明确地等待安装。执行顺序是cloud init,请参阅此答案,谢谢您的建议。我需要将所有内容都放在我的模板中,检查服务是否安装的唯一方法是编写无限循环,在其中检查服务是否正在运行,然而,我认为这将阻止模板的执行,整个过程最终将等待一个无限循环完成,而这个无限循环又在等待一个服务被安装,从而打破循环…在安装实例包之后,必须有一个正确的方法来执行我的脚本。。。