<p dir="auto">I am having a confusing problem. It does look like a bug and hence I am reporting here, not sure if duplicate.</p>
<p dir="auto">I am using ansible version 2.0.0 locally on OSX El Capitan, to run a series of steps which sets up my machine for development for my project. The last step here is to add a few lines to <code class="notranslate">/etc/hosts</code> (~15 lines)<br>
I am using <code class="notranslate">lineinfile</code> to add these lines in a loop.</p>
<p dir="auto">I have tried <code class="notranslate">become: root</code> with <code class="notranslate">become_ask_pass=True</code> in the cfg file. This does nothing. It does not ask my password and once it hits that task, I get <code class="notranslate">The destination directory (/private/etc) is not writable by the current user.</code>. If I try <code class="notranslate">sudo: yes</code> and <code class="notranslate">ask_sudo_pass=True</code> then I get <code class="notranslate">fatal: [localhost]: FAILED! =&gt; {"failed": true, "msg": "ERROR! privilege output closed while waiting for password prompt:\nBECOME-SUCCESS-jpibjiakmfjdrjafspqizphqotvhjikm\n{\"msg\": \"line added\", \"changed\": true, \"backup\": \"\"}\n"}</code>. But infact If i check now, <code class="notranslate">/etc/hosts</code> file now has the first 2 lines of the list of lines I had to add. Running the playbook now doesnt help me at all.. but even more oddly, If i remove the config option to ask for password and run the play it works fully....</p>
<p dir="auto">Ansible crashes when creating links with_items and using <code class="notranslate">ansible_connection=local</code>. Here an example playbook for reproducing the behavior:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="- name: the last task will throw an error
  hosts: localhost
  gather_facts: no

  tasks:
    - name: create files - that will work
      copy:
        content: &quot;test&quot;
        dest: &quot;/tmp/{{ item }}&quot;
      with_items:
        - testfile1
        - testfile2

    - name: create links - that will crash
      become: yes
      file:
        src: &quot;/tmp/{{ item }}&quot;
        dest: &quot;/tmp/{{ item }}link&quot;
        state: link
      with_items:
        - testfile1
        - testfile2"><pre class="notranslate"><code class="notranslate">- name: the last task will throw an error
  hosts: localhost
  gather_facts: no

  tasks:
    - name: create files - that will work
      copy:
        content: "test"
        dest: "/tmp/{{ item }}"
      with_items:
        - testfile1
        - testfile2

    - name: create links - that will crash
      become: yes
      file:
        src: "/tmp/{{ item }}"
        dest: "/tmp/{{ item }}link"
        state: link
      with_items:
        - testfile1
        - testfile2
</code></pre></div>
<p dir="auto">The output is:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="PLAY [the last task will throw an error] ***********************************

TASK [create files - that will work] *************************************************************
ok: [localhost] =&gt; (item=testfile1)
ok: [localhost] =&gt; (item=testfile2)

TASK [create links - that will crash] *************************************************************
fatal: [localhost]: FAILED! =&gt; {&quot;failed&quot;: true, &quot;msg&quot;: &quot;ERROR! privilege output closed while waiting for password prompt:\nBECOME-SUCCESS-smnurvzoeqwqcapbnmmyrhlaautxdumn\n{\&quot;src\&quot;: \&quot;/tmp/testfile2\&quot;, \&quot;group\&quot;: \&quot;root\&quot;, \&quot;uid\&quot;: 0, \&quot;dest\&quot;: \&quot;/tmp/testfile2link\&quot;, \&quot;changed\&quot;: false, \&quot;owner\&quot;: \&quot;root\&quot;, \&quot;state\&quot;: \&quot;link\&quot;, \&quot;gid\&quot;: 0, \&quot;mode\&quot;: \&quot;0777\&quot;, \&quot;invocation\&quot;: {\&quot;directory_mode\&quot;: null, \&quot;force\&quot;: false, \&quot;remote_src\&quot;: null, \&quot;path\&quot;: \&quot;/tmp/testfile2link\&quot;, \&quot;owner\&quot;: null, \&quot;follow\&quot;: false, \&quot;group\&quot;: null, \&quot;state\&quot;: \&quot;link\&quot;, \&quot;content\&quot;: null, \&quot;serole\&quot;: null, \&quot;diff_peek\&quot;: null, \&quot;setype\&quot;: null, \&quot;dest\&quot;: \&quot;/tmp/testfile2link\&quot;, \&quot;selevel\&quot;: null, \&quot;original_basename\&quot;: null, \&quot;regexp\&quot;: null, \&quot;validate\&quot;: null, \&quot;src\&quot;: \&quot;/tmp/testfile2\&quot;, \&quot;seuser\&quot;: null, \&quot;recurse\&quot;: false, \&quot;delimiter\&quot;: null, \&quot;mode\&quot;: null, \&quot;backup\&quot;: null}, \&quot;size\&quot;: 14}\n&quot;}

