ansible / proposals

Repository for sharing and tracking progress on enhancement proposals for Ansible.
Creative Commons Zero v1.0 Universal
92 stars 19 forks source link

allow tasks_from for role #184

Closed tpo closed 3 years ago

tpo commented 3 years ago

Proposal: allow tasks_from for role

Author: Tomáš Pospíšek <@tpo> IRC: tpo2

Date: 2020-11-02

Motivation

Unify abstractions (role: and include_role:). Make accessing tasks in a role more elegant.

Problem

What problems exist that this proposal will solve?

In the IRC channel various core devs have suggested to me that reusing tasks between roles, from various playlists and from various collections is:

- include_role:
    name: the_role
    tasks_from: some_task_list(.yml)
  vars:
    foo: baz
    bar: boz

This is not very elegant. The following seems to be exactly equivalent to me, but somewhat unexpectedly (design goal: minimize surprises, maximize intuitive use) that doesn't work, so I propose it should:

- role: the_role
  tasks_from: some_task_list(.yml)
  foo: baz
  bar: boz

Solution proposal

See above

Dependencies (optional)

None I am aware of. My proposal has some affinity to the collections idea. So maybe the collections implementation solves something related or maybe this proposal could be useful for the collections idea. I have not looked at the current collections implementation.

Testing (optional)

In case this proposal would be welcommed, there of course should be a test for this.

Documentation (optional)

Again, yes, see "Testing" above.

Anything else?

No, nothing atm.

bcoca commented 3 years ago

include_role has dynamic elements so it is not a good match for roles:, import_role is more closely aligned.

There are many reasons we didn't add the functionality to roles: the main one is that it conflates keywords and variables in it's role definitions which already creates issues (try a variable named name) so we didn't want to be adding to the problem.

Also, the equivalent could be done this way:

tasks:
   - import_role: 
         name: therole
         tasks_from: some_task_list(.yml)
     vars:
         foo: baz
         bar: boz

So I doubt that there is a compelling use case for this expansion. What you find 'elegant' in pulling foo and bar into the role definition and conflating them with keywords, I find problematic.

bcoca commented 3 years ago

closing as there does not seem to be much interest in debating or adding this feature