ping inside playbook

Hello,

I bootstrap server security from a bootstrap.yml playbook.

Before restarting the ssh service, I’d like to test that it is possible to ssh into the host via the key mechanism (I have used the authorized_keys module for this purpose).

I’m trying with the ping module as a task, but I’m not sure :

  • if I can ask it to not use password authentication and force using private key authentication
  • how I can force a specific user (I tried user= without success => it is using the user ‘ssh’ ?!?)

Thanks in advance for your insights,

instead of using user=xxx as an argument for the ping module, I use successfully the task remote_user attribute.

But still, I’m unsure if the test works because I am already connected to the host, or because ansible is using the password I provided via the -k option

no apparently I’ve still got this wrong

I’ve seen some interesting variations of:

  • local_action: shell ssh …

For those kinds of tests with keys, feeding it lots of SSH options.

Be careful to launch a command like “echo” and not something interactive.