Relative path assumptions

When Ansible parses a playbook, there are certain assumptions that can be made about the relative paths of items referenced by the statements in a playbook. In most cases, paths for things such as variable files to include, task files to include, playbook files to include, files to copy, templates to render, and scripts to execute, are all relative to the directory where the file referencing them resides. Let's explore this with an example playbook and directory listing to show where the files are:

. 
├── a_vars_file.yaml 
├── mastery-hosts 
├── relative.yaml 
└── tasks 
    ├── a.yaml 
    └── b.yaml 
--- 
something: "better than nothing" 
--- 
- name: relative path play 
  hosts: localhost 
  gather_facts: false 

vars_files: - a_vars_file.yaml

tasks: - name: who am I debug: msg: "I am mastery task" - name: var from file debug: var: something - include: tasks/a.yaml
--- 
- name: where am I 
  debug: 
    msg: "I am task a" 
 
- include: b.yaml 
---
- name: who am I
debug:
msg: "I am task b"

Execution of the playbook is shown as follows:

We can clearly see the relative references to paths and how they are relative to the file referencing them. When using roles, there are some additional relative path assumptions; however, we'll cover that in detail in a later chapter.