Skip to content

Ansible Management

Alexander Diemand edited this page Feb 12, 2025 · 1 revision

Manage your cluster using Ansible

preparations

enable ssh login as root to every node

  • check your current ssh key loaded: ssh-add -l
    • outputs: 4096 SHA256:YtYvnte+NLyybBHBH54Wm+s20bQ0HpYbn/jEVh/dPjQ /home/alex/src/id_rsa (RSA)
  • get the public key: cat /home/alex/src/id_rsa.pub (<-- adding .pub)
    • outputs: ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQ..zgVqJ91HX/w== [email protected]
    • copy that whole output
  • on each node when logged in as root:
    • execute this command: umask 077; mkdir -vp ~/.ssh; touch ~/.ssh/authorized_keys; vi ~/.ssh/authorized_keys
    • press "i" and paste into the editor your public key
    • press "", press ":wq" to write to the file and leave the editor
  • now, you should be able to login to each node as root without a password request

prepare list of nodes hostnames

Create a file hosts that contain the hostnames of your cluster's nodes:

kubian:
  hosts:
    kubian10:
    kubian20:
    kubian22:
    kubian27:
    kubian31:
    kubian35:

tasks

install a package using apt

ansible -i ./hosts kubian -u root -m ansible.builtin.apt -a "name=nfs-common state=present"

this will go through all hosts under kubian in your hosts file, and make sure that the named package is installed on each node.

update entry in /etc/hosts

ansible -i ./hosts kubian -u root -m shell -a "sed -e 's/^[^ ]\+\( \+registry.cluster\).*/10.244.6.1\1/' -i /etc/hosts"

this will set the IP address of "registry.cluster" to a new value in /etc/hosts of each node.