Hello all.
Consider following sample project:
https://github.com/belonesox/ansible_dynamic_role_howto
With tree:
.
├── playbook.yml
├── run-playbook
└── somedir
└── dynamically_defined_dir
├── do.yml
├── roles
│ ├── role1
│ ├── role2
│ │ ├── defaults
│ │ │ └── main.yml
│ │ ├── tasks
│ │ │ └── main.yml
│ │ └── templates
│ │ └── sometemplate.j2
│ └── role3
├── run-nested-playbook
├── templates
└── vars
Here we have here:
- A working playbook “do.yml” in “dynamically_defined_dir” (can be run by “run-nested-playbook” shell script).
- A playbook “playbook.yml” that tried to use “nested” playbook “do.yml”, trying to redefine some of defaults of nested playbook.
- Playbook “playbook.yml” should be run (“run-playbook”) with some external parameters like this:
ansible-playbook -vvv -i ‘localhost,’ -c local playbook.yml --extra-vars “external_extra_var=somedir”
Expected (wanted) result for “run-playbook”
- Get contents of sometemplate.j2 with replacing default variables to some variables/parameters from “playbook.yml”
- “Playbook.yml” should be without hardcoding paths to nested playbook (should be calculated somehow from “–extra-vars”). Better by “set_fact” some variable, and reuse it.