execute ssh-copy-id, if passwdless login not able

in Ansible playbook, I want to do two task, one to check passwdless ssh login is enabled or not, and in another task if passwdless login not abled for the remote host, then execute the ssh-copy-id command.
I have written the following playbook, but it is not working as desired, please help me to resolve the issue.

in Ansible playbook, I want to do two task, one to check passwdless ssh login is enabled or not, and in another task if
passwdless login not abled for the remote host, then execute the ssh-copy-id command.
I have written the following playbook, but it is not working as desired, please help me to resolve the issue.

Gathering facts already requires a working SSH connection, so it stops before executing your tasks.

It doesn't really makes sense to me what you are doing.

Regards
          Racke

I am newbie to ansible. I am trying to execute two different task.

  1. checking passwdless login. executing hostname and id command in the remote host and printing its result when succcess.
  2. executing ssh-copy-id and copying pub key to the remote host

I want to execute the second task, only if the first task failed.

Please let me know the mistake I am doing here.

I am newbie to ansible. I am trying to execute two different task.
1. checking passwdless login. executing hostname and id command in the remote host and printing its result when succcess.
2. executing ssh-copy-id and copying pub key to the remote host

I want to execute the second task, only if the first task failed.

Please let me know the mistake I am doing here.

Please read carefully the Ansible output and my reply.

Gathering facts requires a working SSH connection, so your tasks are never executed when this is the case.

Regards
         Racke