# Using remote\_user for a single task in a play

**URL:** <https://forum.ansible.com/t/using-remote-user-for-a-single-task-in-a-play/26709>\
**Category:** Ansible Project\
**Created:** [February 12, 2018, 5:05pm UTC](https://forum.ansible.com/t/using-remote-user-for-a-single-task-in-a-play/26709 "2018-02-12T17:05:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Robert\_Beaver](https://avatars.discourse-cdn.com/v4/letter/r/22d042/32.png) [@Robert\_Beaver](https://forum.ansible.com/u/Robert_Beaver)\
**Post date:** [February 12, 2018, 5:05pm UTC](https://forum.ansible.com/t/using-remote-user-for-a-single-task-in-a-play/26709/1 "2018-02-12T17:05:11Z")

</div>

I’m guessing this isn’t possible, but I might have been looking at it too long at this point to know if I’m missing something…

I have a playbook with a role in which one task has a remote\_user and a delegate\_to option set. That task has to run for each host on the delegate\_to server which has a different ssh\_user and password. Using ssh-keys or the same password as the ansible\_ssh\_user, it works okay, however, without ssh keys or the same password, it will fail.

For some people that will be executing this play, they will not be able to use ssh\_keys and their passwords are different from the inventory and the delegate\_to host. I could prompt for the remote\_user and password on play run, however, I have not figured out how to set the password for the single task.

Here is an example. Is there a way to specify the password for jdoe? (note syntax and spacing may be off as I just typed this out)

- name: Sample play  
hosts: all

roles:

- myRole

tasks:

debug:  
msg: “End of play”

In the role/myRole/tasks/main.yml

- include: myfacts.yml

- name: Some task  
command: test 0  
changed\_when: false

- name: Problem task  
remote\_user: jdoe  
command: “shell command”

delegate\_to: ###.###.###.###

- name: Some other task  
command: “test -f file.txt”  
register: myOutput  
changed\_when: false

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [February 12, 2018, 5:09pm UTC](https://forum.ansible.com/t/using-remote-user-for-a-single-task-in-a-play/26709/2 "2018-02-12T17:09:19Z")

</div>

remote\_user is usable, but you need to know about precedence, it will  
only work if you did NOT have an override  
(ansible\_user/ansible\_ssh\_user override it).  
It is normally used to change the 'default' remote\_user or the one set  
in config/play/block/role containing the task.

To set a different remote user when using the variable overrides, just  
set the variable for the task:

- name: Problem task  
&nbsp;&nbsp;command: "shell command"  
&nbsp;&nbsp;delegate\_to: ###.###.###.###  
&nbsp;&nbsp;vars:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ansible\_ssh\_user: jdoe

The vars override the keywords, but the vars are still vars and normal  
variable precedence still applies.

---

<div class="post-metadata">

**Author:** ![Robert\_Beaver](https://avatars.discourse-cdn.com/v4/letter/r/22d042/32.png) [@Robert\_Beaver](https://forum.ansible.com/u/Robert_Beaver)\
**Post date:** [February 12, 2018, 5:25pm UTC](https://forum.ansible.com/t/using-remote-user-for-a-single-task-in-a-play/26709/3 "2018-02-12T17:25:02Z")

</div>

Okay, given that, i should be able to set the ansible\_ssh\_pass there as well. Thanks, I figured I was overlooking something obvious!
