Erratic SSH Connection

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

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.