There are many Ansible Network modules (for example: ios_user, asa_user, nxos_user) which share the same (or similar enough) interfaces. Currently, my playbook has to conditionally execute tasks based on the host's group or variables. This leads to a lot of duplicated code as the only real difference between the tasks is the module name.
Is there a way to select the module to be run based on group or variable values without adding extra tasks, roles, or playbooks?
For example, this is how the playbook currently looks:
- hosts: ios
tasks:
ios_user:
provider: "{{ cli }}"
...
- hosts: asa
tasks:
asa_user:
provider: "{{ cli }}"
...
- hosts: nxos
tasks:
nxos_user:
provider: "{{ cli }}"
...
I'd love to have something like this:
- hosts: all
tasks:
{{ module_name }}:
provider: "{{ cli }}"
...
I swear I saw some feature like this in passing, but I'm having a hard time finding it again. Along with version 2.5 making netconf_cli a first-class connection type, this would solve a large number of problems and inconveniences in our org.