gpt4 book ai didi

amazon-web-services - AWS : Simple cfn-init fails on Amazon Linux 2 for no apparent reason

转载 作者:行者123 更新时间:2023-12-04 08:04:05 25 4
gpt4 key购买 nike

我正在配置一个cloudformation堆栈。我只是尝试在使用基于 Amazon Linux 2 的自定义 ami 启动的实例上运行尽可能简单的 cfn-init:

 EC2ESMasterNode1:
Type: AWS::EC2::Instance
Metadata:
Comment: ES Cluster Master 1 instance
AWS::CloudFormation::Init:
config:
commands:
01_template_elastic:
command:
!Sub |
echo "'Hello World'"
Properties:
ImageId: ami-09693313102a30b2c
InstanceType: !Ref MasterInstanceType
SubnetId: !Ref Subn1ID
SecurityGroupIds: [!Ref SGES]
KeyName: mykey
UserData:
"Fn::Base64":
!Sub |
#!/bin/bash -xe
# Start cfn-init
/opt/aws/bin/cfn-init -s ${AWS::StackName} --resource EC2ESMasterNode1 --region ${AWS::Region}
# Send the respective signal to Cloudformation
/opt/aws/bin/cfn-signal -e 0 --stack ${AWS::StackName} --resource EC2ESMasterNode1 --region ${AWS::Region}
Tags:
- Key: "Name"
Value: !Ref Master1NodeName

/var/log/cloud-init-output.log 具有以下打印内容

No packages needed for security; 15 packages available
Resolving Dependencies
Cloud-init v. 18.2-72.amzn2.0.6 running 'modules:final' at Wed, 02 Jan 2019 12:41:26 +0000. Up 14.42 seconds.
+ /opt/aws/bin/cfn-init -s test-elastic --resource EC2ESMasterNode1 --region eu-west-1
+ /opt/aws/bin/cfn-signal -e 0 --stack test-elastic --resource EC2ESMasterNode1 --region eu-west-1
ValidationError: Stack arn:aws:cloudformation:eu-west-1:248059334340:stack/test-elastic/9fc79150-0e8b-11e9-b135-503ac9e74cfd is in CREATE_COMPLETE state and cannot be signaled
Jan 02 12:41:27 cloud-init[2575]: util.py[WARNING]: Failed running /var/lib/cloud/instance/scripts/part-001 [1]
Jan 02 12:41:27 cloud-init[2575]: cc_scripts_user.py[WARNING]: Failed to run module scripts-user (scripts in /var/lib/cloud/instance/scripts)
Jan 02 12:41:27 cloud-init[2575]: util.py[WARNING]: Running module scripts-user (<module 'cloudinit.config.cc_scripts_user' from '/usr/lib/python2.7/site-packages/cloudinit/config/cc_scripts_user.pyc'>) failed
Cloud-init v. 18.2-72.amzn2.0.6 finished at Wed, 02 Jan 2019 12:41:27 +0000. Datasource DataSourceEc2. Up 15.30 seconds

/var/log/cloud-init.log 存在以下错误:

    Jan 02 12:41:26 cloud-init[2575]: handlers.py[DEBUG]: start: modules-final/config-scripts-user: running config-scripts-user with frequency once-per-instance
