<p dir="auto">I've seen other similar posts, but I they seem not to apply to me. The role in question worked fine in 2.2.</p>
<h5 dir="auto">ISSUE TYPE</h5>
<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>
<p dir="auto">Loop</p>
<h5 dir="auto">ANSIBLE VERSION</h5>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible 2.3.0.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides
  python version = 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609]"><pre class="notranslate"><code class="notranslate">ansible 2.3.0.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides
  python version = 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609]
</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[defaults]

host_key_checking = False
ansible_managed = DO NOT MODIFY by hand. This file is under control of Ansible on {host}.
vault_password_file = /var/lib/semaphore/.vpf"><pre class="notranslate"><code class="notranslate">[defaults]

host_key_checking = False
ansible_managed = DO NOT MODIFY by hand. This file is under control of Ansible on {host}.
vault_password_file = /var/lib/semaphore/.vpf
</code></pre></div>
<h5 dir="auto">OS / ENVIRONMENT</h5>
<p dir="auto">N/A</p>
<h5 dir="auto">SUMMARY</h5>
<p dir="auto">When trying to create a list of users, it throws the an error about an invalid value error.</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>

<p dir="auto">I am running this task</p>

<p dir="auto">This is the task I am trying to run.</p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="- name: create user 
  user:
    name: &quot;{{ item.username }}&quot;
    password: &quot;{{ item.password|default(omit) }}&quot;
    shell: /bin/bash
  become: true
  with_items: '{{ users }}'
  no_log: true"><pre class="notranslate">- <span class="pl-ent">name</span>: <span class="pl-s">create user </span>
  <span class="pl-ent">user</span>:
    <span class="pl-ent">name</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ item.username }}<span class="pl-pds">"</span></span>
    <span class="pl-ent">password</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ item.password|default(omit) }}<span class="pl-pds">"</span></span>
    <span class="pl-ent">shell</span>: <span class="pl-s">/bin/bash</span>
  <span class="pl-ent">become</span>: <span class="pl-c1">true</span>
  <span class="pl-ent">with_items</span>: <span class="pl-s"><span class="pl-pds">'</span>{{ users }}<span class="pl-pds">'</span></span>
  <span class="pl-ent">no_log</span>: <span class="pl-c1">true</span></pre></div>
<p dir="auto">This is the <code class="notranslate">users</code> variable. I have truncated the vault values for brevity.</p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="users:
  - username: ptadmin
    password: !vault-encrypted |
      $ANSIBLE_VAULT;1.1;AES256
      ...
    use_sudo: true
    use_ssh: false
  
  - username: ansibleremote
    password: &quot;{{ petra_ansibleremote_password }}&quot;
    use_sudo: true
    use_ssh: true
    public_key: !vault-encrypted |
      $ANSIBLE_VAULT;1.1;AES256
      ...

  - username: semaphore
    password: &quot;{{ petra_ansibleremote_password }}&quot;
    use_sudo: true
    use_ssh: true

  - username: frosty
    password: !vault-encrypted |
      $ANSIBLE_VAULT;1.1;AES256
      ...
    use_sudo: true
    use_ssh: true
    public_key: !vault-encrypted |
      $ANSIBLE_VAULT;1.1;AES256
      ...

  - username: thebeardedone
    password: !vault-encrypted |
      $ANSIBLE_VAULT;1.1;AES256
      ...
    use_sudo: true
    use_ssh: true
    public_key: !vault-encrypted |
      $ANSIBLE_VAULT;1.1;AES256
      ...

  - username: senanufc
    password: !vault-encrypted |
      $ANSIBLE_VAULT;1.1;AES256
      ...
    use_sudo: true
    use_ssh: true
    public_key: !vault-encrypted |
      $ANSIBLE_VAULT;1.1;AES256
      ..."><pre class="notranslate"><span class="pl-ent">users</span>:
  - <span class="pl-ent">username</span>: <span class="pl-s">ptadmin</span>
    <span class="pl-ent">password</span>: <span class="pl-k">!vault-encrypted</span> <span class="pl-s">|</span>
