# Override the Ansible\_ssh\_password set in the dynamic inventory script

**URL:** <https://forum.ansible.com/t/override-the-ansible-ssh-password-set-in-the-dynamic-inventory-script/24050>\
**Category:** Ansible Project\
**Created:** [March 24, 2017, 12:35am UTC](https://forum.ansible.com/t/override-the-ansible-ssh-password-set-in-the-dynamic-inventory-script/24050 "2017-03-24T00:35:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Levi\_Blaney](https://avatars.discourse-cdn.com/v4/letter/l/22d042/32.png) [@Levi\_Blaney](https://forum.ansible.com/u/Levi_Blaney)\
**Post date:** [March 24, 2017, 12:35am UTC](https://forum.ansible.com/t/override-the-ansible-ssh-password-set-in-the-dynamic-inventory-script/24050/1 "2017-03-24T00:35:24Z")

</div>

Hey,

I have a dynamic inventory script. The script sets these variables…

`

“Server01”{  
“ansible\_host”: “xxx.xxx.xxx.xxx”,  
“ansible\_ssh\_host”: “xxx.xxx.xxx.xxx”,  
“ansible\_ssh\_pass”: “xxxxxxxxxxxx”,  
}

`

That way when you spin up a new cloud host you can immediately call a role or playbook on it. I have set up a role using the user module and have used it to set up a new ansible user and ssh key and tested it by sshing from the cmd line to the machine. The problem I have is that I changed the root password on that box and now all ansible task’s fail because it’s defaulting to the ansible\_ssh\_pass.

`

ansible Test -m ping  
Server01 | UNREACHABLE! =\> {  
“changed”: false,  
“msg”: “ERROR! Authentication failure.”,  
“unreachable”: true  
}

`

Do I have something I can change in mmy playbook or cmd line to make it try ssh via key and not password?

Thanks,  
Levi

---

<div class="post-metadata">

**Author:** ![Matt\_Davis](https://avatars.discourse-cdn.com/v4/letter/m/ce7236/32.png) [@Matt\_Davis](https://forum.ansible.com/u/Matt_Davis)\
**Post date:** [March 24, 2017, 1:06am UTC](https://forum.ansible.com/t/override-the-ansible-ssh-password-set-in-the-dynamic-inventory-script/24050/2 "2017-03-24T01:06:07Z")

</div>

Sure- you can override an inventory-set ansible\_password with the vars keyword on a play or task:

# for the whole play

- hosts: thing\_whose\_password\_has\_changed  
vars:  
ansible\_password: “{{ new\_target\_password }}”  
tasks:
- ping:

or

# on a specific task

- hosts: thing\_whose\_password\_has\_changed  
tasks:
- ping:

vars:  
ansible\_password: “{{ new\_target\_password }}”

If you’re
