ansible/ansible — pull request #7838 by obfusk (2014-06-19 14:53:28+00:00)
Title: allow registered vars in playbook to be {{ dynamic }}

A colleague of mine ran into the problem that registered variables were not being overwritten properly when running a role multiple times on the same host for multiple users.

```yaml
- name: foo test
command: /usr/bin/test -e /home/{{ user }}
register: foo
failed_when: false
changed_when: false

- name: foo echo
command: /usr/bin/echo HOME EXISTS
when: foo.rc != 0
```

I wasn't able to diagnose whether this is intended or not or what to do about it. I thought of using dynamic names for registered variables.

```yaml
- name: foo test
command: /usr/bin/test -e /home/{{ user }}
register: foo_{{ user }}
failed_when: false
changed_when: false

- name: foo echo
command: /usr/bin/echo HOME EXISTS
when: hostvars[inventory_hostname]['foo_' + user].rc != 0
```

Unfortunately, that didn't work. It seems that the register attribute is not parsed as a template. I modified ansible to parse the register attribute as a template and now dynamic register variables work and my colleague's problem is solved.

I'd appreciate it if my change could be included in ansible. `make test` runs fine. If you need more information or if the pull request is not up to your standards please let me know. Thanks.

\- Felix