3 ms·
You can pass parameters to roles: http://docs.ansible.com/playbooks_roles.html#role-dependencies http://docs.ansible.com/playbooks_roles.html#role-dependenci...
by BadassFractal 12y ago
You can pass parameters to roles: http://docs.ansible.com/playbooks_roles.html#role-dependencies http://docs.ansible.com/playbooks_roles.html#role-dependenci...
- smegel 12y agoI was somewhat aware of dependencies, but they don't really do what I want. I want to be able to execute a role (or task within a role), much like calling a function, that will be executed at the point it is called (dependencies are all executed before the role executes. I may also want to call the "function" multiple times within a role, with different parameters, to, for example, deploy a template several times to different named files. And yes, dependencies can execute roles multiple times, but this is business logic that belongs in the main role file, not in a meta file. And from what I can see, dependencies can only call a role as a whole, not a part (or task) therein. Basically what I have with "include" does exactly what I want, but it would be nice if it was a bit more explicit that I was calling a role component, something like: # Role X - name: deploy conf files callrole: common::deployconf args: name={{ item.name }} val={{ item.val }} with_items: - { name: 'conf1', val: 33 } - { name: 'conf2', val: 42 } Where callrole::conf corresponds to roles/common/tasks/deployconf.yml. This might allow for more powerful constructs than is available by simply using include.
- skywhopper 12y agoIIRC, they specifically removed this functionality a few versions ago. Their stated reasoning was never clear to me. Something about a lack of clarity regarding which variables passed through how. It might be possible to write a plugin of some sort that adds the functionality you want.