<span class="pl-s">      $ANSIBLE_VAULT;1.1;AES256</span>
<span class="pl-s">      ...</span>
<span class="pl-s"></span>    <span class="pl-ent">use_sudo</span>: <span class="pl-c1">true</span>
    <span class="pl-ent">use_ssh</span>: <span class="pl-c1">false</span>
  
  - <span class="pl-ent">username</span>: <span class="pl-s">ansibleremote</span>
    <span class="pl-ent">password</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ petra_ansibleremote_password }}<span class="pl-pds">"</span></span>
    <span class="pl-ent">use_sudo</span>: <span class="pl-c1">true</span>
    <span class="pl-ent">use_ssh</span>: <span class="pl-c1">true</span>
    <span class="pl-ent">public_key</span>: <span class="pl-k">!vault-encrypted</span> <span class="pl-s">|</span>
<span class="pl-s">      $ANSIBLE_VAULT;1.1;AES256</span>
<span class="pl-s">      ...</span>
<span class="pl-s"></span>
<span class="pl-s"></span>  - <span class="pl-ent">username</span>: <span class="pl-s">semaphore</span>
    <span class="pl-ent">password</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ petra_ansibleremote_password }}<span class="pl-pds">"</span></span>
    <span class="pl-ent">use_sudo</span>: <span class="pl-c1">true</span>
    <span class="pl-ent">use_ssh</span>: <span class="pl-c1">true</span>

  - <span class="pl-ent">username</span>: <span class="pl-s">frosty</span>
    <span class="pl-ent">password</span>: <span class="pl-k">!vault-encrypted</span> <span class="pl-s">|</span>
<span class="pl-s">      $ANSIBLE_VAULT;1.1;AES256</span>
<span class="pl-s">      ...</span>
<span class="pl-s"></span>    <span class="pl-ent">use_sudo</span>: <span class="pl-c1">true</span>
    <span class="pl-ent">use_ssh</span>: <span class="pl-c1">true</span>
    <span class="pl-ent">public_key</span>: <span class="pl-k">!vault-encrypted</span> <span class="pl-s">|</span>
<span class="pl-s">      $ANSIBLE_VAULT;1.1;AES256</span>
<span class="pl-s">      ...</span>
<span class="pl-s"></span>
<span class="pl-s"></span>  - <span class="pl-ent">username</span>: <span class="pl-s">thebeardedone</span>
    <span class="pl-ent">password</span>: <span class="pl-k">!vault-encrypted</span> <span class="pl-s">|</span>
<span class="pl-s">      $ANSIBLE_VAULT;1.1;AES256</span>
<span class="pl-s">      ...</span>
<span class="pl-s"></span>    <span class="pl-ent">use_sudo</span>: <span class="pl-c1">true</span>
    <span class="pl-ent">use_ssh</span>: <span class="pl-c1">true</span>
    <span class="pl-ent">public_key</span>: <span class="pl-k">!vault-encrypted</span> <span class="pl-s">|</span>
<span class="pl-s">      $ANSIBLE_VAULT;1.1;AES256</span>
<span class="pl-s">      ...</span>
<span class="pl-s"></span>
<span class="pl-s"></span>  - <span class="pl-ent">username</span>: <span class="pl-s">senanufc</span>
    <span class="pl-ent">password</span>: <span class="pl-k">!vault-encrypted</span> <span class="pl-s">|</span>
<span class="pl-s">      $ANSIBLE_VAULT;1.1;AES256</span>
<span class="pl-s">      ...</span>
<span class="pl-s"></span>    <span class="pl-ent">use_sudo</span>: <span class="pl-c1">true</span>
    <span class="pl-ent">use_ssh</span>: <span class="pl-c1">true</span>
    <span class="pl-ent">public_key</span>: <span class="pl-k">!vault-encrypted</span> <span class="pl-s">|</span>
<span class="pl-s">      $ANSIBLE_VAULT;1.1;AES256</span>
<span class="pl-s">      ...</span></pre></div>
<p dir="auto">I tried a <code class="notranslate">debug</code> before it and the results are in this <a href="https://gist.github.com/thedumbtechguy/33a2de0c2b841f360e89ec29559a4790">gist</a>.</p>
<p dir="auto">I also tried with below and the same thing happens</p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="- name: test loop
  debug:
    msg: &quot;{{ item.username }}&quot;
  with_items: &quot;{{ users }}&quot;"><pre class="notranslate">- <span class="pl-ent">name</span>: <span class="pl-s">test loop</span>
  <span class="pl-ent">debug</span>:
    <span class="pl-ent">msg</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ item.username }}<span class="pl-pds">"</span></span>
  <span class="pl-ent">with_items</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ users }}<span class="pl-pds">"</span></span></pre></div>
