title: Ansible lineinfile give an error with /etc/hosts
body: <p>I have this simple task in my role:</p>
  
  <pre><code>- name: Updating the /etc/hosts
    lineinfile: dest=/etc/hosts line="192.168.99.100  {{ item }}"
    with_items: 
      - domain1.com
      - domain2.com
    tags: etc
  </code></pre>
  
  <p>When I run my Ansible playbook:</p>
  
  <pre><code>robe:ansible-develop robe$ ansible-playbook -i inventory develop-env.yml -vvvv --extra-vars "user=`whoami`" --tags etc --become-user=robe --ask-become-pass
  SUDO password: 
  
  PLAY [127.0.0.1] ************************************************************** 
  
  GATHERING FACTS *************************************************************** 
  &lt;127.0.0.1&gt; REMOTE_MODULE setup
  &lt;127.0.0.1&gt; EXEC ['/bin/sh', '-c', 'mkdir -p /tmp/ansible-tmp-1446050161.27-256837595805154 &amp;&amp; chmod a+rx /tmp/ansible-tmp-1446050161.27-256837595805154 &amp;&amp; echo /tmp/ansible-tmp-1446050161.27-256837595805154']
  &lt;127.0.0.1&gt; PUT /var/folders/x1/dyrdksh50tj0z2szv3zx_9rc0000gq/T/tmpMYjnXz TO /tmp/ansible-tmp-1446050161.27-256837595805154/setup
  &lt;127.0.0.1&gt; EXEC ['/bin/sh', '-c', 'chmod a+r /tmp/ansible-tmp-1446050161.27-256837595805154/setup']
  &lt;127.0.0.1&gt; EXEC /bin/sh -c 'sudo -k &amp;&amp; sudo -H -S -p "[sudo via ansible, key=rqphpqfpcbsifqtnwflmmlmpwrcnkpqe] password: " -u robe /bin/sh -c '"'"'echo BECOME-SUCCESS-rqphpqfpcbsifqtnwflmmlmpwrcnkpqe; LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python /tmp/ansible-tmp-1446050161.27-256837595805154/setup'"'"''
  &lt;127.0.0.1&gt; EXEC ['/bin/sh', '-c', 'rm -rf /tmp/ansible-tmp-1446050161.27-256837595805154/ &gt;/dev/null 2&gt;&amp;1']
  ok: [127.0.0.1]
  
  TASK: [docker-tool-box | Updating the /etc/hosts] ***************************** 
  &lt;127.0.0.1&gt; REMOTE_MODULE lineinfile dest=/etc/hosts line="192.168.99.100 ptxrt.com"
  &lt;127.0.0.1&gt; EXEC ['/bin/sh', '-c', 'mkdir -p /tmp/ansible-tmp-1446050161.49-9492873099893 &amp;&amp; chmod a+rx /tmp/ansible-tmp-1446050161.49-9492873099893 &amp;&amp; echo /tmp/ansible-tmp-1446050161.49-9492873099893']
  &lt;127.0.0.1&gt; PUT /var/folders/x1/dyrdksh50tj0z2szv3zx_9rc0000gq/T/tmpyLOGd6 TO /tmp/ansible-tmp-1446050161.49-9492873099893/lineinfile
  &lt;127.0.0.1&gt; EXEC ['/bin/sh', '-c', u'chmod a+r /tmp/ansible-tmp-1446050161.49-9492873099893/lineinfile']
  &lt;127.0.0.1&gt; EXEC /bin/sh -c 'sudo -k &amp;&amp; sudo -H -S -p "[sudo via ansible, key=nofwziqxytbhjwhluhtzdfcqclqjuypv] password: " -u robe /bin/sh -c '"'"'echo BECOME-SUCCESS-nofwziqxytbhjwhluhtzdfcqclqjuypv; LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python /tmp/ansible-tmp-1446050161.49-9492873099893/lineinfile'"'"''
  &lt;127.0.0.1&gt; EXEC ['/bin/sh', '-c', 'rm -rf /tmp/ansible-tmp-1446050161.49-9492873099893/ &gt;/dev/null 2&gt;&amp;1']
  failed: [127.0.0.1] =&gt; (item=ptxrt.com) =&gt; {"failed": true, "item": "ptxrt.com"}
  msg: The destination directory (/private/etc) is not writable by the current user.
  
  FATAL: all hosts have already failed -- aborting
  
  PLAY RECAP ******************************************************************** 
             to retry, use: --limit @/Users/robe/develop-env.retry
  
  127.0.0.1                  : ok=1    changed=0    unreachable=0    failed=1 
  </code></pre>
  
  <p>I don't understand why the error msg said:</p>
  
  <pre><code> msg: The destination directory (/private/etc) is not writable by the current user.
  </code></pre>
  
  <p>The correct directory should be /etc/hosts.</p>
  
  <p>Any clue?</p>
  
  <p><strong>I am working on MacOS.</strong></p>
  
  <h2>My playbook is:</h2>
  
  <pre><code>- hosts: 127.0.0.1
    connection: local
    become: yes
    become_method: sudo
    become_user: "{{user}}"
    roles:
      - role-1
      - role-2
  </code></pre>
  
  <p>I put the become_user by command line. So all my roles are running with become. And it still doesn't work.</p>