Skip to content

28 Ansible control node ​

A control node with Ansible, an inventory and a playbook, managing three nodes over SSH keys.

What you practice ​

  • An Ansible inventory, ansible.cfg and a playbook
  • Key-based SSH set up by cloud-init (ssh_authorized_keys)
  • Idempotence: run the playbook twice

Topology ​

NodeImageCPUs / memoryAddressesRole
ctldebian-131 / 1GiBmgmt 10.128.0.11Ansible, key, inventory, playbook
n1debian-131 / 1GiBmgmt 10.128.0.12Managed (web)
n2debian-131 / 1GiBmgmt 10.128.0.13Managed (web)
n3debian-131 / 1GiBmgmt 10.128.0.14Managed (db)

Before you start ​

bash
vz image pull disk debian-13

Run it ​

bash
cd examples/28-ansible-control
vz validate
vz up
vz node ls
ssh lab@10.128.0.11        # password: lab

First boot installs packages; give it a minute or two after vz up returns.

Try it ​

bash
ssh lab@10.128.0.11
cd ansible
ansible all -m ping
ansible-playbook site.yml        # changes n1 and n2, then every motd
ansible-playbook site.yml        # again: nothing to change
curl -s http://10.128.0.12

Notes ​

The SSH key pair in init/ctl was generated for this example and is public now; use it only in this lab. Make your own with ssh-keygen -t ed25519.

Clean up ​

bash
vz down
vz destroy --yes   # deletes the overlays and state of this lab