Store playbook name as a 'global' variable across plays?

399 views
Skip to first unread message

burn...@umn.edu

unread,
Nov 8, 2016, 5:59:31 PM11/8/16
to Ansible Project
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>_<timestamp>.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!

Dick Davies

unread,
Nov 9, 2016, 7:25:43 PM11/9/16
to ansible list
you could set it as a group_var in your inventory.

Do you mind me asking what's going on with your roles there (I don't
understand what the target var is for)?
If you have 2 different roles that you want to apply to groups,
couldn't you just have multiple plays?

...
...
- hosts: Lower_Envs
roles:
- role_mhe_config_lower

- hosts: Upper_Envs
roles:
- role_mhe_config_upper
...
...
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/01de0105-bc9d-4efc-a4da-4f62ebc87ee5%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

burn...@umn.edu

unread,
Nov 28, 2016, 6:23:33 PM11/28/16
to Ansible Project, di...@hellooperator.net
Hello - Apologies for the late reply. I failed to see the update before.

Thanks for the suggestion. I ended up defining this as a fact early on in my playbook.

As for your question on roles, I do agree with you. I already redesigned the role setup to make more sense. Thanks!
Reply all
Reply to author
Forward
0 new messages