roles and compound vars

113 views
Skip to first unread message

Adam Bozanich

unread,
Mar 22, 2014, 2:21:27 AM3/22/14
to ansible...@googlegroups.com
I'm having trouble figuring out how to pass non-string parameters to roles.

I've tried a few different methods, with the most recent using "vars_files" in the play:

This only seems to import the variables into the play; the variables defined in the vars file aren't visible in the roles.

Ideally I'd be able to parametrize roles with a reference to a compound variable.  I've tried this, but the roles only receive a stringified version of the hash that I pass in.

The only other options I can see at this point are either passing in a large amount of parameters every time or creating an extra role for every "abstract" role that I want to invoke.  Neither of these sound very appealing and so I'm hoping that there's something that I'm missing.  Ideas?

Thanks,
-Adam

Michael DeHaan

unread,
Mar 24, 2014, 10:49:04 AM3/24/14
to ansible...@googlegroups.com


If you really mean passing parameters to roles:

roles:
# short form
- webserver
# long form
- { role: dbserver, port: 4200, foo: [ 1,2,3] }

vars_files of course works too, I'd need to see your vars_file to see what you might have wrong in it.


--
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/baee45cc-3069-473f-9c3d-6c993147aabb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Adam Bozanich

unread,
Mar 31, 2014, 9:50:25 PM3/31/14
to ansible...@googlegroups.com
Thanks, Michael.

I had wanted to be able to pass an entire dict by name into a role, but apparently that isn't possible.

I've gotten things to work with vars_files, I'll try restructuring things to work with this.

Cheers,
-Adam

C. Morgan Hamill

unread,
Apr 1, 2014, 9:48:50 AM4/1/14
to ansible-project
Excerpts from Adam Bozanich's message of 2014-03-31 21:50:25 -0400:
> I had wanted to be able to pass an entire dict by name into a role, but
> apparently that isn't possible.

I *believe* recent versions of Ansible will allow:

- { role: my role, myrolevars: "{{ some_dict_defined_elsewhere }}"

--
Morgan Hamill
Reply all
Reply to author
Forward
0 new messages