- Local Execution:
Ansible always targets
localhostwith alocalconnection.inventoryis a simple minimal file defining localhost. - Configuration Defaults:
Default configuration settings are defined in the role scope in
roles/x/defaults/main.yml. (This has the lowest priority and is easily overridden.) - Dynamic Configuration:
The
vars_filesdirective in the playbook combined with a variable (setup) is used to dynamically load specific settings files. - Containerized CI Builds: On GitHub Actions, the Ansible install is tested inside containers, which are created as part of the pipeline for all four flavours.
Setups for different runs are held in configuration profiles
inside the vars/ directory.
File: playbook.yml
This is the core logic.
Each configurable role has a boolean variable (needs to be set true to include the role)
and a tag, used to only run specific roles during development.
There are multiple ways to control the configuration setup.
Specify settings files to load
using the extra vars flag (-e).
# Run with foobar.yml config
ansible-playbook playbook.yml -e "@vars/foobar.yml"Result: Will override role defaults with settings from foobar.yml
If you do not specify a config file,
Ansible will use the variables defined in roles/*/defaults/main.yml.
You can always set specific variables on the command line, which will override any values in role defaults or setup files.
# Run with foobar config, but set in_container flag
ansible-playbook playbook.yml -e "vars/@foobar.yml" -e "in_container=true"Result: Will override role defaults with settings from foobar.yml and set in_container to true.
In this setup, the variable precedence (priority) is:
- Command line (
-e): Highest (overrides everything). - Selected setup (using setup files in
vars): Middle (overrides defaults). - Role Defaults: Lowest (used only if not defined elsewhere).