1

私は、人形をインストールし、aws人形モジュールをインストールする雲のテンプレートを作成しようとしています。私は人形でインスタンスを作成し、セキュリティグループなどを定義することができます。それはうまくいくようですが、テンプレートの一部としてaws puppetモジュールもインストールしたいと考えています。 これは、しかし、私は人形がインストールされた後、以下のコマンドを実行したい、私の人形のインスタンスのコード雲形テンプレートの実行順序?

"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" 
      ] 
     ] 
     } 
    } 
    } 
} 

これが正常に動作している:

"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"の内部にコードを入れようとしました:しかし、もう一度失敗しました。テンプレートのさまざまなセクションの実行順序に関する情報を見つけることができず、失敗が実行順序が間違っていると仮定します(コマンド実行時に人形&ルビーはインストールされません)。

ご協力いただければ幸いです。

+0

私はこの事例を書く時間がありませんが、私は最初に、インストールを明示的に待つシェルスクリプトを書きます。実行の順序は、クラウドのinitのためです。この回答を参照してください。http://stackoverflow.com/questions/34095839/cloud-init-what-is-the-execution-order-of-cloud-config-directives – Vorsprung

+0

提案。私はテンプレート内にすべてを持っている必要があります。サービスがインストールされているかどうかをチェックする唯一の方法は、サービスが実行されているかどうかをチェックする無限ループを書くことですが、テンプレートの実行がブロックされ、すべてが無限ループを待って終了し、サービスがループから抜け出すのを待っています...インスタンスパッケージのインストール後にスクリプトを実行する適切な方法が必要です。 。 – martini

答えて

1

awsフォーラムでは、実行順序に関して非常に有益な投稿がありました。 AWS CloudFormation :: :: initは次の順序で実行します。

パッケージ - >グループ - > users->ソース - >ファイル - >コマンド - >サービス

ソース:https://forums.aws.amazon.com/message.jspa?messageID=414670

私は問題を修正方法は、おそらく理想からかけ離れているが、それは動作します:

"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" 
      ] 
     ] 
     } 
    } 
    } 
} 

私はインストールして、人形のANを構成するために必要なすべてを実行することができていますconfigSetsの実行順序を指定することでdの後に、プラグインをインストールするコマンドを実行します。