Ansible-playbook service module does not suppport -e

Hello, 

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’

tasks:

  • name: Service ‘{{ service }}’ Restarting
    service:
    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,

This post was moved to a different board that fits your topic of discussion a bit better. This means you’ll get better engagement on your post, and it keeps our Community organized so users can more easily find information.

As you’ll notice, your Topic is now in the Project Development Help and Advice board. No action is needed on your part; you can continue the conversation as normal here.

Let me know if you have any other questions or if I can help with anything else.

Cheers!

ru kidding me? moved it so no one comments?

im also looking at this problem.

@holyender No, the conversation was not moved to limit it’s engagement, but rather because it is now in the designated topic on this forum - where it should be.

@ahmer84 and @holyender The fact that this post receives too little attention might be due to the fact that this is a more general forum. Everyone here would love to help out, but there is a chance that there just aren’t so many people around with deep knowledge about Ansible. If you need help with specifically Ansible, you might want to check out https://docs.ansible.com/ansible/latest/community/index.html#ansible-community-guide for additional sources of help.