Override the Ansible_ssh_password set in the dynamic inventory script

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

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