# Is there a way to specify a password for the SSH session in config file or CLI

**URL:** <https://forum.ansible.com/t/is-there-a-way-to-specify-a-password-for-the-ssh-session-in-config-file-or-cli/19607>\
**Category:** Ansible Project\
**Created:** [October 25, 2015, 4:45am UTC](https://forum.ansible.com/t/is-there-a-way-to-specify-a-password-for-the-ssh-session-in-config-file-or-cli/19607 "2015-10-25T04:45:23Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![techraf](https://avatars.discourse-cdn.com/v4/letter/t/ba9def/32.png) [@techraf](https://forum.ansible.com/u/techraf)\
**Post date:** [October 25, 2015, 4:45am UTC](https://forum.ansible.com/t/is-there-a-way-to-specify-a-password-for-the-ssh-session-in-config-file-or-cli/19607/1 "2015-10-25T04:45:23Z")

</div>

Is it possible to specify a password for the SSH connection in Ansible (the initial connection not the one for sudo) in a non-interactive way (ie. in config file or a command)?

The configuration file in Ansible has the option `ask_pass` to prompt user to input the password (works ok), but I would like to hardcode the default Raspberry Pi’s password (which is “raspberry” on the original image) for the purpose of unattended configuration of new Pis.

---

<div class="post-metadata">

**Author:** ![Jason3](https://avatars.discourse-cdn.com/v4/letter/j/f9ae1b/32.png) [@Jason3](https://forum.ansible.com/u/Jason3)\
**Post date:** [October 25, 2015, 6:48am UTC](https://forum.ansible.com/t/is-there-a-way-to-specify-a-password-for-the-ssh-session-in-config-file-or-cli/19607/2 "2015-10-25T06:48:36Z")

</div>

You can just use the ansible\_ssh\_pass parameter:

- name: some task  
shell: “echo ‘hello world’”  
ansible\_ssh\_pass: raspberry

[http://docs.ansible.com/ansible/intro\_inventory.html#list-of-behavioral-inventory-parameters](http://docs.ansible.com/ansible/intro_inventory.html#list-of-behavioral-inventory-parameters)

---

<div class="post-metadata">

**Author:** ![techraf](https://avatars.discourse-cdn.com/v4/letter/t/ba9def/32.png) [@techraf](https://forum.ansible.com/u/techraf)\
**Post date:** [October 25, 2015, 1:19pm UTC](https://forum.ansible.com/t/is-there-a-way-to-specify-a-password-for-the-ssh-session-in-config-file-or-cli/19607/3 "2015-10-25T13:19:15Z")

</div>

You mean a parameter in the playbook? Never thought it was possible, but I tried your suggestion and it did not work. I got the following (I am using 1.9.4 now):

`  
ERROR: ansible\_ssh\_pass is not a legal parameter in an Ansible task or handler

`

The link you mentioned is however a description of the parameters for the inventory file. And it works, but I forgot to mention that I do not want to use the inventory file and provide the IP address of the destination machine as a command-line parameter (that’s why I asked [this](https://groups.google.com/forum/#!topic/ansible-project/kiZdBh0FplQ) question - if the “syntax with comma” would allow passing parameters, I could do it).

Summary of my goal (initial configuration only, before I upload the ssh keys with Ansible):

1. pass the destination IP address as a command-line parameter for `ansible-playbook` command
2. hardcode user name “pi” (now in ansible.cfg)
3. hardcode password 'raspberry" (in ansible.cfg, as a command-line parameter or elsewhere, but not in the inventory file which I do not intend to use)

---

<div class="post-metadata">

**Author:** ![Jason3](https://avatars.discourse-cdn.com/v4/letter/j/f9ae1b/32.png) [@Jason3](https://forum.ansible.com/u/Jason3)\
**Post date:** [October 25, 2015, 5:04pm UTC](https://forum.ansible.com/t/is-there-a-way-to-specify-a-password-for-the-ssh-session-in-config-file-or-cli/19607/4 "2015-10-25T17:04:05Z")

</div>

My mistake. I thought i’d used it previously in a playbook, but when i went back and looked it was commented out.

So If i’m understanding all your requirements properly. I think this should work(and i’ve tested it this time).

`ansible-playbook -i 192.168.0.1, playbook.yml --extra-vars "ansible_ssh_pass=rapsberry"`

---

<div class="post-metadata">

**Author:** ![techraf](https://avatars.discourse-cdn.com/v4/letter/t/ba9def/32.png) [@techraf](https://forum.ansible.com/u/techraf)\
**Post date:** [October 25, 2015, 10:52pm UTC](https://forum.ansible.com/t/is-there-a-way-to-specify-a-password-for-the-ssh-session-in-config-file-or-cli/19607/5 "2015-10-25T22:52:12Z")

</div>

Thank you. That’s the solution.

But… I would like to ask if your example really did work for you?

I managed to do what I wanted, but in addition I also had to pass a variable to hosts in playbook:

ansible-playbook -i 192.168.0.1, playbook.yml --extra-vars “newpi=192.168.0.1 ansible\_ssh\_pass=raspberry”

and use:

`- hosts: '{{ newpi }}'`

in the playbook.yml

Is there a way that makes passing the _newpi_ unnecessary?

---

<div class="post-metadata">

**Author:** ![Jason3](https://avatars.discourse-cdn.com/v4/letter/j/f9ae1b/32.png) [@Jason3](https://forum.ansible.com/u/Jason3)\
**Post date:** [October 26, 2015, 2:03am UTC](https://forum.ansible.com/t/is-there-a-way-to-specify-a-password-for-the-ssh-session-in-config-file-or-cli/19607/6 "2015-10-26T02:03:21Z")

</div>

Hmm, well in my test playbook, i just had

- hosts: all

I’m guessing that’s why I didn’t need to pass the additional variable.

---

<div class="post-metadata">

**Author:** ![techraf](https://avatars.discourse-cdn.com/v4/letter/t/ba9def/32.png) [@techraf](https://forum.ansible.com/u/techraf)\
**Post date:** [October 26, 2015, 11:12am UTC](https://forum.ansible.com/t/is-there-a-way-to-specify-a-password-for-the-ssh-session-in-config-file-or-cli/19607/7 "2015-10-26T11:12:50Z")

</div>

Great! I was dragging my trial-and-error results. Now its (your version) in the simplest possible form, I guess.

Thank you again.
