Vars output differences during ansible run when vars located in /defaults or /vars

29 views
Skip to first unread message

Walter Dolce

unread,
Feb 10, 2015, 7:18:21 PM2/10/15
to ansible...@googlegroups.com
Hi,

I've fairly new to Ansible and I've been trying things out with it.
I'm trying to write a simple playbook. As I'd like to have the ability to [let others] decide what to put in some vars and by following the docs on vars override rules I came up with something like the following:

roles/
   php-composer/
      defaults/main.xml
      tasks/main.xml

Where defaults/main.xml contains:

---
composer_destination: ./

And one of the tasks in tasks/main.xml contains:

---
- name: install composer to "{{ composer_destination }}" 
  command: chdir={{ composer_destination }} php installer 
  when: is_composer_installer_downloaded and is_composer_installer_downloaded|success

When I run the above, the output is:

TASK: [php-composer | install composer to "{{ composer_destination }}"] *******

But if I change/move the main.xml from defaults/ to vars/ I get the variable "expanded", like so:

TASK: [php-composer | install composer to "/the/directory/specified/in/vars_mainxml/"] *******

Is this expected?
If so, how can I always get a variable "expanded" in the name definition of a task?

I ask as I'm looking forward to write a reusable and configurable playbook but I would also like to always have the variable meant to give the destination directory outputted when performing a run like in the latter output above.

Thank you in advance,
Walter

Matt Martz

unread,
Feb 10, 2015, 9:29:24 PM2/10/15
to ansible...@googlegroups.com
Just so that we are clear. Are your files really named with a .xml extension? It was it just a typo and you meant .yml?

.yml is the appropriate file extension.

In general it is not straightforward to get var expansion in the name of a task, mainly due to scope.  I would however expect defaults and cars to be in the same scope, but without the code in front of me I can't say. Although in general is recommend staying away from cars in the task names.
--
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/60ed7e76-9978-4abf-b8a6-924889842b5a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Matt Martz
@sivel
sivel.net

Walter Dolce

unread,
Feb 11, 2015, 3:11:11 AM2/11/15
to ansible...@googlegroups.com

Argh! Sorry that was a typo.
They have .yml extension.

> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAD8N0v9sd%3DAfv_UdiAkrrr0E9md7GjKif-ikoJ7dMm1h_%3DpVOg%40mail.gmail.com.

Reply all
Reply to author
Forward
0 new messages