I want to remember current playbook folder name and pass it to another imported playbook. I set fact as "playbook_dir | basename" that returns proper folder name: appfolder. I pass it as bpm_folder to the imported playbook it is visible as appfolder (debug returns: "msg": "appfolder") but it doesn't work.
Inside imported playbook I got: skipping vars_file '../{{ bpm_folder }}/deployment_settings.yml' due to an undefined variable.
But when I add vars to imported playbook ant set "bpm_folder: 'appfolder'" it does work, even if this is exactly the same folder name.
The point is that I want to get the appfolder automatically. How to fix it?
---
- name: pre deploy
hosts: myhosts
gather_facts: no
tasks:
- set_fact:
myfolder: "{{ playbook_dir | basename }}"
- name: start deploy
import_playbook: '../Common/deploy.yml'
vars:
bpm_folder: 'appfolder' <- it is working
bpm_folder: "{{ myfolder }}" <-- doent't work
ansible --version
ansible [core 2.11.6]
python version = 3.6.8 (default, Aug 13 2020, 07:46:32) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]
jinja version = 3.0.2
libyaml = True
Best regards!
According your description it seems to be related to the difference between include_... and import_....
Since the import is static and pre-processed at the time playbooks are parsed, the variable isn't initialized at that stage.
Might import_task: ../Common/deploy.yml work for you?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With