<p dir="auto">Hi,<br>
i'm facing an issue with the with_items option in combination with a variable to replace + a fixed string behind the variable name. The issue came up after updating from 1.9.4 to 2.0.0.2.</p>
<h2 dir="auto">Environment:</h2>
<p dir="auto">Ansible: 2.0.0.2-1<br>
OS: Ubuntu 14.04<br>
Python: 2.7.5-5ubuntu3</p>
<h2 dir="auto">Steps To Reproduce:</h2>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="site.yml

---
- hosts: localhost
  tags: withitems
  roles:
    - { role: withitems }


roles/withitems/tasks/main.yml

---
- name: debug01
  debug: msg={{ role_name }}

- name: debug02
  debug: msg=&quot;{{ role_name }}_anystring&quot;
  with_items: nameofrole_anystring

- name: debug03
  debug: msg={{ item.name }}
  with_items: nameofrole_anystring

- name: debug04
  debug: msg={{ item }}
  with_items: &quot;{{ role_name }}_anystring&quot;

- name: debug05
  debug: msg={{ item.name }}
  with_items:
    - { name: foo }

- name: debug06
  debug: msg={{ item.name }}
  with_items: &quot;{{ role_name }}_anystring&quot;

roles/withitems/vars/main.yml

---
role_name: nameofrole

nameofrole_anystring:
  - { name: foo }"><pre class="notranslate"><code class="notranslate">site.yml

---
- hosts: localhost
  tags: withitems
  roles:
    - { role: withitems }


roles/withitems/tasks/main.yml

---
- name: debug01
  debug: msg={{ role_name }}

- name: debug02
  debug: msg="{{ role_name }}_anystring"
  with_items: nameofrole_anystring

- name: debug03
  debug: msg={{ item.name }}
  with_items: nameofrole_anystring

- name: debug04
  debug: msg={{ item }}
  with_items: "{{ role_name }}_anystring"

- name: debug05
  debug: msg={{ item.name }}
  with_items:
    - { name: foo }

- name: debug06
  debug: msg={{ item.name }}
  with_items: "{{ role_name }}_anystring"

roles/withitems/vars/main.yml

---
role_name: nameofrole

nameofrole_anystring:
  - { name: foo }
</code></pre></div>
<h3 dir="auto">When executing this on Ansible 1.9.4:</h3>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content=":~ ansible --version
ansible 1.9.4
  configured module search path = None

:~ ansible-playbook testsite.yml --tags withitems

PLAY [localhost] **************************************************************

TASK: [withitems | debug01] ***************************************************
ok: [localhost] =&gt; {
    &quot;msg&quot;: &quot;nameofrole&quot;
}

TASK: [withitems | debug02] ***************************************************
ok: [localhost] =&gt; (item={'name': 'foo'}) =&gt; {
    &quot;item&quot;: {
        &quot;name&quot;: &quot;foo&quot;
    },
    &quot;msg&quot;: &quot;nameofrole_anystring&quot;
}

TASK: [withitems | debug03] ***************************************************
ok: [localhost] =&gt; (item={'name': 'foo'}) =&gt; {
    &quot;item&quot;: {
        &quot;name&quot;: &quot;foo&quot;
    },
    &quot;msg&quot;: &quot;foo&quot;
}

