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.cfgand a playbook - Key-based SSH set up by cloud-init (
ssh_authorized_keys) - Idempotence: run the playbook twice
Topology
| Node | Image | CPUs / memory | Addresses | Role |
|---|---|---|---|---|
ctl | debian-13 | 1 / 1GiB | mgmt 10.128.0.11 | Ansible, key, inventory, playbook |
n1 | debian-13 | 1 / 1GiB | mgmt 10.128.0.12 | Managed (web) |
n2 | debian-13 | 1 / 1GiB | mgmt 10.128.0.13 | Managed (web) |
n3 | debian-13 | 1 / 1GiB | mgmt 10.128.0.14 | Managed (db) |
Before you start
bash
vz image pull disk debian-13Run it
bash
cd examples/28-ansible-control
vz validate
vz up
vz node ls
ssh lab@10.128.0.11 # password: labFirst 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.12Notes
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