1

I am trying to use a dict in an Ansible task, which is defined like this:

in vars/main.yml file:

username: user1
userpass: pass1
users:
  "{{ username }}":
    pass: "{{ userpass }}"

This doesn't work in Ansible 2.9: Ansible seems to not interpolate the value for "{{ username }}"

IIRC this worked fine around Ansible 2.5

What has changed? How should I rewrite my roles and playbooks now?

  • FYI, I was not able to make your above var definition display your expected result with ansible version 2.4 and 2.5. Anslble only expands jinja2 template expressions in values, not in hash keys – Zeitounator Jan 14 '20 at 21:25

1 Answers1

2

The play

- hosts: localhost
  vars:
    username: user1
    userpass: pass1
    users: "{{ {username: {'pass': userpass}} }}"
  tasks:
    - debug:
        var: users

gives:

"users": {
    "user1": {
        "pass": "pass1"
    }
}

Is this what you're looking for?

Vladimir Botka
  • 5,138
  • 8
  • 20