Ansible / Basic: execution, inventory, and typed state / Lesson 7
Trace Ansible configuration and execution context
Identify configuration sources and effective execution context before running an Ansible playbook.
On this page
Lesson goals
- Distinguish configuration file selection from setting precedence.
- Record inventory, identity and working directory for a run.
- Verify a bounded lab context without exposing secrets.
Identify the configuration source
Ansible can read settings from a configuration file and other sources, including environment variables and command-line options. It selects the first configuration file found in its documented search order rather than merging every candidate file. A setting can still be affected by higher-precedence sources. The records below are fictional and no Ansible command or remote action was executed.
Record the expected context
This record identifies a synthetic project and inventory. Also record playbook revision, execution environment, hosts and remote identity. Working directory affects configuration discovery, so a laptop and runner can select different files. A familiar project name does not prove which file was used.
working_directory: synthetic-project
config_source: project-ansible-cfg
inventory_source: lab-inventory
This record is a checklist, not an ansible.cfg file or a runnable command.
Trace effective settings
The second record compares an expected and observed remote user but leaves privilege escalation for separate review. Inspect the setting’s source using documented tools in an authorized environment, and consider relevant playbook keywords and variables as well as configuration. Do not print secrets, full inventories containing sensitive data or private credential paths in shared logs. A correct user alone does not establish the correct target hosts.
expected_remote_user: lab-reader
observed_remote_user: lab-reader
privilege_escalation: separately-reviewed
This fictional comparison does not prove host selection or escalation permissions.
Separate scope from permission
Resolve the inventory pattern and any limit to the final host list before a modifying run. Check the remote user and any privilege escalation against the authorized change. A successful syntax check cannot prove that hosts are reachable or that a task has permission. If the selected file, target or identity differs from the request, stop and correct the source under review.
Verify the lab scenario
In a disposable lab, compare expected configuration, hosts and identity with sanitized evidence. Test a different directory or override and record versions. A bounded read-only check does not authorize a modifying playbook.
Common errors and fixes
Every ansible.cfg file is assumed to merge
- Why it happens
- Ansible selects the first matching configuration file.
- How to fix it
- Identify the file selected under the documented search order.
- Prevent it next time
- Record working directory and configuration source.
A correct remote user is treated as a correct target
- Why it happens
- Inventory selection is a separate decision.
- How to fix it
- Resolve the intended hosts and limit before running.
- Prevent it next time
- Review target and identity together.
A syntax check is treated as operational authorization
- Why it happens
- Syntax does not verify access or side effects.
- How to fix it
- Obtain the required review and use an isolated lab.
- Prevent it next time
- Separate static validation from runtime evidence.
2 practice exercises
1. A runner and a laptop use different working directories. Why might their behavior differ?
Show worked solution
They can discover different configuration files or relative inputs. Compare selected configuration and effective settings with sanitized evidence.
2. The remote user matches but the host list includes an unexpected server. What next?
Show worked solution
Stop before changes, resolve the inventory and limit, and proceed only when the final list matches the authorized scope.
Key takeaways
- Ansible selects a configuration file; other sources can override settings.
- Target hosts, identity and escalation are distinct checks.
- Record context without exposing secrets.