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/9a2c0d05-cc9f-4a0e-9749-e701b7f43c44n%40googlegroups.com.