variables defined in group_vars cannot be used as arguments when calling roles in a playbook.

31 views
Skip to first unread message

Rémy Saissy

unread,
Apr 15, 2014, 6:07:13 PM4/15/14
to ansible...@googlegroups.com
Hi,
I want ot call the same role several time with different parameters in a playbook.
the variables I use are a dictionnary defined in group_vars.
I cannot use these variables defined in a group_vars file when listing roles in a playbook.
Is it a normal behaviour? How should I do in order to achieve it?
Thanks,
Regards.

group_vars/all
---
web_project:
  user: 'existinguser'
  repo: g...@gitrepo.com:examplecom.git
  root: /var/www/virtualhosts/examplecom/

playbook.yml
---
# file: queueservers.yml
- name: Configure all MessageQueue servers
  hosts: queueservers
  sudo: yes
  roles:
    - { role: django, test: fakeuser', project: web_project }
 

roles/django/tasks/main.yml:
---
- name: test
  shell: 'echo foobar'
  sudo_user: "{{project.user}}"

--> It tries to execute the shell command as {{project.user}}'s user (in spite of 'existinguser').

and when I try with:

roles/django/tasks/main.yml:
---
- name: test
  shell: 'echo foobar'
  sudo_user: "{{test}}"

--> It tries to execute the shell command as 'fakeuser''s user, as expected.

The expected behaviour also happens when I use the following:

roles/django/tasks/main.yml:
---
- name: test
  shell: 'echo foobar'
  sudo_user: "{{web_project.user}}"



Rémy Saissy

unread,
May 2, 2014, 1:48:01 PM5/2/14
to ansible...@googlegroups.com
I have eventually found out what was wrong.
The double {{ }} and the double quote were missing in the playbook.yml, I didn't notice at first.



playbook.yml
---
# file: queueservers.yml
- name: Configure all MessageQueue servers
  hosts: queueservers
  sudo: yes
  roles:
    - { role: django, test: fakeuser', project: "{{web_project}}" }
 

Reply all
Reply to author
Forward
0 new messages