# Erratic SSH Connection

**URL:** <https://forum.ansible.com/t/erratic-ssh-connection/18550>\
**Category:** Ansible Project\
**Created:** [June 19, 2015, 2:46pm UTC](https://forum.ansible.com/t/erratic-ssh-connection/18550 "2015-06-19T14:46:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Manoj\_Govindan](https://avatars.discourse-cdn.com/v4/letter/m/ea5d25/32.png) [@Manoj\_Govindan](https://forum.ansible.com/u/Manoj_Govindan)\
**Post date:** [June 19, 2015, 2:46pm UTC](https://forum.ansible.com/t/erratic-ssh-connection/18550/1 "2015-06-19T14:46:34Z")

</div>

Consider the following two commands:

(1) ansible-playbook --limit dtest --private-key=/path/to/private/key.pem test\_stat.yml  
(2) ansible-playbook --limit dtest test\_stat.yml

The test\_stat playbook is given below:

# An ANSIBLE playbook to execute stat

- name: Play - Stat  
hosts: all  
vars\_files:
- “ssh\_server\_static\_keys/{{ inventory\_hostname }}.yml”  
roles:
- stat

I have a file named ssh\_server\_static\_keys/dtest.yml that contains something like this.

ssh\_host\_rsa\_key: |  
-----BEGIN RSA PRIVATE KEY-----

…  
-----END RSA PRIVATE KEY-----

If I execute the commands (1), followed by (2), both work.  
Executing (1) creates a socket named $HOME/.ansible/cp/ansible-ssh-

As long as that socket is alive, (2) works.

If I execute (2) alone, it doesn’t work. I get the following error:

fatal: [dtest] =\> SSH Error: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).  
while connecting to :

However, (2) alone works without any error for _another_ host, which has a key in ssh\_server\_static\_keys/something.yml.

What am I missing?

Thanks,  
Manoj

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [June 22, 2015, 2:41pm UTC](https://forum.ansible.com/t/erratic-ssh-connection/18550/2 "2015-06-22T14:41:32Z")

</div>

No, unless I’m missing something, this is how ssh works. ControlPersist/Master allows you to reuse the connection so you don’t need to re-authenticate. But if you never authenticated … there is nothing to reuse.
