2017-10-13 1 views
0

내 aws Cloud Formation cfn configset에서 아파치 또는 www- 데이터 일 수있는 것처럼 사용자 그룹의 이름에 환경 키를 설정하는 명령이 있습니다. 배포판에 따라. 이 같은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 결과를 catch하고 사용하는 것이 바람직한 방법입니까? configset 명령? 더 좋은 방법이 있습니까? cfn_init.log에 던져진 오류를 해결하려면 어떻게해야합니까?

OK, 배포시에 배포 유형을 캡처하고 그에 따라 웹 서버 그룹을 설정하기 위해 매개 변수와 매핑 요소를 만들 수 있다고 생각하지만 실제로 cli의 응답에 env : 키를 설정하는 방법을 이해하려고합니다.

답변

1

코드 문제는 WebServerGp입니다. 귀하의 경우는 01_01_get_WebServerGroup입니다에

라인 commandcommands 이름으로, env 동일한 수준에 있어야합니다. 그래서,이 같은되어야합니다 : 당신은 GREP의 결과를 사용하려는 경우, 당신은 변수에 넣어 나중에 사용할 수 있습니다

commands: 
    01_01_get_WebServerGroup: 
     env: .. 
     command: .. 

. command 행 아래에 명령을 실행하기 위해 \n을 사용하여 둘 이상의 명령을 지정할 수 있습니다.

아래에서이 코드를 확인하십시오. 당신이 정말로 긴 명령이있는 경우

command: "result=(ps ef | grep ...)\n echo $result\n ..." 

, 당신은 command의 값하는 Fn::Join를 사용할 수 있습니다.

관련 문제