I don't see any benefit to the proposed feature. If you want to skip an
include based on a flag value, you can do that without adding complexity to
the engine.
- include_tasks: "{{ task_file }}.yml"
when: task_file | default('noop') != 'noop'
On Thursday, December 9, 2021 at 6:05:10 PM UTC-5 Omar wrote:
> This is potential feature idea.
>
> I'm developing a small collection and as an extension points I expose
> various variable that refer to 'task files'. For example, I have a role
> named prepare with a task file named `_yum.yml` and I have a variable
> `repositories_tasks` with a default value `_yum.yml`.
>
> Users can override the variable `repositories_tasks` and provide their own
> tasks file. Or they could disable it entirely by providing an empty tasks
> file(maybe with a debug task).
> `repositories_tasks: noop.yml`
>
> Another case is for 'hooks' to run tasks at various phases in a role's
> execution. For example a `pre_upgrade_hook` or a `pre_restart hook` and
> have them undefined or set to `None` or an empty string. Sample code:
> ```
> - include_tasks: "{{ pre_kubelet_upgrade_hook }}"
> when: pre_kubelet_upgrade_hook is defined and (not
> pre_kubelet_upgrade_hook is none) and (pre_kubelet_upgrade_hook | trim !=
> '')
> ```
>
> After seeing this pattern I thought that this could br a lot simpler(from
> a user perspective). Suppose we have a special value that when it appears
> as a value in `include_tasks` nothing happens. I will use `ansible_noop` as
> the special value. the following:
> - include_tasks: ansible_noop
> simply does nothing.
>
> When I user wants to disable a set tasks exposed through a variable, they
> can assign it to `ansible_noop`, and as a default value for all hook
> variables you can assign them to `ansible_noop`.
>
> Sample code for role author:
> `defaults/main.yml`
>
> pre_kubelet_upgrade_hook: ansible_noop
> update_kube_tasks: _update_kube.yml
> copy_config_tasks: _copy_config.yml
>
> Sample code for role clients:
> include_role:
> name: upgrade
> vars:
> pre_kubelet_upgrade_hook: cri_upgrade.yml # File supplied by user
> update_kube_tasks: update_kube.yml
> copy_config_tasks: ansible_noop
>
> What do you think?
>
>
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/72b9c4c9-e1e7-40c6-9637-e472de9abeacn%40googlegroups.com.