aws / ec2-image-builder-roadmap

Public Roadmap for EC2 Image Builder.
Other
34 stars 7 forks source link

Ability to include `{{ variable }}` in CreateFile content #76

Closed jgard closed 3 weeks ago

jgard commented 2 years ago

Community Note

Tell us about your request I'd like to be able to write out an Ansible playbook (itself being yaml) using Image Builder Component action CreateFile. In this playbook we have a looping construct that is coincidentally, syntactically identical to component parameter substitution syntax. It uses {{ variable }}. I need to be able to escape those curly braces in the context of Image Builder, so the string ends up as-is in the file created in the image.

Overly simplified example, not valid Ansible playbook yaml but you should get the point:

name: CreateAnsiblePlaybook
schemaVersion: 1.0
phases:
  - name: build
    steps:
      - name: CreatePlaybook
        action: CreateFile
        inputs:
          - path: /tmp/playbook.yaml
            overwrite: true
            content: |
              I want Image Builder to not try to substitute this next line:
              {{ myAnsibleVariable }}

In the above example, trying to create this component would result in error The value supplied for parameter 'data' is not valid. Parameter validation failed for document index '0' phase 'build' step 'CreatePlaybook'. Error: Parameter 'myAnsibleVariable' not declared but referenced.

I couldn't find any hint for escaping syntax in the documentation, and I tried plenty of permutations with \ and `

Tell us about the problem you're trying to solve. What are you trying to do, and why is it hard?

Are you currently working around this issue? Saving the file to an http repository and using WebDownload

Additional context

Attachments

austoonz commented 3 weeks ago

I cannot recall when it was added, but this functionality works.

I created a component with:

schemaVersion: 1.0
constants:
  - MY_VAR:
      type: string
      value: MY_VAR_VALUE!
phases:
  - name: build
    steps:
      - name: CreatePlaybook
        action: CreateFile
        inputs:
          - path: /tmp/playbook.yaml
            overwrite: true
            content: |
              I want Image Builder to not try to substitute this next line:
              {{ MY_VAR }}

When I run this and look at the file:

$ cat /tmp/playbook.yaml
I want Image Builder to not try to substitute this next line:
MY_VAR_VALUE!