This page looks best with JavaScript enabled

Ansible SSH prompt known_hosts issue explained and solved

 ·  ☕ 2 min read  ·  🐧 sysadmin

Article about known_hosts: What is known_hosts File in Linux

  1. Here is a video tutorial

Scripts and configuration files are available here:

  1. Cleanup known_hosts in /home/user/.ssh directory
  2. Run the ansible playbook with the below command:
1
ansible-playbook ssh-session.yaml
  1. Break it with ctrl+c
  2. Run the below command:
1
./ssh-session.ssh
  1. Check the result in known_hosts
1
cat ~/.ssh/known_hosts
  1. You will see all the entries added by ssh.
  2. Run the ansible playbook with the below command one more time:
1
ansible-playbook ssh-session.yaml
  1. Type yes few times and then break it with ctrl+c
  2. Check the result in the screen.
  3. Cleanup known_hosts in /home/user/.ssh directory and then run the ansible playbook with the below command:
1
ansible-playbook ssh-session.yaml --ssh-common-args='-o StrictHostKeyChecking=no'

Problem is solved.

Working solution that I do not recommend
  1. Cleanup known_hosts in /home/user/.ssh directory
  2. Display global variables with the below command:
1
export
  1. Perform the below command:
1
export ANSIBLE_HOST_KEY_CHECKING=False
  1. Connect using ssh to the remote host
1
ssh username@hostname
  1. Run the ansible playbook with the below command:
1
ansible-playbook ssh-session.yaml
  1. Check the result in known_hosts
1
cat ~/.ssh/known_hosts
  1. See do you have entries added into known_hosts
Solution that I have found in the Internet that I really do not recommend
  1. Run the ansible playbook with the below command:
1
ansible-playbook ssh-keyscan.yaml
  1. Check the result in known_hosts
1
cat ~/.ssh/known_hosts
  1. Get rid of unecessary entries in known_hosts
  2. Run the ansible playbook with the below command:
1
ansible-playbook ssh-session.yaml
  1. Watch the mentioned video to understand what happened and why.
Share on

sysadmin
WRITTEN BY
sysadmin
QA & Linux Specialist