Fork me on GitHub

Herr Knedel/Controlling PIs remotely with Ansible

Created Fri, 25 Jun 2021 00:00:00 +0000 Modified Mon, 28 Mar 2022 18:10:38 +0000 Difficulty level: Not too easy and not too hard

144 Words

After creating a Kubernetes cluster in the Great things with containers: Kubenetes cluster and NFS storage tutorial, I would now like to be able to address these machines via Ansible.

A new key is required for this:
x
+
Terminal

$ ssh-keygen -b 4096

The new public key added to the “/home/pi/.ssh/authorized_keys” file of all servers (Server 1, Server 2 and Server 3).Also, this package must be installed for Ansible:
x
+
Terminal

$ sudo apt-get install -y ansible

After that the Raspberrys have to be entered into the “/etc/ansible/hosts” file:

[raspi-kube.clust]
ip-server-1:ssh-port ansible_ssh_user=username 
ip-server-2:ssh-port ansible_ssh_user=username 
ip-server-3:ssh-port ansible_ssh_user=username 

Now the configuration can be checked as follows:

x
+
Terminal

$ ansible all -m ping --ssh-common-args='-o StrictHostKeyChecking=no'

See: Now you can run playbooks or commands, for example, reboot all servers:
x
+
Terminal

$ ansible raspi -m shell -a 'sudo /sbin/reboot'