Jan 02 12:41:26 cloud-init[2575]: util.py[DEBUG]: Writing to /var/lib/cloud/instances/i-0c10a5ff1be475b99/sem/config_scripts_user - wb: [644] 20 bytes
Jan 02 12:41:26 cloud-init[2575]: helpers.py[DEBUG]: Running config-scripts-user using lock (<FileLock using file '/var/lib/cloud/instances/i-0c10a5ff1be475b99/sem/config_scripts_user'>)
Jan 02 12:41:26 cloud-init[2575]: util.py[DEBUG]: Running command ['/var/lib/cloud/instance/scripts/part-001'] with allowed return codes [0] (shell=True, capture=False)
Jan 02 12:41:27 cloud-init[2575]: util.py[WARNING]: Failed running /var/lib/cloud/instance/scripts/part-001 [1]
Jan 02 12:41:27 cloud-init[2575]: util.py[DEBUG]: Failed running /var/lib/cloud/instance/scripts/part-001 [1]
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/cloudinit/util.py", line 860, in runparts
subp(prefix + [exe_path], capture=False, shell=True)
File "/usr/lib/python2.7/site-packages/cloudinit/util.py", line 2053, in subp
cmd=args)
ProcessExecutionError: Unexpected error while running command.
Command: ['/var/lib/cloud/instance/scripts/part-001']
Exit code: 1
Reason: -
Stdout: -
Stderr: -
Jan 02 12:41:27 cloud-init[2575]: cc_scripts_user.py[WARNING]: Failed to run module scripts-user (scripts in /var/lib/cloud/instance/scripts)
Jan 02 12:41:27 cloud-init[2575]: handlers.py[DEBUG]: finish: modules-final/config-scripts-user: FAIL: running config-scripts-user with frequency once-per-instance
Jan 02 12:41:27 cloud-init[2575]: util.py[WARNING]: Running module scripts-user (<module 'cloudinit.config.cc_scripts_user' from '/usr/lib/python2.7/site-packages/cloudinit/config/cc_scripts_user.pyc'>) failed
Jan 02 12:41:27 cloud-init[2575]: util.py[DEBUG]: Running module scripts-user (<module 'cloudinit.config.cc_scripts_user' from '/usr/lib/python2.7/site-packages/cloudinit/config/cc_scripts_user.pyc'>) failed
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/cloudinit/stages.py", line 798, in _run_modules
freq=freq)
File "/usr/lib/python2.7/site-packages/cloudinit/cloud.py", line 54, in run
return self._runners.run(name, functor, args, freq, clear_on_fail)
File "/usr/lib/python2.7/site-packages/cloudinit/helpers.py", line 187, in run
results = functor(*args)
File "/usr/lib/python2.7/site-packages/cloudinit/config/cc_scripts_user.py", line 45, in handle
util.runparts(runparts_path)
File "/usr/lib/python2.7/site-packages/cloudinit/util.py", line 867, in runparts
% (len(failed), len(attempted)))
RuntimeError: Runparts: 1 failures in 1 attempted commands
Jan 02 12:41:27 cloud-init[2575]: stages.py[DEBUG]: Running module ssh-authkey-fingerprints (<module 'cloudinit.config.cc_ssh_authkey_fingerprints' from '/usr/lib/python2.7/site-packages/cloudinit/config/cc_ssh_authkey_fingerprints.pyc'>) with frequency once-per-instance

_

cat /var/log/cfn-init-cmd.log
2019-01-02 12:50:54,777 P2582 [INFO] ************************************************************
2019-01-02 12:50:54,777 P2582 [INFO] ConfigSet default
2019-01-02 12:50:54,778 P2582 [INFO] ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2019-01-02 12:50:54,778 P2582 [INFO] Config config
2019-01-02 12:50:54,778 P2582 [INFO] ============================================================
2019-01-02 12:50:54,778 P2582 [INFO] Command 01_template_elastic
2019-01-02 12:50:54,782 P2582 [INFO] -----------------------Command Output-----------------------
2019-01-02 12:50:54,782 P2582 [INFO] 'Hello World'
2019-01-02 12:50:54,783 P2582 [INFO] ------------------------------------------------------------
2019-01-02 12:50:54,783 P2582 [INFO] Completed successfully.

有人知道错误是什么吗?

另外,为什么堆栈创建成功呢? (还有具体资源?)

最佳答案

/var/log/cloud-init.log 中的错误消息意味着您的 UserData 脚本已退出并显示 error status 1 而不是预期的 0。

同时,您的 /var/log/cloud-init-output.log 包含以下行:

ValidationError: Stack arn:aws:cloudformation:eu-west-1:248059334340:stack/test-elastic/9fc79150-0e8b-11e9-b135-503ac9e74cfd
is in CREATE_COMPLETE state and cannot be signaled

对于您的其他问题:

Furthermore, why the stack is created with success? (as also the specific resource?)

创建资源后,堆栈进入 CREATE_COMPLETE 状态是正常行为。默认情况下,UserData 脚本的运行不会延迟此状态。

因为您正在使用cfn-signal,所以我假设您需要将 CREATE_COMPLETE 状态推迟到您在 UserData 中发送信号时为止。

有一篇很好的博客文章介绍了如何设置这一切 here .

但是 tl;博士 -

您可能只需要向 EC2 实例资源添加 CreationPolicy,如下所示:

Resources:
EC2ESMasterNode1:
...
CreationPolicy:
ResourceSignal:
Count: 1
Timeout: PT10M

这表示等待 1 个信号并在 10 分钟后超时。显然根据您的要求进行设置。

关于amazon-web-services - AWS : Simple cfn-init fails on Amazon Linux 2 for no apparent reason,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54003048/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com