PLAY RECAP *********************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=1 "><pre class="notranslate"><code class="notranslate">PLAY [the last task will throw an error] ***********************************

TASK [create files - that will work] *************************************************************
ok: [localhost] =&gt; (item=testfile1)
ok: [localhost] =&gt; (item=testfile2)

TASK [create links - that will crash] *************************************************************
fatal: [localhost]: FAILED! =&gt; {"failed": true, "msg": "ERROR! privilege output closed while waiting for password prompt:\nBECOME-SUCCESS-smnurvzoeqwqcapbnmmyrhlaautxdumn\n{\"src\": \"/tmp/testfile2\", \"group\": \"root\", \"uid\": 0, \"dest\": \"/tmp/testfile2link\", \"changed\": false, \"owner\": \"root\", \"state\": \"link\", \"gid\": 0, \"mode\": \"0777\", \"invocation\": {\"directory_mode\": null, \"force\": false, \"remote_src\": null, \"path\": \"/tmp/testfile2link\", \"owner\": null, \"follow\": false, \"group\": null, \"state\": \"link\", \"content\": null, \"serole\": null, \"diff_peek\": null, \"setype\": null, \"dest\": \"/tmp/testfile2link\", \"selevel\": null, \"original_basename\": null, \"regexp\": null, \"validate\": null, \"src\": \"/tmp/testfile2\", \"seuser\": null, \"recurse\": false, \"delimiter\": null, \"mode\": null, \"backup\": null}, \"size\": 14}\n"}

PLAY RECAP *********************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=1 
</code></pre></div>
<p dir="auto">I think the local connector misbehaves with more then just the <em>file</em> module, when using <code class="notranslate">with_items</code>. I have another issue open (<a href="https://github.com/ansible/ansible-modules-core/issues/2552" data-hovercard-type="issue" data-hovercard-url="/ansible/ansible-modules-core/issues/2552/hovercard">pip module does not work with_items in Ansible 2.0 #2552</a>) where i suspected the <em>pip</em> module having problems <code class="notranslate">with_items</code>. However, the general error remains the same in both issues:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ERROR! privilege output closed while waiting for password prompt"><pre class="notranslate"><code class="notranslate">ERROR! privilege output closed while waiting for password prompt
</code></pre></div>
<p dir="auto">During the investigation of the other issue, I found out that the error for it was introduced with commit <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/ansible/ansible/commit/53e86f3130145ce40606cec32aef2858756a20ab/hovercard" href="https://github.com/ansible/ansible/commit/53e86f3130145ce40606cec32aef2858756a20ab"><tt>53e86f3</tt></a>, which was merged with PR <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="118424201" data-permission-text="Title is private" data-url="https://github.com/ansible/ansible/issues/13261" data-hovercard-type="pull_request" data-hovercard-url="/ansible/ansible/pull/13261/hovercard" href="https://github.com/ansible/ansible/pull/13261">#13261</a>. I haven't checked if it is the same for this issue, but it could be a first trace.</p>