Exercise 02 — Preparing the Nodes
Ansible for Proxmox VE · Module 02
~15 min · in ~/ansible-proxmox · after exercise 01
Objective: bring three freshly installed nodes to the state a cluster needs, and prove that running it a second time changes nothing.
Everything here was on the slides; the handout for this module is the reference. Handlers · apt · deb822_repository · file · Proxmox package repositories
1 — Fill in the playbook
playbooks/10-node-prep.yml is a skeleton: the task names, the order and the handler are already there, and every body is an ansible.builtin.debug with a TODO. Replace the four that say TODO:
| Task | Module |
|---|---|
| Update apt cache (the handler) | apt, update_cache: true |
| Disable the enterprise repositories | file, state: absent, over a loop |
| Enable the no-subscription repository | deb822_repository |
| Install the admin tools | apt |
Uncomment the two notify: lines while you are there, and look the modules up rather than guessing:
ansible-doc ansible.builtin.deb822_repository # uris, suites, components, signed_by
ansible-doc -s ansible.builtin.apt # every option as a snippetsuites should be the release the node reports, not the string trixie. The fact is ansible_distribution_release.
Done when: task 2 gets past all four without an error.
2 — See what it would do
ansible-playbook playbooks/10-node-prep.yml --check --diffDone when: tasks report changed, nothing fails, and the diff shows you the repository file before it is written anywhere.
3 — Run it, then run it again
ansible-playbook playbooks/10-node-prep.yml
ansible-playbook playbooks/10-node-prep.ymlDone when:
# first run
pve01 : ok=8 changed=4 unreachable=0 failed=0
# second run
pve01 : ok=7 changed=0 unreachable=0 failed=0
changed=0 is the point of the exercise. One task fewer on the second run is worth a second of thought: which one, and why?
4 — Two tasks that do not change anything
The playbook ends with a resolution check and a time check. Neither configures anything. Read those two tasks and answer for yourself why changed_when: false is on one of them, and what --check would do without check_mode: false on the other.
Done when: you can say what would break if both lines were removed.
If you finish early
- Add
htoptopve_packagesininventory/group_vars/pve.ymland re-run. How many tasks reportchanged? ansible pve01 -m ansible.builtin.command -a 'pvecm status'still fails. That is module 03.- Break it on purpose:
ansible pve03 -m ansible.builtin.command -a 'hostname bogus', then re-run with--limit pve03. Which task notices, and which does not? Set the hostname back afterwards.
Solutions
Solutions are discussed live with the trainer.