How to add two variables in Cloudformation Fn::Sub in UserData

眉间皱痕 提交于 2019-12-06 15:45:28

问题


I am able to add 1 variable but unable to add second, I am a sys admin, and not that much knowledgeable about YAML

UserData:  
    Fn::Base64: !Sub  
       - |+  
        #!/bin/bash -xe  
        NEW_HOSTNAME=${test}  
       - test:   
             Fn::FindInMap: [Regions, !Ref "AWS::Region", Name]   

I would like to add another FindInMap variable after test, but I am unable to.


回答1:


You can do it like this:

UserData:
  Fn::Base64: !Sub
    - |
      #!/bin/bash -xe
      foo=${foo}
      baz=${baz}
    - foo: !FindInMap [FooMap, Foo, Value]
      baz: !FindInMap [FooMap, Baz, Value]

It could also be formatted as:

UserData:
  Fn::Base64: !Sub
    - |
      #!/bin/bash -xe
      foo=${foo}
      baz=${baz}
    - {
        foo: !FindInMap [FooMap, Foo, Value],
        baz: !FindInMap [FooMap, Baz, Value]
      }

See also docs for the Fn::FindInMap function.

Note that I removed the |+ - which is a YAML feature and says to keep the trailing newlines. It isn't really required here.




回答2:


UserData: 
              Fn::Base64: !Sub
               - |
                  #!/bin/bash
                  NEW_HOSTNAME=${hostName}
               -  {
                  share: !FindInMap [Regions, !Ref "AWS::Region", SHARE],
                  hostName: !Join ["", [!Ref Name, !FindInMap [Regions, 
                                                         !Ref"AWS::Region",USERDATA] ] ]
                  }


来源:https://stackoverflow.com/questions/54564787/how-to-add-two-variables-in-cloudformation-fnsub-in-userdata

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!