# How do I pass a password as an argument?

**URL:** <https://forum.ansible.com/t/how-do-i-pass-a-password-as-an-argument/20714>\
**Category:** Ansible Project\
**Created:** [March 1, 2016, 2:01am UTC](https://forum.ansible.com/t/how-do-i-pass-a-password-as-an-argument/20714 "2016-03-01T02:01:19Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gilberto\_Valentin](https://avatars.discourse-cdn.com/v4/letter/g/b4bc9f/32.png) [@Gilberto\_Valentin](https://forum.ansible.com/u/Gilberto_Valentin)\
**Post date:** [March 1, 2016, 2:01am UTC](https://forum.ansible.com/t/how-do-i-pass-a-password-as-an-argument/20714/1 "2016-03-01T02:01:19Z")

</div>

I have a playbook that installs the appropriate packages for Active Directory Authentication. When it gets to the “join” portion, Ansible just sits there because the join process is asking the user for the password of the account that has access to join the system to Active Directory. How can I pass my password from vars\_prompt? I have highlighted where I call the variable but I know that is the wrong place since it’s going to try to pass it to my “realm join” command, which isn’t supported. I only added it there to show I want to call it after the “realm join” portion is called.

Here is my playbook:

`

---

<div class="post-metadata">

**Author:** ![Gilberto\_Valentin](https://avatars.discourse-cdn.com/v4/letter/g/b4bc9f/32.png) [@Gilberto\_Valentin](https://forum.ansible.com/u/Gilberto_Valentin)\
**Post date:** [March 1, 2016, 4:29pm UTC](https://forum.ansible.com/t/how-do-i-pass-a-password-as-an-argument/20714/2 "2016-03-01T16:29:45Z")

</div>

I changed this a bit by removing the **vars\_prompt** and using expect. Here is what I did:

`

---

<div class="post-metadata">

**Author:** ![Gilberto\_Valentin](https://avatars.discourse-cdn.com/v4/letter/g/b4bc9f/32.png) [@Gilberto\_Valentin](https://forum.ansible.com/u/Gilberto_Valentin)\
**Post date:** [March 2, 2016, 2:02pm UTC](https://forum.ansible.com/t/how-do-i-pass-a-password-as-an-argument/20714/3 "2016-03-02T14:02:53Z")

</div>

Ok, I figured this out. This is how I did it:

`

---

<div class="post-metadata">

**Author:** ![Chris\_Helming](https://avatars.discourse-cdn.com/v4/letter/c/779978/32.png) [@Chris\_Helming](https://forum.ansible.com/u/Chris_Helming)\
**Post date:** [March 12, 2016, 6:37am UTC](https://forum.ansible.com/t/how-do-i-pass-a-password-as-an-argument/20714/4 "2016-03-12T06:37:14Z")

</div>

Thanks, I was just looking for this tonight. Awesome timing!

For encrypting your password, use Ansible Vault. Here’s a quick example:  
[https://gist.github.com/tristanfisher/e5a306144a637dc739e7](https://gist.github.com/tristanfisher/e5a306144a637dc739e7)

I have a vars file called bind\_creds.yml with bind\_user and bind\_password defined.

---

<div class="post-metadata">

**Author:** ![Gilberto\_Valentin](https://avatars.discourse-cdn.com/v4/letter/g/b4bc9f/32.png) [@Gilberto\_Valentin](https://forum.ansible.com/u/Gilberto_Valentin)\
**Post date:** [March 14, 2016, 8:22pm UTC](https://forum.ansible.com/t/how-do-i-pass-a-password-as-an-argument/20714/5 "2016-03-14T20:22:48Z")

</div>

Glad this post helped you. Also, thank you very much for the Ansible Vault info!!

---

<div class="post-metadata">

**Author:** ![Cyriel\_R](https://avatars.discourse-cdn.com/v4/letter/c/77aa72/32.png) [@Cyriel\_R](https://forum.ansible.com/u/Cyriel_R)\
**Post date:** [August 5, 2016, 2:57pm UTC](https://forum.ansible.com/t/how-do-i-pass-a-password-as-an-argument/20714/6 "2016-08-05T14:57:09Z")

</div>

Ohh thank you for this tips 😉

---

<div class="post-metadata">

**Author:** ![Jacob\_brown](https://avatars.discourse-cdn.com/v4/letter/j/7ba0ec/32.png) [@Jacob\_brown](https://forum.ansible.com/u/Jacob_brown)\
**Post date:** [August 30, 2016, 6:08am UTC](https://forum.ansible.com/t/how-do-i-pass-a-password-as-an-argument/20714/7 "2016-08-30T06:08:58Z")

</div>

Hi guys,

Do you do anything for “pre flight checks”? Or is this a one-off playbook your run on newly provisioned servers?

Wouldn’t mind something that goes “am I joined? notify: join ad”

Cheers  
Jacob

---

<div class="post-metadata">

**Author:** ![Chris\_Helming](https://avatars.discourse-cdn.com/v4/letter/c/779978/32.png) [@Chris\_Helming](https://forum.ansible.com/u/Chris_Helming)\
**Post date:** [August 31, 2016, 12:31pm UTC](https://forum.ansible.com/t/how-do-i-pass-a-password-as-an-argument/20714/8 "2016-08-31T12:31:29Z")

</div>

`

- name: Check if machine is bound  
shell: /bin/bash -c “realm list | grep sssd”  
register: realmd\_bound  
changed\_when: false  
ignore\_errors: true

- name: Join using realmd  
expect:  
command: “/bin/bash -c ‘/usr/sbin/realm join -U {{ bind\_user }} {{ bind\_domain }}’”  
responses:  
Password for.\*: “{{ bind\_password }}”  
when: realmd\_bound|failed

`

I’m planning on getting away from realmd but that’s one way to do it with realm.

---

<div class="post-metadata">

**Author:** ![Jacob\_brown](https://avatars.discourse-cdn.com/v4/letter/j/7ba0ec/32.png) [@Jacob\_brown](https://forum.ansible.com/u/Jacob_brown)\
**Post date:** [August 31, 2016, 11:03pm UTC](https://forum.ansible.com/t/how-do-i-pass-a-password-as-an-argument/20714/9 "2016-08-31T23:03:41Z")

</div>

That’s awesome Chris, thank you very much!

I’m still learning Ansible so that’s a huge help. Thanks again!
