Hello -
Is there a way to store playbook name as a ‘global’ variable across plays?? I’ve seen potential options via callbacks or group_vars:all but still struggling with the solve.
At the end of the day I want to log certain actions for a specific playbook (which contains several different plays). I have the default ansible logging setup, but it lacks readability and is otherwise difficult to consume. The playbook contains all sorts of prep, validations, and deployments but I only want to log the aggregate changes in our operational environments such that it can be easily digested. I envision a log file with <playbook_name>_.log with all the stuff I want to plop into it.
I could approach the callback; however I’m still new to ansible so hesitating before hopping into more ‘advanced’ features.
I don’t believe group_vars:all will work because the playbook name isn’t tied to the host groups.
Passing in the name as an extra-var on the command line reduces usability.
So far the best that I could do is manually define the var in the playbook when calling the role. However, it then only exists for that specific play.
`
- name: MHE Dematic Conveyer Configuration
hosts: “{{ target }}”
vars:
playbook_name: “pb_MA_WMOS_Post_Install_Config”
roles: - { role: role_mhe_config_lower, when: “‘Lower_Envs’ in group_names”, tags: [“Lower_Envs”] }
- { role: role_mhe_config_upper, when: “‘Upper_Envs’ in group_names”, tags: [“Upper_Envs”] }
`
Or, perhaps I’m just looking at this all wrong and restricting too much down one path. Thoughts?
Thanks!