To Connect Linux host, Create the ansible inventory file like below
Add the follow line into the hosts
file. This is sample Kubernetes nodes, we use master node as control server.
[master]
localhost ansible_connection=local
[workers]
worker01 ansible_connection=ssh ansible_user=root
worker02 ansible_connection=ssh ansible_user=root
[cluster:children]
master
workers
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/id_ed25519.pub user@hostname
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
Start the docker container like this CentOS8 with SSH
create the hosts
file like below:
[nodes]
node01 ansible_host=192.168.16.7 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"
}