<h5 dir="auto">EXPECTED RESULTS</h5>
<p dir="auto">Users created</p>
<h5 dir="auto">ACTUAL RESULTS</h5>


<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="fatal: [petra-hq-dev-master]: FAILED! =&gt; {&quot;failed&quot;: true, &quot;msg&quot;: &quot;the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: 'ansible.vars.unsafe_proxy.AnsibleUnsafeText object' has no attribute 'username'\n\nThe error appears to have been in '/etc/ansible/roles/thedumbtechguy.manage-users/tasks/create_users.yml': line 6, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: create user\n  ^ here\n&quot;}
	to retry, use: --limit @/var/lib/semaphore/repository_1/playbooks/setup_new_hosts.retry"><pre class="notranslate"><code class="notranslate">fatal: [petra-hq-dev-master]: FAILED! =&gt; {"failed": true, "msg": "the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: 'ansible.vars.unsafe_proxy.AnsibleUnsafeText object' has no attribute 'username'\n\nThe error appears to have been in '/etc/ansible/roles/thedumbtechguy.manage-users/tasks/create_users.yml': line 6, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: create user\n  ^ here\n"}
	to retry, use: --limit @/var/lib/semaphore/repository_1/playbooks/setup_new_hosts.retry
</code></pre></div>
<h5 dir="auto">ISSUE TYPE</h5>
<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>
<p dir="auto">ansible-vault or jinja</p>
<h5 dir="auto">ANSIBLE VERSION</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible 2.3.0.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides
  python version = 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609]"><pre class="notranslate"><code class="notranslate">ansible 2.3.0.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides
  python version = 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609]
</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>
<p dir="auto">No special configuration</p>
<h5 dir="auto">OS / ENVIRONMENT</h5>
<p dir="auto">Ubuntu 16.04</p>
<h5 dir="auto">SUMMARY</h5>
<p dir="auto">When using the newly introduced <a href="http://docs.ansible.com/ansible/playbooks_vault.html#single-encrypted-variable" rel="nofollow">single encrypted variables </a> in lists or dictionaries these cannot be looped like expected with <code class="notranslate">with_items</code> or <code class="notranslate">with_dict</code>. The list or dictionary is somehow treated as one object and not as a "loopable" object.</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>

<p dir="auto">Simple playbook containing a single encrypted variable <code class="notranslate">vaulted</code> in the list <code class="notranslate">test_with_vaulted_variable</code>. The vault password is "test" (without quotes) and the <code class="notranslate">vaulted</code> variable content is "vaulted variable".</p>

<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="---
- hosts: all
  vars:
      test_without_vaulted_variable:
          - not_vaulted: not vaulted variable
          - another_standard_variable: standard
      test_with_vaulted_variable:
          - not_vaulted: not vaulted variable
          - vaulted: !vault |
              $ANSIBLE_VAULT;1.1;AES256
              66376230363937306331353166333731633037326166626530393462636666346630366463313134
              6635313236366537346339313338633539643665313931390a373264326437663530616630623734
              31666136343232666235323865653838393830613432343561633465333837633531643564343064
              3237353766313835310a643963313163663632623064313034363531356330653131303833646138
              65366139376134396231353864383662623832376239336433623630383464303161
  tasks:
    - debug: var=test_without_vaulted_variable
    - debug: var=test_with_vaulted_variable
    - debug: 
      with_items: &quot;{{ test_without_vaulted_variable }}&quot;
    - debug: 
      with_items: &quot;{{ test_with_vaulted_variable }}&quot;"><pre class="notranslate">---
- <span class="pl-ent">hosts</span>: <span class="pl-s">all</span>
  <span class="pl-ent">vars</span>:
      <span class="pl-ent">test_without_vaulted_variable</span>:
          - <span class="pl-ent">not_vaulted</span>: <span class="pl-s">not vaulted variable</span>
          - <span class="pl-ent">another_standard_variable</span>: <span class="pl-s">standard</span>
      <span class="pl-ent">test_with_vaulted_variable</span>:
          - <span class="pl-ent">not_vaulted</span>: <span class="pl-s">not vaulted variable</span>
          - <span class="pl-ent">vaulted</span>: <span class="pl-k">!vault</span> <span class="pl-s">|</span>
