Cloudformation堆栈在执行所有用户数据之前显示为已完成 [英] Cloudformation stack shows as complete before execution of all user data

查看:56
本文介绍了Cloudformation堆栈在执行所有用户数据之前显示为已完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的cloudformation堆栈中,我有一个启动配置,该配置在用户数据中运行ansible脚本。这里的问题是,即使ansible脚本尚未完成执行,我的堆栈状态仍显示 CREATE_COMPLETE 。在ssh进入ec2实例后,我看到了显示ansible执行仍在进行中的日志。我的示例cloudformation堆栈json是这样的:

In my cloudformation stack, I have a launch config which runs ansible scripts in the user data. The problem here is, my stack status shows CREATE_COMPLETE even if the ansible scripts have not completed exacution. After I ssh into the ec2 instance, I see the logs which shows the ansible execution still in progress. My sample cloudformation stack json is something like this:

"OpenShiftMasterASLaunchConfig": {
      "Type": "AWS::AutoScaling::LaunchConfiguration",
      "Metadata": {
        "AWS::CloudFormation::Init": {
          "configSets": {
            "quickstart": ["GetPublicKey", "AddPublicKey", "rpms", "ConfigSSHD", "DockerGroup", "DockerSecurity", "InstallAWSCLI", "SetPrivateKey", "StartServices"]
          },
          "rpms": {
            "packages": {
              "yum": {
                "epel-release": [],
                "NetworkManager": [],
                "ansible": [],
                "docker": [],
                "git": [],
                "python-boto": [],
                "python-cryptography": [],
                "python-lxml": [],
                "python-pip": [],
                "origin-docker-excluder": [],
                "centos-release-openshift-origin": [],
                "atomic-openshift-utils": [],
                "origin-clients": [],
                "awslogs" : []
              }
            }
          },
          "Properties": {
        "AssociatePublicIpAddress" : "true",
        "KeyName": {
          "Ref": "KeyPairName"
        },
        "ImageId": {
          "Fn::FindInMap": [
            "AWSAMIRegionMap",
            {
              "Ref": "AWS::Region"
            },
            "CENTOS7HVM"
          ]
        },
        "BlockDeviceMappings": [{
          "DeviceName": "/dev/sda1",
          "Ebs": {
            "VolumeSize": "100"
          }
        }],
        "InstanceMonitoring": "true",
        "IamInstanceProfile": {
          "Ref": "SetupRoleProfile"
        },
        "InstanceType": {
          "Ref": "MasterInstanceType"
        },
        "SecurityGroups": [{
          "Ref": "OpenShiftSecurityGroup"
        }],
        "UserData": {
          "Fn::Base64": {
            "Fn::Join": [
              "", [
                "bash /local/scripts/openshift-origin-bootstrap-master.sh\n",

                "ansible-playbook -i /local/ansible/inventory/hosts.cluster /local/openshift-ansible/playbooks/prerequisites.yml >> /local/prereq.log\n",

                "ansible-playbook -i /local/ansible/inventory/hosts.cluster /local/openshift-ansible/playbooks/deploy_cluster.yml -vvv > /local/cluster.log\n",

                "bash /local/scripts/configure_openebs.sh\n"
              ]
            ]
          }
        }
      }

这只是一个示例。 c> ansible-playbook 命令在堆栈显示为已完成时仍在执行中,是否有任何方法可以延迟堆栈上的创建条件以确保首先执行所有用户数据。尝试使用 wait条件,但未达到预期效果。

This is just a sample to illustrate. The ansible-playbook commands here, are still under execution when the stack shows as completed. Is there any way to delay the create condition on the stack to make sure all the user data is executed first. I tried using the wait condition but it is not giving the desired result.

推荐答案

CreationPolicy 与资源相关联以防止其状态达到创建完成状态,直到您的用户数据脚本发出CloudFormation信号(在用户数据末尾)为止。这是示例

Associate a CreationPolicy with your resource to prevent its status from reaching 'create complete' until your userdata script signals CloudFormation (at the end of userdata). Here's an example.

这篇关于Cloudformation堆栈在执行所有用户数据之前显示为已完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