# windows - ansible.. create user and run remaining tasks with the user created

**URL:** <https://forum.ansible.com/t/windows-ansible-create-user-and-run-remaining-tasks-with-the-user-created/28942>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [November 5, 2018, 12:57pm UTC](https://forum.ansible.com/t/windows-ansible-create-user-and-run-remaining-tasks-with-the-user-created/28942 "2018-11-05T12:57:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nadim\_mansour](https://avatars.discourse-cdn.com/v4/letter/n/a698b9/32.png) [@nadim\_mansour](https://forum.ansible.com/u/nadim_mansour)\
**Post date:** [November 5, 2018, 12:57pm UTC](https://forum.ansible.com/t/windows-ansible-create-user-and-run-remaining-tasks-with-the-user-created/28942/1 "2018-11-05T12:57:53Z")

</div>

In the first task I am creating a user called cbsadmin. In the second task I am copying a file from templates to tmp and then installing oracle

is it possible to run the second and third task using the user I created in the first task (user: cbsadmin) rather than using Administrator.

Administrator is the user I am connecting to the machine through ansible  
please advice ?

**- name: Create cbs-admin windows user**  
**win\_user:**  
**name: cbsadmin**  
**password:**  
**state: present**  
**groups:**  
**- Administrators**

**- name: Copy**  
**template:**  
**src: client.rsp.j2**  
**dest: C:\tmp\client.rsp**

**- name: Install Oracle client 12.1.0.2.1**  
**win\_command: C:\tmp\ODAC121021\_x64\setup.exe -silent -responseFile C:\tmp\client.rsp**  
**ignore\_errors: yes**

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [November 5, 2018, 4:23pm UTC](https://forum.ansible.com/t/windows-ansible-create-user-and-run-remaining-tasks-with-the-user-created/28942/2 "2018-11-05T16:23:23Z")

</div>

Not tried this myself, but you can probably do this using ‘become’ See [https://docs.ansible.com/ansible/latest/user\_guide/become.html#become-and-windows](https://docs.ansible.com/ansible/latest/user_guide/become.html#become-and-windows)

One issue you might hit is the new user’s home directory is not yet created until an interactive login has occurred for the new user. I haven’t actually tested whether this is a problem as in my case it was easy enough to create the directory I needed using `win_file` module (its possible that if you use become this won’t be an issue).

Hope this helps,

Jon

---

<div class="post-metadata">

**Author:** ![jborean](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jborean/32/1525_2.png) [@jborean](https://forum.ansible.com/u/jborean)\
**Post date:** [November 5, 2018, 9:12pm UTC](https://forum.ansible.com/t/windows-ansible-create-user-and-run-remaining-tasks-with-the-user-created/28942/3 "2018-11-05T21:12:31Z")

</div>

Using become is what you need, you shouldn’t have to worry about creating the profile as become will do that for you when it first logs on as that user. You just need to make sure you don’t manually create that profile before becoming that user as Windows will then create the profile at a different path.

Thanks

Jordan
