# Use SSH Machine credential as ansible\_ssh\_private\_key\_file

**URL:** <https://forum.ansible.com/t/use-ssh-machine-credential-as-ansible-ssh-private-key-file/38046>\
**Category:** AWX Project\
**Tags:** awx\
**Created:** [June 2, 2023, 2:14am UTC](https://forum.ansible.com/t/use-ssh-machine-credential-as-ansible-ssh-private-key-file/38046 "2023-06-02T02:14:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Isiah](https://avatars.discourse-cdn.com/v4/letter/i/3ec8ea/32.png) [@Isiah](https://forum.ansible.com/u/Isiah)\
**Post date:** [June 2, 2023, 2:14am UTC](https://forum.ansible.com/t/use-ssh-machine-credential-as-ansible-ssh-private-key-file/38046/1 "2023-06-02T02:14:10Z")

</div>

Is it possible to use an SSH private key stored as a credential as the ansible\_ssh\_private\_key\_file value? Im attempting to rotate SSH keys across many and want to store the new SSH keys in AWX and use it on subsequent runs.

---

<div class="post-metadata">

**Author:** ![AWX\_Project](https://avatars.discourse-cdn.com/v4/letter/a/eada6e/32.png) [@AWX\_Project](https://forum.ansible.com/u/AWX_Project)\
**Post date:** [June 2, 2023, 5:38pm UTC](https://forum.ansible.com/t/use-ssh-machine-credential-as-ansible-ssh-private-key-file/38046/2 "2023-06-02T17:38:46Z")

</div>

ssh machine credentials are passed to the ssh key agent inside of the pod/container. Then when playbook runs, the ssh agent uses that key to connect to your hosts. So in this case, ansible\_ssh\_private\_key\_file wouldn’t be set.

For key rotation, you could callback to the awx server (with awx.awx.credential module, or api call) at the end of the playbook run and update that machine credential with a new ssh key.

AWX Team

---

<div class="post-metadata">

**Author:** ![Isiah](https://avatars.discourse-cdn.com/v4/letter/i/3ec8ea/32.png) [@Isiah](https://forum.ansible.com/u/Isiah)\
**Post date:** [June 2, 2023, 6:08pm UTC](https://forum.ansible.com/t/use-ssh-machine-credential-as-ansible-ssh-private-key-file/38046/3 "2023-06-02T18:08:00Z")

</div>

So is it not possible to call it as a variable like mentioned here? [https://access.redhat.com/solutions/3332591](https://access.redhat.com/solutions/3332591)

---

<div class="post-metadata">

**Author:** ![AWX\_Project](https://avatars.discourse-cdn.com/v4/letter/a/eada6e/32.png) [@AWX\_Project](https://forum.ansible.com/u/AWX_Project)\
**Post date:** [June 7, 2023, 6:43pm UTC](https://forum.ansible.com/t/use-ssh-machine-credential-as-ansible-ssh-private-key-file/38046/4 "2023-06-07T18:43:46Z")

</div>

that article is a little dated, and it seems machine username/password isn’t exposed as a variable in your playbook like in that article’s example. Feel free to use that playbook and try it out though

AWX Team
