# 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/23448>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [January 13, 2017, 8:19am UTC](https://forum.ansible.com/t/run-multiple-tasks-with-different-ansible-users-for-windows-hosts/23448 "2017-01-13T08:19:37Z")\
**Posts on this page:** 3\
**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, 8:19am UTC](https://forum.ansible.com/t/run-multiple-tasks-with-different-ansible-users-for-windows-hosts/23448/1 "2017-01-13T08:19:37Z")

</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

```

```auto

```

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:

`

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

`

```auto

```

```auto

```

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?

---

<div class="post-metadata">

**Author:** ![Matt\_Davis](https://avatars.discourse-cdn.com/v4/letter/m/ce7236/32.png) [@Matt\_Davis](https://forum.ansible.com/u/Matt_Davis)\
**Post date:** [January 13, 2017, 8:19pm UTC](https://forum.ansible.com/t/run-multiple-tasks-with-different-ansible-users-for-windows-hosts/23448/2 "2017-01-13T20:19:16Z")

</div>

The problem is that vars set on the command-line have the highest possible precedence. If you were to set the initial value in inventory, or someplace else with a lower precedence than a play/task var, it’d work fine (verified).

See [http://docs.ansible.com/ansible/playbooks\_variables.html#variable-precedence-where-should-i-put-a-variable](http://docs.ansible.com/ansible/playbooks_variables.html#variable-precedence-where-should-i-put-a-variable) for more details.

-Matt

---

<div class="post-metadata">

**Author:** ![Matt\_Davis](https://avatars.discourse-cdn.com/v4/letter/m/ce7236/32.png) [@Matt\_Davis](https://forum.ansible.com/u/Matt_Davis)\
**Post date:** [January 13, 2017, 8:19pm UTC](https://forum.ansible.com/t/run-multiple-tasks-with-different-ansible-users-for-windows-hosts/23448/3 "2017-01-13T20:19:52Z")

</div>

(ie, vars set by --extra-vars on the command-line cannot be overridden)
