Repository navigation
Ansible Inventory
By using different inventory locations, Ansible can be used to run the same Playbooks on different sets of hosts. This is particularly useful when dealing with multiple PVE hosts or clusters.
The showcase items here use two inventory directories, lab and lab-minimal that use a combination of static files and dynamic plugins. And also contain group_vars and host_vars directories specific to the respective inventory.
Alternatively, hosts can be added to the inventory using the cloudcodger.proxmox_client.add_guest_host role. This provides a way of using the lab-minimal inventory and still configure guest machines that use DHCP. The builder.yml playbook provides and example of this.
These include the local_aliases.yml and pve.yml files and contain basic static inventory details.
A unique method of defining Ansible variables is by using inventory aliases.
The local_aliases.yml demonstrate how to use them for creating multiple playbooks that all run on localhost but require different values for the same variables.
All of the alias hostnames start with local_ to emphasize the fact that they are aliases for localhost.
The local_lxc and local_qemu groups, provide a location for setting variables for the LXC containers (group_vars/local_lxc.yml) and QEMU VMs (group_vars/local_qemu.yml), respectively. The proxmox_clients group includes both of the local_lxc and local_qemu groups so that proxmox_client_* variables can be set in one place (group_vars/proxmox_clients.yml).
This may seem overly complex at first, because the variables in these files are unique, they could all have been set in group_vars/all.yml or even just combined together in group_vars/proxmox_clients.yml. This is just one example showing how variables can be grouped into different vars files. Go ahead and pick the option you like best.
This file defines the proxmox_hosts group used in launching either, the PVE node, or the PVE lab cluster.
The name of the inventory.proxmox.yml files end with .proxmox.yml as required by the Proxmox inventory plugin and will cause Ansible launch that plugin to dynamically read the inventory from a PVE node. It must be configured to account for the certificate in use and requires a Proxmox user with either a password or an API token (token_id) and the associated secret (token_secret) for access. For a PVE cluster, the plugin will generates an inventory for the entire cluster. The want_facts setting is different for the two inventory directories.
The plugin files in this showcase use the s1m0ne@pve user with a dedicated inventory API token that is limited to the PVEAuditor permissions role in order to limit the security exposure.