Vagrant: Relative paths in Ansible roles

The default path to the current working directory for any role is the role directory itself!

So if you reference a file inside of a role task: lets say the copy module for example, and the file is not in that role directory then you have to use parent path .. /.

Directory structure:

├── devenv/
│   └── ansible
│       └── roles
│           └── autossh
│               └── tasks
│                   └── main.yml
├─────── private/
│        └── myfile.txt
└────── Vagrantfile

In the case the cwd is autosh and the relative path to the file is: ../../../private/myfile.txt

You cannot use relative paths that are outside the Vagrantfile folder: when you do vagrant up it maps the directory to one in the VM and there it references the files.. so no files outside that directory will work if it doesn’t exist already in the VM.