Interview Prep/Ansible/Playbooks, Plays, Tasks and Handlers

How do relative paths resolve in a playbook?

IntermediateConceptPlaybooks, Plays, Tasks and Handlers
Answer

Ansible searches by context. For roles, copy/template/script look in the role's files/ or templates/ first. For plain playbooks they look relative to the playbook directory, in files/ or templates/. Variables files and include_tasks paths are relative to the including file.

Useful magic variables: playbook_dir, role_path, inventory_dir, inventory_file. Running from another working directory is fine, but ansible.cfg is looked up in the current directory, so use ANSIBLE_CONFIG in wrappers and CI.

All Ansible questions Roadmap: Ansible

More on Playbooks, Plays, Tasks and Handlers