role name as variable

59 views
Skip to first unread message

jepper

unread,
Jul 25, 2014, 7:13:42 AM7/25/14
to ansible...@googlegroups.com
I'm sure this is dead simple, but googling seems hard since most posts contain the words "role" and "variable"!

I have versioned playbooks. I would like to stick a file somewhere on the target system that explains what role was used, a time stamp, and a version. I use maven as it happens. I thought I could something like this:

roles/install_iod_base/tasks/pom.yml
- name: copy the pom for this trunk/branch/tag
  copy: src=../../../../pom.xml dest=~/pom.xml-{{ ansible_date_time.date }}-{{ ansible_date_time.time }} mode=0644

I would like to include this snippet in all my roles, and therefore it would be useful to have something like

  copy: src=../../../../pom.xml dest=~/pom.xml-{{ ansible_role }}-{{ ansible_date_time.date }}-{{ ansible_date_time.time }} mode=0644

How can I enumerate the current roles name?

Michael DeHaan

unread,
Jul 25, 2014, 3:17:39 PM7/25/14
to ansible...@googlegroups.com
Generally speaking, a role shouldn't change behavior based on it's name, and this would become confusing if role dependencies were used (should the dependent role set thename, etc)

So basically you can't do this, but you could do a

- set_fact: role_name="xxx" if you wanted or something like that.








--
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/8865c77e-9e5f-4695-b643-cb1a17281d79%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages