Get "Could not find the requested service" when trying to restart httpd; but it is installed

  • name: Restart Apache
    service:
    name: “{{ services }}”
    state: restarted
    enabled: yes
    become: true
    vars:
    services:
  • httpd

Have tried variants with different states, enabled, become. All fail with exact same error:
amzn-build: TASK [web_server : Restart Apache] ********************************************* amzn-build: fatal: [127.0.0.1]: FAILED! => {“changed”: false, “msg”: “Could not find the requested service [‘httpd’]: host”}

Logging onto the instance and running:

sudo service httpd restart

Stopping httpd: [FAILED]

Starting httpd: [ OK ]

Vanilla Amazon 2018.03 image with ansible installed via pip

I cannot see why ansible would report that httpd does not exist when it patently does

This is almost certainly to do with the PID file.

Check that it is where the stop script expects it to be.

Regards, K.

The pid file is at

/var/run/httpd/httpd.pid

How would I check where the stop script expects it to be?

Could not find the requested service ['httpd']: host"}

looks to me like your issue is in the playbook., You're passing an
array ( 'services' ) in as the service name, ansible is treating that
as a length 1 array
rather than just a string. Replace the "{{ services }}" with just :
httpd and I bet it works.