1

I'm new to Ansible, and i'm having a hard time figuring out how to get an expression to work. I'm try to run a command task that references a dictionary variable where the key i need to reference is dynamic as well. Relevant code (multilined for formatting):

   tasks:
      - name: set volume
        command: az webapp config storage-account add --share-name shareName2 
                --access-key {{ kvsecrets['connectionstring-{{resources_name}}-key2'] }}

So kvsecrets is a dictionary registered by a previous task, and resources_name is a variable declared further up in the playbook. The syntax above doesn't work as it outputs kvsecrets['connectionstring-{{resources_name}}-key2'] without making the inner transformation. What is the proper format to get the value for that dictionary key?

Thanks!

Gonzalo
  • 679
  • 1
  • 8
  • 18

1 Answers1

1

Ansible is a wrapper of python modules and uses jinja2 for templating. This problem can be solved by string concatenation:

Below is an example:

Note: Please be mindful of the double and single quotes

tasks:
  - name: set volume
    command: az webapp config storage-account add --share-name shareName2 
             --access-key   {{ kvsecrets["'connectionstring-'+resources_name+'-key2'"]}} }}
garlicFrancium
  • 2,013
  • 14
  • 23