# Run multiple tasks with different Ansible users for Windows hosts

**URL:** <https://forum.ansible.com/t/run-multiple-tasks-with-different-ansible-users-for-windows-hosts/23451>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [January 13, 2017, 10:43am UTC](https://forum.ansible.com/t/run-multiple-tasks-with-different-ansible-users-for-windows-hosts/23451 "2017-01-13T10:43:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![davidfof](https://avatars.discourse-cdn.com/v4/letter/d/73ab20/32.png) [@davidfof](https://forum.ansible.com/u/davidfof)\
**Post date:** [January 13, 2017, 10:43am UTC](https://forum.ansible.com/t/run-multiple-tasks-with-different-ansible-users-for-windows-hosts/23451/1 "2017-01-13T10:43:51Z")

</div>

Hi all,

I have role that contains several tasks that should be run by different Ansible users. The playbook that uses this role should run on Windows hosts and I do this using a command similar to the following:

```auto
 

ansible-playbook --limit windows -i hosts --extra-vars "ansible_user=my_username ansible_password=my_password" site.yaml

```

Most of the tasks in the role should be done through the user specified in the command above while others should use another Windows user. For these other tasks, I try to override the user credential variables as shown below:

```auto

 - include: task_for_other_windows_user.yml vars: ansible_user: "{{other_windows_user_name}}" ansible_password: "{{other_windows_user_pw}}"

```

This unfortunately doesn’t work as the playbook appears to use the same user initially defined, on all the plays. How do I implement what I’m trying to achieve here?

I also raised an issue for this in Ansible’s GitHub.

David

---

<div class="post-metadata">

**Author:** ![Johannes\_Kastl](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@Johannes\_Kastl](https://forum.ansible.com/u/Johannes_Kastl)\
**Post date:** [January 18, 2017, 10:12am UTC](https://forum.ansible.com/t/run-multiple-tasks-with-different-ansible-users-for-windows-hosts/23451/2 "2017-01-18T10:12:35Z")

</div>

> ansible-playbook --limit windows -i hosts --extra-vars  
> "ansible\_user=my\_username ansible\_password=my\_password" site.yaml

> - include: task\_for\_other\_windows\_user.yml vars: ansible\_user:  
> "{{other\_windows\_user\_name}}" ansible\_password:  
> "{{other\_windows\_user\_pw}}"

Look here:

> [https://docs.ansible.com/ansible/playbooks\_variables.html#variable-precedence-where-should-i-put-a-variable](https://docs.ansible.com/ansible/playbooks_variables.html#variable-precedence-where-should-i-put-a-variable)

This says the last one wins:  
role defaults [1]  
[...]  
play vars  
[...]  
role and include vars  
block vars (only for tasks in block)  
task vars (only for the task)  
extra vars (always win precedence)

So your command line options override the task variables and those  
from includes.

Solution: Put your command line vars in the playbook or the role  
defaults, these get overwritten

> I also raised an issue for this in Ansible's GitHub.

Care to tell us which one?

Johannes
