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

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

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

Thanks for your response Brian.

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

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.

–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)