use variable with a default in a role

32 views
Skip to first unread message

fabix

unread,
May 20, 2015, 8:41:01 AM5/20/15
to ansible...@googlegroups.com
I have this role (roles/dummy/tasks/main.yml) :

---
- debug: var=dum_name

and this playbook (test.yml) :

---
- hosts: localhost
  vars:
    name: "{{ foo_name | default('boom') }}"
  tasks:
  - debug: var=name
  roles:
  - { role: dummy, dum_name: "{{ name }}" }


If I define a variable "foo_name=bar" in the inventory file for localhost , I get this output :

TASK: [dummy | debug var=dum_name] ******************************************** 
ok: [localhost] => {
    "var": {
        "dum_name": "boom"
    }
}

TASK: [debug var=name] ******************************************************** 
ok: [localhost] => {
    "var": {
        "name": "bar"
    }
}

In the dummy task, I expected : "dum_name": "bar" .

In a real application, I need to use several times a same role with different parameters. A simple way to get the same thing is :

...
  roles:
  - { role: dummy, dum_name: "{{ foo_name | default('boom') }}" }

but the problem is the same : I get "boom" in the result instead of "bar" .

What is the solution/workaround ?

Regards,
Fabien

fabix

unread,
May 22, 2015, 4:02:54 AM5/22/15
to ansible...@googlegroups.com
Is it a bug or not ?
Reply all
Reply to author
Forward
0 new messages