# Apache config test and send signal to restart apache if syntax check is passed

**URL:** <https://forum.ansible.com/t/apache-config-test-and-send-signal-to-restart-apache-if-syntax-check-is-passed/29240>\
**Category:** Ansible Project\
**Created:** [December 11, 2018, 6:19pm UTC](https://forum.ansible.com/t/apache-config-test-and-send-signal-to-restart-apache-if-syntax-check-is-passed/29240 "2018-12-11T18:19:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Himanshu\_Maity](https://avatars.discourse-cdn.com/v4/letter/h/f0a364/32.png) [@Himanshu\_Maity](https://forum.ansible.com/u/Himanshu_Maity)\
**Post date:** [December 11, 2018, 6:19pm UTC](https://forum.ansible.com/t/apache-config-test-and-send-signal-to-restart-apache-if-syntax-check-is-passed/29240/1 "2018-12-11T18:19:00Z")

</div>

Hi,

I’m trying to run two commands in a single line, which will validate the syntax of apache configuration copied from template file and send a signal to reload the apache if it’s passed.

Right now, my configuration looks like as below where I only sending the signal to apache to reload after coping the config from template file and it’s working fine.

_command: ‘-consul={{ ansible\_host }}:2250 -template=“vhosts.ctmpl:vhosts.conf:/bin/docker/docker kill -s USR1 apache”’_

But I’m trying to add configtest with this command like,

command: ‘-consul={{ ansible\_host }}:2250 -template=“vhosts.ctmpl:vhosts.conf:/bin/docker/docker exec apache /usr/local/apache2/bin/apachectl configtest && **/bin/docker/docker kill -s USR1 apache** ”’

But, the last reload of the apache command is failing as I can’t send the signal to reload own process(apache) inside of staying in the container.

Can anyone please guide, you help is truly appreciated. Thanks in advance.

Best Regards

Himanshu Maity

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [December 11, 2018, 6:31pm UTC](https://forum.ansible.com/t/apache-config-test-and-send-signal-to-restart-apache-if-syntax-check-is-passed/29240/2 "2018-12-11T18:31:31Z")

</div>

First i would make this a script and use the 'script' module, but the  
issue you are probably hitting is that 'command' does not support  
'shellisms' like &&, so you need to use the shell module

---

<div class="post-metadata">

**Author:** ![Himanshu\_Maity](https://avatars.discourse-cdn.com/v4/letter/h/f0a364/32.png) [@Himanshu\_Maity](https://forum.ansible.com/u/Himanshu_Maity)\
**Post date:** [December 11, 2018, 6:45pm UTC](https://forum.ansible.com/t/apache-config-test-and-send-signal-to-restart-apache-if-syntax-check-is-passed/29240/3 "2018-12-11T18:45:16Z")

</div>

Thanks for your response Brian.

I think I’m using docker exec which support &&, please find the screenshot attached.

 ![Screen Shot 2018-12-11 at 12.37.23 PM.png](https://us1.discourse-cdn.com/ansible/original/2X/6/64f80ed6188ce53f4b70a1d79a21eaac66cfb564.png)

Like, if I run this command - docker exec -it apache bash -c “/usr/local/apache2/bin/httpd -t && echo a” ,then it execute properly.

But, once I’m trying to run this - docker exec -it apache bash -c “/usr/local/apache2/bin/httpd -t && /bin/kill -s USR1 apache” ,then 1st command is getting executed but 2nd command is giving error as I used ‘docker exec’ to get into the container and it can’t reload the apache staying inside of container.

Output:

[root@### ~]$ docker exec -it apache bash -c “/usr/local/apache2/bin/httpd -t && /bin/kill -s USR1 apache”

Syntax OK

kill: failed to parse argument: ‘apache’

FYIP, apache is a container running on the host.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [December 11, 2018, 6:55pm UTC](https://forum.ansible.com/t/apache-config-test-and-send-signal-to-restart-apache-if-syntax-check-is-passed/29240/4 "2018-12-11T18:55:19Z")

</div>

–For that you need to go to a docker mailing list/support forum.

I only responded to the first post as it seemed to show an incorrect usage of the Ansible comand module.

> **(attachments)**
>
> ![Screen Shot 2018-12-11 at 12.37.23 PM.png](https://us1.discourse-cdn.com/ansible/original/2X/6/64f80ed6188ce53f4b70a1d79a21eaac66cfb564.png)
