Ansible for Proxmox VE · Module 01
ansible-core; the managed nodes only require Python.Which machines
What to do
The plan
Everything else (roles, handlers, variables, templates) is structure on top of these three.
all:
children:
pve: # group: all Proxmox VE nodes
hosts:
pve01: {ansible_host: 192.168.0.1}
pve02: {ansible_host: 192.168.0.2}
pve03: {ansible_host: 192.168.0.3}
vars:
ansible_user: root
pve_primary: # group with exactly one member
hosts: {pve01: null}
pve_secondary:
hosts: {pve02: null, pve03: null}A host may be in several groups. We will use exactly that in module 03.
Check that Ansible reads it the way you meant it:
ansible.cfg: stop typing the same flagshost_key_checking = False disables SSH host key verification. Acceptable in a throwaway lab, never in production. There you pre-seed known_hosts.
One module, one run, no file:
pve is the group from the inventory (all, pve01, pve* also work)-m names the module-a passes its argumentsYour key is on the nodes, so nothing asks for a password. Where it is not, --ask-pass asks once instead of once per task.
Useful for looking. For changing, write a playbook.
Ansible reads ansible.cfg from the current working directory, and that file is what points at your inventory. From anywhere else:
Three warnings, no error, nothing ran. Almost always a wrong cd, not a broken inventory.
A module that returns data:
SUCCESS means nothing changed, CHANGED means it did. The hosts come back in whatever order they finish — ad-hoc runs them in parallel.
command and shell answer differently: a header line, then raw output.
And when it fails, the return code comes with it:
| Word | Meaning |
|---|---|
SUCCESS |
already in the desired state, nothing done |
CHANGED |
Ansible changed something |
FAILED |
the task ran and did not succeed |
UNREACHABLE |
Ansible never got to the host |
You describe the target state, not the steps.
changedokA playbook that reports only ok still did its job: it checked every statement and found reality already matching.
command is the last resortAnsible cannot know what your command does, so it reports changed even for reading a version number. You saw that in exercise 01.
Look for a module first. Nearly everything you would type on a Proxmox VE node has one, or is reachable through the API.
Then the guard is yours to write:
creates: — skip the task when that path already existswhen: — a condition of your ownchanged_when: / failed_when: — decide yourself what countscommand, with every guard listed: https://docs.ansible.com/ansible/latest/collections/ansible/builtin/command_module.htmlEvery module page online has the same content as ansible-doc <module> on your desktop, which is offline and matches the version you are actually running.
ansible.cfg and the inventory, check it with ansible-inventory --graphfile command twice→ Exercise sheet: Ansible in 30 minutes
pve01 appears twice. Groups are labels, not folders.
Three SUCCESS blocks, in whatever order the hosts finish.
Three [WARNING] lines and nothing else means you are in the wrong directory, not that the inventory is broken. Check pwd first.
Quote the wildcard, or the shell gets to it first.
Patterns are not shell globs: pve0[23] matches nothing, and an empty match is not an error.
The module stats the path, finds it already right, and reports SUCCESS.
Same result on the machine, different report. This is why modules beat commands.
credativ · Ansible for Proxmox VE