Pass complex variables into roles

30 views
Skip to first unread message

Eric Bruno

unread,
Jul 11, 2016, 10:18:28 AM7/11/16
to Ansible Project
Hi folks,

I'm facing an issue with roles call in plays when passing complex var. I want to find a way to pass variable by reference like so:

#group_vars/python-app/fooapi.yml

fooapi
:
  uno
: 1
  dos
: 2


#group_vars/python-app/barapi.yml

fooapi
:
  uno
: 1000
  dos
: 2000

#play.yml

- hosts: python-app
  roles
:
   
- { role: python, app: fooapi}
    - { role: python, app: barapi}

#roles/python/tasks/main.yml

- debug: var=app

This is maybe a bad practice but if we found a solution, this is a very usefull and nice way to do what I want to do.

Thank you for your help :)

Eric Bruno

unread,
Jul 18, 2016, 5:14:55 AM7/18/16
to Ansible Project
Hi folks,

Maybe there is no solution for that exactly. I want to make a role that is completly free from looping over a list of complex map like so:

# group_vars/python-app/apps.yml
-python_apps:
 
- name: foo
    uno
: 1
    dos
: 2
   
[...]
 
- name: bar
    uno
: 1000
    dos
: 2000
   
[...]

# roles/python-apps/tasks/main.yml
- include: install.yml
  with_items
: "{{python_apps}}"
  tags
:
   
- python-apps
   
- install

# roles/python-apps/tasks/install.yml
- debug: var={{item.name}}

The role itself is maintenable, but the group_vars file containing all complex data structures will become huge and hard to maintain. What do you do in this case?

Thanks !
Kindly
Reply all
Reply to author
Forward
0 new messages