<span class="pl-s">              $ANSIBLE_VAULT;1.1;AES256</span>
<span class="pl-s">              66376230363937306331353166333731633037326166626530393462636666346630366463313134</span>
<span class="pl-s">              6635313236366537346339313338633539643665313931390a373264326437663530616630623734</span>
<span class="pl-s">              31666136343232666235323865653838393830613432343561633465333837633531643564343064</span>
<span class="pl-s">              3237353766313835310a643963313163663632623064313034363531356330653131303833646138</span>
<span class="pl-s">              65366139376134396231353864383662623832376239336433623630383464303161</span>
<span class="pl-s"></span>  <span class="pl-ent">tasks</span>:
    - <span class="pl-ent">debug</span>: <span class="pl-s">var=test_without_vaulted_variable</span>
    - <span class="pl-ent">debug</span>: <span class="pl-s">var=test_with_vaulted_variable</span>
    - <span class="pl-ent">debug</span>: 
      <span class="pl-ent">with_items</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ test_without_vaulted_variable }}<span class="pl-pds">"</span></span>
    - <span class="pl-ent">debug</span>: 
      <span class="pl-ent">with_items</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ test_with_vaulted_variable }}<span class="pl-pds">"</span></span></pre></div>
<p dir="auto">Start the play with (and enter the vault pass "test")</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible-playbook -i 'lavego-test,' vault-with-items.yml --ask-vault-pass"><pre class="notranslate"><code class="notranslate">ansible-playbook -i 'lavego-test,' vault-with-items.yml --ask-vault-pass
</code></pre></div>

<h5 dir="auto">EXPECTED RESULTS</h5>
<p dir="auto">The list processing should be the same for the lists <code class="notranslate">test_without_vaulted_variable</code>and <code class="notranslate">test_with_vaulted_variable</code>: The loops should output each element of each list.</p>
<h5 dir="auto">ACTUAL RESULTS</h5>
<p dir="auto">The list containing the vaulted variable is not looped like expected. In the last debug statement: Note that there is only one "Hello world!" message printed instead of two, one for each element, for the list with no vaulted variable.</p>
<p dir="auto">Note that also the normal debug output of the two lists differs (first and second debug statements) - the list containing the vaulted variable "has no structure".</p>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ ansible-playbook -i 'localhost,' vault-with-items.yml --ask-vault-pass
Vault password: 

PLAY [all] *********************************************************************************************************************************************************************************************************

TASK [Gathering Facts] *********************************************************************************************************************************************************************************************
ok: [localhost]

TASK [debug] *******************************************************************************************************************************************************************************************************
ok: [localhost] =&gt; {
    &quot;changed&quot;: false, 
    &quot;test_without_vaulted_variable&quot;: [
        {
            &quot;not_vaulted&quot;: &quot;not vaulted variable&quot;
        }, 
        {
            &quot;another_standard_variable&quot;: &quot;standard&quot;
        }
    ]
}

TASK [debug] *******************************************************************************************************************************************************************************************************
ok: [localhost] =&gt; {
    &quot;changed&quot;: false, 
    &quot;test_with_vaulted_variable&quot;: &quot;[{u'not_vaulted': u'not vaulted variable'}, {u'vaulted': AnsibleVaultEncryptedUnicode($ANSIBLE_VAULT;1.1;AES256\n66376230363937306331353166333731633037326166626530393462636666346630366463313134\n6635313236366537346339313338633539643665313931390a373264326437663530616630623734\n31666136343232666235323865653838393830613432343561633465333837633531643564343064\n3237353766313835310a643963313163663632623064313034363531356330653131303833646138\n65366139376134396231353864383662623832376239336433623630383464303161\n)}]&quot;
}

TASK [debug] *******************************************************************************************************************************************************************************************************
ok: [localhost] =&gt; (item={u'not_vaulted': u'not vaulted variable'}) =&gt; {
    &quot;item&quot;: {
        &quot;not_vaulted&quot;: &quot;not vaulted variable&quot;
    }, 
    &quot;msg&quot;: &quot;Hello world!&quot;
}
ok: [localhost] =&gt; (item={u'another_standard_variable': u'standard'}) =&gt; {
    &quot;item&quot;: {
        &quot;another_standard_variable&quot;: &quot;standard&quot;
    }, 
    &quot;msg&quot;: &quot;Hello world!&quot;
}

