Problem scenario
You want to refer to files in a subdirectory of the parent directory that houses your Ansible playbook. You have Git repositories with .yaml files and subdirectories. You want the Git repo to be transferred to a variety of different servers. The absolute path to the directory where the files are will vary. How do you have a variable or relative path reference in the playbook so as long as the directory structure is in place, your playbook will run correctly?
Solution
- This assumes you have a directory called "files" in the directory with your Ansible playbook (e.g., called good.yaml).
- In your playbook (e.g., good.yaml) use this notation:
../files/foo.bar
Here is an example:
- copy:
src: ../files/foo.bar
dest: /tmp/excellent.file
mode: 0777