How to become a user at remote machine when running a role in Ansible playbook
<p>I know this has been discussed in other questions and I have tried various options but nothing seems to be solving my issue.</p>

<p>I am starting to learn Ansible and trying to run a playbook. I have one role which have tasks in it. I want to run the whole playbook as user john on remote machine. Playbook begins with a copying task. Everything was working fine till I started using become and become_user. I tried running the role as user john by specifying in major playbbok :</p>

<pre><code>---
- hosts: target-machine.com
   roles:
   - role: installSoftware
     become: yes
     become_user: john
</code></pre>

<p>Then when executing the playbook, I run the following :</p>

<pre><code> ansible-playbook -s major.yml -K
</code></pre>

<p>which prompts me for </p>

<pre><code>SUDO password:
</code></pre>

<p>I enter the password of user john which exists in the remote target machine. As soon as it starts running playbook, it hangs at the task which requires user as john and complains :</p>

<pre><code>fatal: [target.com]: FAILED! =&gt; {"failed": true, "msg": "Failed to get information on remote file (/home/john/software.zip): MODULE FAILURE"}
</code></pre>

<p>I also tried the following:</p>

<pre><code>---
- hosts: target-machine.com
  become: yes
  become_user: john
  roles:
   - role: installSoftware
</code></pre>

<p>so as to run the whole playbook as user john. It again asks me for the SUDO password and then after 5 minutes complains:</p>

<pre><code>fatal: [openam.ansible-target.com]: FAILED! =&gt; {"changed": false, "failed":       true, "module_stderr": "", "module_stdout": "\r\nSorry, try again                           .\r\n[sudo via ansible, key=kchjtpjorgnvaksspqvgwzzkgtjnxsyv] password: \r\nsudo: 1 incorrect password attempt\r\n", "msg": "MODULE FAILURE"}
</code></pre>

<p>although the password I have entered is correct. On SO it was suggested to increase the SSH timeout which I did in ansible.cfg file:</p>

<pre><code> [ssh_connection]
 ssh_args = -o ServerAliveInterval=60 -o ControlMaster=auto -o ControlPersist=1m
</code></pre>

<p>All I want to mirror is what I would run on target machine:</p>

<pre><code>   su john
   Enter Password:
   john$
</code></pre>

<p>Any help will be appreciated. Thank You.</p>