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

**URL:** <https://forum.ansible.com/t/get-could-not-find-the-requested-service-when-trying-to-restart-httpd-but-it-is-installed/29035>\
**Category:** Ansible Project\
**Created:** [November 15, 2018, 10:44am UTC](https://forum.ansible.com/t/get-could-not-find-the-requested-service-when-trying-to-restart-httpd-but-it-is-installed/29035 "2018-11-15T10:44:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sean\_Hederman](https://avatars.discourse-cdn.com/v4/letter/s/3ec8ea/32.png) [@Sean\_Hederman](https://forum.ansible.com/u/Sean_Hederman)\
**Post date:** [November 15, 2018, 10:44am UTC](https://forum.ansible.com/t/get-could-not-find-the-requested-service-when-trying-to-restart-httpd-but-it-is-installed/29035/1 "2018-11-15T10:44:29Z")

</div>

- 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

---

<div class="post-metadata">

**Author:** ![Karl\_Auer](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@Karl\_Auer](https://forum.ansible.com/u/Karl_Auer)\
**Post date:** [November 15, 2018, 10:47am UTC](https://forum.ansible.com/t/get-could-not-find-the-requested-service-when-trying-to-restart-httpd-but-it-is-installed/29035/2 "2018-11-15T10:47:23Z")

</div>

This is almost certainly to do with the PID file.

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

Regards, K.

---

<div class="post-metadata">

**Author:** ![Sean\_Hederman](https://avatars.discourse-cdn.com/v4/letter/s/3ec8ea/32.png) [@Sean\_Hederman](https://forum.ansible.com/u/Sean_Hederman)\
**Post date:** [November 15, 2018, 1:16pm UTC](https://forum.ansible.com/t/get-could-not-find-the-requested-service-when-trying-to-restart-httpd-but-it-is-installed/29035/3 "2018-11-15T13:16:53Z")

</div>

The pid file is at

/var/run/httpd/httpd.pid

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

---

<div class="post-metadata">

**Author:** ![Dick\_Davies](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Dick\_Davies](https://forum.ansible.com/u/Dick_Davies)\
**Post date:** [November 16, 2018, 8:51am UTC](https://forum.ansible.com/t/get-could-not-find-the-requested-service-when-trying-to-restart-httpd-but-it-is-installed/29035/4 "2018-11-16T08:51:56Z")

</div>

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.
