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

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

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

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

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