在我的aws Cloud Formation cfn configset我有一個命令來設置一個環境鍵到apache所屬的用戶組的名稱,因爲它可能是apache或www-data取決於發行版。如何收集一個grep並在aws中使用configset
事情是這樣的:
Metadata:
AWS::CloudFormation::Init:
configSets:
joomla:
- "set_permissions"
- "and_some_more..."
configure_cfn:
files:
/etc/cfn/hooks.d/cfn-auto-reloader.conf:
content: !Sub |
[cfn-auto-reloader-hook]
triggers=post.update
path=Resources.EC2.Metadata.AWS::CloudFormation::Init
action=/opt/aws/bin/cfn-init -v --stack ${AWS::StackName} --resource EC2 --configsets joomla --region ${AWS::Region}
mode: "000400"
owner: root
group: root
.....
set_permissions:
commands:
01_01_get_WebServerGroup:
env:
#webserver group might be apache or www-data depending on the distro
WebServerGp:
command: "ps -ef | egrep '(httpd|apache2|apache)' | grep -v `whoami` | grep -v root | head -n1 | awk '{print $1}'"
然而,當我推出這個堆棧中,configsets過程停止在這一點上,我在得到一個錯誤cfn_init.log看起來像這樣:
File "/usr/lib/python2.7/dist-packages/cfnbootstrap/command_tool.py", line 80, in apply raise ToolError(u"%s does not specify the 'command' attribute, which is required" % name) ToolError: 01_01_get_WebServerGroup does not specify the 'command' attribute, which is required
這是首選的方法來捕獲和使用grep結果在一個configset命令?有沒有更好的辦法?我能做些什麼來解決cfn_init.log中引發的錯誤?
好的,我想我可以創建參數和映射元素來捕獲啓動時的發行版類型,然後相應地設置web服務器組,但我真的想了解如何將env:key設置爲來自cli的響應。