Change Ansible module based on variable or group
Elaborating on @030's answer, here's how you can use variables for modules:


You need to group the target hosts in groups, for the example I'm using server1.example.com as member of hosts1 group and server2.example.com as member of hosts2 group.
You create group variables:


group_vars/hosts1
group_vars/hosts2



Both files contain a variable named module with different value, in the test I use stat.


Your playbook will look like this:


test.yml

---
 - hosts: all        
   user: me        
   tasks:
     - name: test module variables
       action: "{{ module }} path=/home/me/myfile"


The result of the play:

[me@myserver]$ ansible-playbook test.yml -i test

PLAY [all] ********************************************************************************

TASK [Gathering Facts] ********************************************************************
ok: [server1.example.com]
ok: [server2.example.com]

TASK [test module variables] **************************************************************
ok: [server1.example.com]
ok: [server2.example.com]

PLAY RECAP ********************************************************************************
server1.example.com        : ok=2    changed=0    unreachable=0    failed=0
server2.example.com        : ok=2    changed=0    unreachable=0    failed=0