TASK [debug] *******************************************************************************************************************************************************************************************************
ok: [localhost =&gt; (item=[{u'not_vaulted': u'not vaulted variable'}, {u'vaulted': AnsibleVaultEncryptedUnicode($ANSIBLE_VAULT;1.1;AES256
66376230363937306331353166333731633037326166626530393462636666346630366463313134
6635313236366537346339313338633539643665313931390a373264326437663530616630623734
31666136343232666235323865653838393830613432343561633465333837633531643564343064
3237353766313835310a643963313163663632623064313034363531356330653131303833646138
65366139376134396231353864383662623832376239336433623630383464303161
)}]) =&gt; {
    &quot;item&quot;: &quot;[{u'not_vaulted': u'not vaulted variable'}, {u'vaulted': AnsibleVaultEncryptedUnicode($ANSIBLE_VAULT;1.1;AES256\n66376230363937306331353166333731633037326166626530393462636666346630366463313134\n6635313236366537346339313338633539643665313931390a373264326437663530616630623734\n31666136343232666235323865653838393830613432343561633465333837633531643564343064\n3237353766313835310a643963313163663632623064313034363531356330653131303833646138\n65366139376134396231353864383662623832376239336433623630383464303161\n)}]&quot;, 
    &quot;msg&quot;: &quot;Hello world!&quot;
}

PLAY RECAP *********************************************************************************************************************************************************************************************************
localhost                : ok=5    changed=0    unreachable=0    failed=0   "><pre class="notranslate"><code class="notranslate">$ ansible-playbook -i 'localhost,' vault-with-items.yml --ask-vault-pass
Vault password: 

PLAY [all] *********************************************************************************************************************************************************************************************************

TASK [Gathering Facts] *********************************************************************************************************************************************************************************************
ok: [localhost]

TASK [debug] *******************************************************************************************************************************************************************************************************
ok: [localhost] =&gt; {
    "changed": false, 
    "test_without_vaulted_variable": [
        {
            "not_vaulted": "not vaulted variable"
        }, 
        {
            "another_standard_variable": "standard"
        }
    ]
}

TASK [debug] *******************************************************************************************************************************************************************************************************
ok: [localhost] =&gt; {
    "changed": false, 
    "test_with_vaulted_variable": "[{u'not_vaulted': u'not vaulted variable'}, {u'vaulted': AnsibleVaultEncryptedUnicode($ANSIBLE_VAULT;1.1;AES256\n66376230363937306331353166333731633037326166626530393462636666346630366463313134\n6635313236366537346339313338633539643665313931390a373264326437663530616630623734\n31666136343232666235323865653838393830613432343561633465333837633531643564343064\n3237353766313835310a643963313163663632623064313034363531356330653131303833646138\n65366139376134396231353864383662623832376239336433623630383464303161\n)}]"
}

TASK [debug] *******************************************************************************************************************************************************************************************************
ok: [localhost] =&gt; (item={u'not_vaulted': u'not vaulted variable'}) =&gt; {
    "item": {
        "not_vaulted": "not vaulted variable"
    }, 
    "msg": "Hello world!"
}
ok: [localhost] =&gt; (item={u'another_standard_variable': u'standard'}) =&gt; {
    "item": {
        "another_standard_variable": "standard"
    }, 
    "msg": "Hello world!"
}

TASK [debug] *******************************************************************************************************************************************************************************************************
ok: [localhost =&gt; (item=[{u'not_vaulted': u'not vaulted variable'}, {u'vaulted': AnsibleVaultEncryptedUnicode($ANSIBLE_VAULT;1.1;AES256
66376230363937306331353166333731633037326166626530393462636666346630366463313134
6635313236366537346339313338633539643665313931390a373264326437663530616630623734
31666136343232666235323865653838393830613432343561633465333837633531643564343064
3237353766313835310a643963313163663632623064313034363531356330653131303833646138
65366139376134396231353864383662623832376239336433623630383464303161
)}]) =&gt; {
    "item": "[{u'not_vaulted': u'not vaulted variable'}, {u'vaulted': AnsibleVaultEncryptedUnicode($ANSIBLE_VAULT;1.1;AES256\n66376230363937306331353166333731633037326166626530393462636666346630366463313134\n6635313236366537346339313338633539643665313931390a373264326437663530616630623734\n31666136343232666235323865653838393830613432343561633465333837633531643564343064\n3237353766313835310a643963313163663632623064313034363531356330653131303833646138\n65366139376134396231353864383662623832376239336433623630383464303161\n)}]", 
    "msg": "Hello world!"
}

PLAY RECAP *********************************************************************************************************************************************************************************************************
localhost                : ok=5    changed=0    unreachable=0    failed=0   
</code></pre></div>
<p dir="auto">Thank you for your help!</p>