# Using new SSH password when running task

**URL:** <https://forum.ansible.com/t/using-new-ssh-password-when-running-task/26832>\
**Category:** Ansible Project\
**Created:** [February 22, 2018, 11:54pm UTC](https://forum.ansible.com/t/using-new-ssh-password-when-running-task/26832 "2018-02-22T23:54:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cody\_Harlow](https://avatars.discourse-cdn.com/v4/letter/c/59ef9b/32.png) [@Cody\_Harlow](https://forum.ansible.com/u/Cody_Harlow)\
**Post date:** [February 22, 2018, 11:54pm UTC](https://forum.ansible.com/t/using-new-ssh-password-when-running-task/26832/1 "2018-02-22T23:54:31Z")

</div>

So I have a role that pulls a password from a website using the uri method and I store it in a variable. I call the variable like this: varname.json.password. How can I use this password when Ansible jumps to the next play? I tried setting ansible\_user and ansible\_ssh\_pass as variables, and I can see it change the user but it always rejects the password. Am I missing something simple, or can this not be done? I’ve hard coded the password and it’s worked before but it appears when I try to call the variable, something isn’t passing properly.

---

<div class="post-metadata">

**Author:** ![Cody\_Harlow](https://avatars.discourse-cdn.com/v4/letter/c/59ef9b/32.png) [@Cody\_Harlow](https://forum.ansible.com/u/Cody_Harlow)\
**Post date:** [February 22, 2018, 11:56pm UTC](https://forum.ansible.com/t/using-new-ssh-password-when-running-task/26832/2 "2018-02-22T23:56:18Z")

</div>

I should mention that I call the variable using hostvars[‘localhost’][‘varname’][‘json’][‘password’].

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [February 23, 2018, 2:25pm UTC](https://forum.ansible.com/t/using-new-ssh-password-when-running-task/26832/3 "2018-02-23T14:25:17Z")

</div>

Without the code there is very little we can help with.

Variables in Ansible are global and are available between play in the same playbook.  
To get variable from another host you would need to use hostvars.

---

<div class="post-metadata">

**Author:** ![Cody\_Harlow](https://avatars.discourse-cdn.com/v4/letter/c/59ef9b/32.png) [@Cody\_Harlow](https://forum.ansible.com/u/Cody_Harlow)\
**Post date:** [February 23, 2018, 5:28pm UTC](https://forum.ansible.com/t/using-new-ssh-password-when-running-task/26832/4 "2018-02-23T17:28:55Z")

</div>

So I guess this turns into a question of can I start a new SSH connection with a new password and user when it runs a new play?
