Configure SSH Connetion

To Connect Linux host, Create the ansible inventory file like below

sample inventory file for Linux servers

Add the follow line into the hosts file. This is sample Kubernetes nodes, we use master node as control server.

localhost              ansible_connection=local

worker01     ansible_connection=ssh        ansible_user=root
worker02     ansible_connection=ssh        ansible_user=root


Generate the ssh key in the master server and copy the public key in the work node root user. Also enable the root user ssh access for the worker nodes.

ssh-keygen -N ''  -t ed25519 -f ~/.ssh/id_ed25519 -C "Secure Key"

ssh-copy-id  -i ~/.ssh/ user@hostname

Test the ssh connection

ansible -i hosts workers  -m ping

ansible -m command -a "df -h" servers

ansible -i hosts  all -m ping -u <username>

ansible -i hosts all -m ping -u <username> -b

To connect with docker continer

Start the docker container like this CentOS8 with SSH

create the hosts file like below:

node01 ansible_host=    ansible_connection=ssh        ansible_user=root ansible_port=2222 ansible_ssh_private_key_file=~/.ssh/id_ed25519

Test the SSH connection

ansible -i hosts nodes -m ping

node01 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    "changed": false,
    "ping": "pong"

Copyright © 2004, Software Groups