TASK: [withitems | debug04] ***************************************************
ok: [localhost] =&gt; (item={'name': 'foo'}) =&gt; {
    &quot;item&quot;: {
        &quot;name&quot;: &quot;foo&quot;
    },
    &quot;msg&quot;: &quot;{'name':&quot;
}

TASK: [withitems | debug05] ***************************************************
ok: [localhost] =&gt; (item={'name': 'foo'}) =&gt; {
    &quot;item&quot;: {
        &quot;name&quot;: &quot;foo&quot;
    },
    &quot;msg&quot;: &quot;foo&quot;
}

TASK: [withitems | debug06] ***************************************************
ok: [localhost] =&gt; (item={'name': 'foo'}) =&gt; {
    &quot;item&quot;: {
        &quot;name&quot;: &quot;foo&quot;
    },
    &quot;msg&quot;: &quot;foo&quot;
}

PLAY RECAP ********************************************************************
localhost                  : ok=6    changed=0    unreachable=0    failed=0"><pre class="notranslate"><code class="notranslate">:~ ansible --version
ansible 1.9.4
  configured module search path = None

:~ ansible-playbook testsite.yml --tags withitems

PLAY [localhost] **************************************************************

TASK: [withitems | debug01] ***************************************************
ok: [localhost] =&gt; {
    "msg": "nameofrole"
}

TASK: [withitems | debug02] ***************************************************
ok: [localhost] =&gt; (item={'name': 'foo'}) =&gt; {
    "item": {
        "name": "foo"
    },
    "msg": "nameofrole_anystring"
}

TASK: [withitems | debug03] ***************************************************
ok: [localhost] =&gt; (item={'name': 'foo'}) =&gt; {
    "item": {
        "name": "foo"
    },
    "msg": "foo"
}

TASK: [withitems | debug04] ***************************************************
ok: [localhost] =&gt; (item={'name': 'foo'}) =&gt; {
    "item": {
        "name": "foo"
    },
    "msg": "{'name':"
}

TASK: [withitems | debug05] ***************************************************
ok: [localhost] =&gt; (item={'name': 'foo'}) =&gt; {
    "item": {
        "name": "foo"
    },
    "msg": "foo"
}

TASK: [withitems | debug06] ***************************************************
ok: [localhost] =&gt; (item={'name': 'foo'}) =&gt; {
    "item": {
        "name": "foo"
    },
    "msg": "foo"
}

PLAY RECAP ********************************************************************
localhost                  : ok=6    changed=0    unreachable=0    failed=0
</code></pre></div>
<h3 dir="auto">When executing this on Ansible 2.0.0.2:</h3>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content=":~ ansible --version
ansible 2.0.0.2
  config file = /root/ansible-test/ansible.cfg
  configured module search path = Default w/o overrides

:~ ansible-playbook testsite.yml --tags withitems

PLAY ***************************************************************************

TASK [withitems : debug01] *****************************************************
ok: [localhost] =&gt; {
    &quot;msg&quot;: &quot;withitems&quot;
}

TASK [withitems : debug02] *****************************************************
ok: [localhost] =&gt; (item={u'name': u'foo'}) =&gt; {
    &quot;item&quot;: {
        &quot;name&quot;: &quot;foo&quot;
    },
    &quot;msg&quot;: &quot;withitems_anystring&quot;
}

TASK [withitems : debug03] *****************************************************
ok: [localhost] =&gt; (item={u'name': u'foo'}) =&gt; {
    &quot;item&quot;: {
        &quot;name&quot;: &quot;foo&quot;
    },
    &quot;msg&quot;: &quot;foo&quot;
}

TASK [withitems : debug04] *****************************************************
ok: [localhost] =&gt; (item=withitems_anystring) =&gt; {
    &quot;item&quot;: &quot;withitems_anystring&quot;,
    &quot;msg&quot;: &quot;withitems_anystring&quot;
}

TASK [withitems : debug05] *****************************************************
ok: [localhost] =&gt; (item={u'name': u'foo'}) =&gt; {
    &quot;item&quot;: {
        &quot;name&quot;: &quot;foo&quot;
    },
    &quot;msg&quot;: &quot;foo&quot;
}

TASK [withitems : debug06] *****************************************************
fatal: [localhost]: FAILED! =&gt; {&quot;failed&quot;: true, &quot;msg&quot;: &quot;ERROR! 'unicode object' has no attribute 'name'&quot;}

PLAY RECAP *********************************************************************
localhost                  : ok=5    changed=0    unreachable=0    failed=1"><pre class="notranslate"><code class="notranslate">:~ ansible --version
ansible 2.0.0.2
  config file = /root/ansible-test/ansible.cfg
  configured module search path = Default w/o overrides

:~ ansible-playbook testsite.yml --tags withitems

PLAY ***************************************************************************

TASK [withitems : debug01] *****************************************************
ok: [localhost] =&gt; {
    "msg": "withitems"
}

TASK [withitems : debug02] *****************************************************
ok: [localhost] =&gt; (item={u'name': u'foo'}) =&gt; {
    "item": {
        "name": "foo"
    },
    "msg": "withitems_anystring"
}

TASK [withitems : debug03] *****************************************************
ok: [localhost] =&gt; (item={u'name': u'foo'}) =&gt; {
    "item": {
        "name": "foo"
    },
    "msg": "foo"
}

TASK [withitems : debug04] *****************************************************
ok: [localhost] =&gt; (item=withitems_anystring) =&gt; {
    "item": "withitems_anystring",
    "msg": "withitems_anystring"
}

TASK [withitems : debug05] *****************************************************
ok: [localhost] =&gt; (item={u'name': u'foo'}) =&gt; {
    "item": {
        "name": "foo"
    },
    "msg": "foo"
}

TASK [withitems : debug06] *****************************************************
fatal: [localhost]: FAILED! =&gt; {"failed": true, "msg": "ERROR! 'unicode object' has no attribute 'name'"}

PLAY RECAP *********************************************************************
localhost                  : ok=5    changed=0    unreachable=0    failed=1
</code></pre></div>
<h2 dir="auto">Actual Results:</h2>
<p dir="auto">Using with_items: "{{ variable_name }}_fixedstring" the playbook fails to find attributes on the item.</p>
<h2 dir="auto">Expected Results:</h2>
<p dir="auto">Usage of above combination is able to find attributes like it was in version &lt;2.0.</p>
<p dir="auto">Let me know if i can provide further details. Thank you for your help.</p>
<h5 dir="auto">Issue Type: Bug Report/Regression</h5>
<h5 dir="auto">Ansible Version:</h5>
<p dir="auto">ansible 2.0.0 (<a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/ansible/ansible/commit/f41dd578b340b76aa706af9540fd8fab2fbb0eb6/hovercard" href="https://github.com/ansible/ansible/commit/f41dd578b340b76aa706af9540fd8fab2fbb0eb6"><tt>f41dd57</tt></a>)</p>
<h5 dir="auto">Ansible Configuration:</h5>
<p dir="auto">self-packaged version based on above revision</p>
<h5 dir="auto">Environment:</h5>
<p dir="auto">openSuSE Leap 42.1</p>
<h5 dir="auto">Summary:</h5>
<p dir="auto">Substituting variable names based on other variables does not work in ansible 2.0.0 but used to work in 1.9.4.</p>
<p dir="auto">This should either be fixed or stated more prominently in the Changelog as it breaks existing playbooks.</p>
<h5 dir="auto">Steps To Reproduce:</h5>
<p dir="auto">Example playbook:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="vars:
  packages_install_42:
    - bash
    - zsh

tasks:
- name: install stuff
  zypper: name={{item}} state=present
  with_items: packages_install_{{ansible_distribution_major_version}}"><pre class="notranslate"><code class="notranslate">vars:
  packages_install_42:
    - bash
    - zsh

tasks:
- name: install stuff
  zypper: name={{item}} state=present
  with_items: packages_install_{{ansible_distribution_major_version}}
</code></pre></div>
<h5 dir="auto">Expected Results:</h5>
<p dir="auto">Variable packages_install_42 is used, the packages bash and zsh are installed.</p>
<h5 dir="auto">Actual Results:</h5>
<p dir="auto">The task fails:<br>
<code class="notranslate">(item=[u'packages_install_42']) =&gt; {"failed": true, "item": ["packages_install_42"], "msg": "No provider of 'packages_install_42' found.\n", "rc": 104}</code></p>