# Windows - become\_method runas - password definition

**URL:** <https://forum.ansible.com/t/windows-become-method-runas-password-definition/26779>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [February 19, 2018, 9:40am UTC](https://forum.ansible.com/t/windows-become-method-runas-password-definition/26779 "2018-02-19T09:40:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jeremie\_Levy](https://avatars.discourse-cdn.com/v4/letter/j/e95f7d/32.png) [@Jeremie\_Levy](https://forum.ansible.com/u/Jeremie_Levy)\
**Post date:** [February 19, 2018, 9:40am UTC](https://forum.ansible.com/t/windows-become-method-runas-password-definition/26779/1 "2018-02-19T09:40:07Z")

</div>

Hello  
I am using successfully ansible in my windows environment with Kerberos.  
I am still having trouble if i want to execute a task as another user than my ansible user.

For example, i want to execute specific task as build user to make sure it’s home dir is present - if not i guess my command will create it by login this specific user.

build\_usr\_password is in the var files (i used the debug module to check i can access it)

- name: Touching a file in order to make sure the account home dir is created.  
win\_stat:  
path: C:\Users\build\_usr  
state: present

become: yes  
become\_method: runas  
become\_user: build\_usr@DOMAIN  
password: “{{ build\_usr\_password }}”

I tried **ansible\_become\_password**  **become\_password** and **ansible\_password**. Still same issue:

The full traceback is:  
LogonUser failed (The user name or password is incorrect, Win32ErrorCode 1326)  
At line:623 char:13

- throw [Ansible.Shell.Win32Exception] “LogonUser failed”
- 

```auto

```

- CategoryInfo : OperationStopped: (🙂 , Win32Exception
- FullyQualifiedErrorId : LogonUser failed (The user name or password is incorrect, Win32ErrorCode 1326)

failed: [[hasgqba110.ger.corp.intel.com](http://hasgqba110.ger.corp.intel.com)] (item=bEeq07WG8-RQ.Myr9Ymd) =\> {  
“changed”: false,  
“item”: “bEeq07WG8-RQ.Myr9Ymd”,  
“msg”: “LogonUser failed (The user name or password is incorrect, Win32ErrorCode 1326)”

}

How do i define the password for this task ? (the password is in the vault encrypted file, i don’t want to/can’t pass it via the CLI)

ansible-playbook 2.4.3.0

python version = 2.7.12 (default, Dec 4 2017, 14:50:18) [GCC 5.4.0 20160609]

Jordan ? 🙂

---

<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:** [February 19, 2018, 1:47pm UTC](https://forum.ansible.com/t/windows-become-method-runas-password-definition/26779/2 "2018-02-19T13:47:53Z")

</div>

Hello,

I haven’t tried this myself but I am wondering if you maybe have a password containing a special character, such as $ - I have had trouble with passwords which contain characters which have reserved meaning in powershell in the past?

Also do you perhaps mean to use win\_file module instead of win\_stat? If I recall, win\_stat only returns information on a file, such as whether it exists and is in the expected state, but win\_file will ensure a file or directory exists

`win_file: state: directory path: c:\Users\bld_usr`

Hope this helps,

Jon

---

<div class="post-metadata">

**Author:** ![Jeremie\_Levy](https://avatars.discourse-cdn.com/v4/letter/j/e95f7d/32.png) [@Jeremie\_Levy](https://forum.ansible.com/u/Jeremie_Levy)\
**Post date:** [February 19, 2018, 1:56pm UTC](https://forum.ansible.com/t/windows-become-method-runas-password-definition/26779/3 "2018-02-19T13:56:23Z")

</div>

Hi  
No $ but @ is there.  
I created a service with the credentials so they are working. (win\_service)  
It’s just for this. And win\_file or win\_stat, it doesn’t matter, I can’t find out how to pass the password.

---

<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:** [February 19, 2018, 8:08pm UTC](https://forum.ansible.com/t/windows-become-method-runas-password-definition/26779/4 "2018-02-19T20:08:52Z")

</div>

While become, become\_method, become\_flags, and become\_user can be play or task directive, the password side is not and either needs to be specified with;

- Passed in when calling ansible-playbook with -K
- Set as a connection variable for the host

What you are looking for is to set the ansible\_become\_pass connection variable for the host, this can be done on either a host/group var set outside the playbook and makes it host specified. If you wanted to set it on the playbook/task side you can do it like this

`

- win\_stat:  
path: C:\Users\build\_user  
become: yes  
become\_method: runas  
become\_user: build\_usr@DOMAIN  
vars:  
ansible\_become\_pass: ‘{{ build\_usr\_password }}’  
`

It is still better to define it on the host/group side instead of the play/task side as you could define different password for each host that runs in a play and so on. Once other thing, the connection variables take precedence over the task directive, so setting ansible\_become\_user: someuser will override the task directory become\_user: anotheruser.

Source for this info  
[http://docs.ansible.com/ansible/latest/become.html#connection-variables](http://docs.ansible.com/ansible/latest/become.html#connection-variables)

Thanks

Jordan

---

<div class="post-metadata">

**Author:** ![Jeremie\_Levy](https://avatars.discourse-cdn.com/v4/letter/j/e95f7d/32.png) [@Jeremie\_Levy](https://forum.ansible.com/u/Jeremie_Levy)\
**Post date:** [February 21, 2018, 10:42am UTC](https://forum.ansible.com/t/windows-become-method-runas-password-definition/26779/5 "2018-02-21T10:42:21Z")

</div>

Worked!  
Thank you so much!  
Sorry i miss this information.
