roles and compound vars

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:

https://github.com/boz/ansible-deploy/blob/multiplay/playbook.yml#L45

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


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.

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

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 }}"