Ansible-playbook service module does not suppport -e


I want to make generic playbook to start multiple services could be any service from any server. 
the server works fine but services module only restarts one server from the list.

 ansible-playbook  -e servername=hostb,hostc  -e service=autofs,sshd testautofs2.yml

[ansible@ansible test]$ cat testautofs2.yml

##This PLaybook Restarts services on rhel 6 - 7 Machines

  • hosts: ‘{{ servername }}’
    become: true
    name: Restart Service

when: ansible_system == ‘Linux’


  • name: Service ‘{{ service }}’ Restarting
    name: “{{ service }}”
    state: restarted
    enabled: yes
    when: ansible_os_family == “RedHat”

[ansible@ansible test]$ ansible-playbook -e servername=hostb,hostc -e service=autofs,sshd testautofs2.yml

PLAY [Restart Service] *************************************************************************************************************************************************************************************************

TASK [Gathering Facts] *************************************************************************************************************************************************************************************************
ok: [hostb]
ok: [hostc]

TASK [Service ‘autofs,sshd’ Restarting] ********************************************************************************************************************************************************************************
fatal: [hostb]: FAILED! => {“changed”: false, “msg”: “Could not find the requested service autofs,sshd: host”}
fatal: [hostc]: FAILED! => {“changed”: false, “msg”: “Could not find the requested service autofs,sshd: host”}
to retry, use: --limit @/home/ansible/test/testautofs2.retry

PLAY RECAP *************************************************************************************************************************************************************************************************************
hostb : ok=1 changed=0 unreachable=0 failed=1
hostc : ok=1 changed=0 unreachable=0 failed=1

Hi @ahmer84,

Thanks for being a part of the GitHub Community Forum!

This Topic has already been opened and is being discussed in another thread already here:

In an effort to keep the Community Forum organized and make it easier for other users to find information, we ask that users continue the conversation in existing threads, instead of opening new ones about the same topic. For this reason, I’ll be closing this Topic, and you can continue the conversation in the original thread, if you’d like. It’s more likely you’ll get engagement and answers to your own questions this way, too.

Thank you again for being here!