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

查看:24
本文介绍了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"
              ]
            ]
          }
        }
      }

这只是一个示例来说明.当堆栈显示为完成时,此处的 ansible-playbook 命令仍在执行中.有什么方法可以延迟堆栈上的创建条件,以确保首先执行所有用户数据.我尝试使用 wait condition 但它没有给出想要的结果.

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天全站免登陆