04.04.2020 Views

Mastering Ansible

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 1

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, scripts to execute, and so on, are all

relative to the directory where the file referencing them lives. Let's explore this with

an example playbook and directory listing to show where the things are.

• Directory structure:

.

├── a_vars_file.yaml

├── mastery-hosts

├── relative.yaml

└── tasks

├── a.yaml

└── b.yaml

• Contents of _vars_file.yaml:

---

something: "better than nothing"

• Contents of relative.yaml:

---

- 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

[ 15 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!