# Ansible fails to start services

**URL:** <https://forum.ansible.com/t/ansible-fails-to-start-services/30429>\
**Category:** Ansible Project\
**Created:** [May 27, 2019, 3:13pm UTC](https://forum.ansible.com/t/ansible-fails-to-start-services/30429 "2019-05-27T15:13:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Borja\_Salamanca\_Domi](https://avatars.discourse-cdn.com/v4/letter/b/977dab/32.png) [@Borja\_Salamanca\_Domi](https://forum.ansible.com/u/Borja_Salamanca_Domi)\
**Post date:** [May 27, 2019, 3:13pm UTC](https://forum.ansible.com/t/ansible-fails-to-start-services/30429/1 "2019-05-27T15:13:17Z")

</div>

Hello Ansible Group, i recently had problems while i try to launch any services via Ansible playbook.

I sent via Ansible these services to etc/systemd/system/zookeeper.services and /etc/systemd/system/kafka.services

zookeeper.service:

_[Unit]_  
_Description=Apache Zookeeper server (Kafka)_  
_Documentation=[http://zookeeper.apache.org](http://zookeeper.apache.org)_  
_Requires=network.target remote-fs.target_  
_After=network.target remote-fs.target_

_[Service]_  
_User=borja_  
_ExecStart=/home/borja/inventory/Innovery/zookeeper/bin/zkServer.sh start /home/borja/inventory/Innovery/zookeeper/config/zookeeper.properties_  
_ExecStop=/home/borja/inventory/Innovery/zookeeper/bin/zkServer.sh stop_

_[Install]_  
_WantedBy=multi-user.target_

kafka.service:

_[Unit]_  
_Description=Apache Kafka server (broker)_  
_Documentation=[http://kafka.apache.org/documentation.html](http://kafka.apache.org/documentation.html)_  
_Requires=network.target remote-fs.target_  
_After=network.target remote-fs.target_

_[Service]_  
_User=borja_  
_ExecStart=/home/borja/inventory/Innovery/Kafka/bin/kafka-server-start.sh /home/borja/inventory/Innovery/Kafka/config/server.properties_  
_ExecStop=/home/borja/inventory/Innovery/Kafka/bin/kafka-server-stop.sh_

_[Install]_  
_WantedBy=multi-user.target_

The Kafka/Zookeeper installation procedure consists in decompress kafka .tar.gz file and zookeeper .tar.gz file.

Looks like it doesn’t work at all, the services never start via Ansible on the remote machine, but if i launch these services on the remote machine they work perfectly.  
It is making me crazy! Any help?

Thanks, Ansible Group.

---

<div class="post-metadata">

**Author:** ![Jonathan\_Lozada\_De\_L](https://avatars.discourse-cdn.com/v4/letter/j/eb8c5e/32.png) [@Jonathan\_Lozada\_De\_L](https://forum.ansible.com/u/Jonathan_Lozada_De_L)\
**Post date:** [May 27, 2019, 3:15pm UTC](https://forum.ansible.com/t/ansible-fails-to-start-services/30429/2 "2019-05-27T15:15:56Z")

</div>

how are you starting the services and what comes up qhen you it with -vvvv ? a lot of services after a file change lile this require a daemon-reload

Jonathan Lozada De La Matta on mobile

– You received this message because you are subscribed to the Google Groups “Ansible Project” group. To unsubscribe from this group and stop receiving emails from it, send an email to . To post to this group, send email to . To view this discussion on the web visit . For more options, visit .

---

<div class="post-metadata">

**Author:** ![Borja\_Salamanca\_Domi](https://avatars.discourse-cdn.com/v4/letter/b/977dab/32.png) [@Borja\_Salamanca\_Domi](https://forum.ansible.com/u/Borja_Salamanca_Domi)\
**Post date:** [May 28, 2019, 7:05am UTC](https://forum.ansible.com/t/ansible-fails-to-start-services/30429/3 "2019-05-28T07:05:43Z")

</div>

I tried sending an .sh file to the remote machine with the needed commands and launching it:

_#!/bin/bash_  
_nohup bin/zookeeper-server-start.sh config/zookeeper.properties &_  
_nohup bin/kafka-server-start.sh config/server.properties &_

If i launch this .sh on the remote machine manually, it works but it doesn’t work if i do it via Ansible playbook with this task:  
Anything that i try manually works perfectly.

_- name: starting service via .sh_  
_shell: /path/to/remoteserver/sh\_location/start\_service.sh_

I tried using command module instead. Doesn’t work either.

When the service is on the remote server, i tried to launch with these tasks, they give the same output error (Connection Timed Out):  
Before launching these tasks i have a daemon reload task, but doesn’t matter which task, the first one that references any service will give the same error.

So if i launch the daemon reload task first, it will fail. If i skip this reload, the next one will fail.

_- name: starting service via Systemd module_  
_systemd:_

_name: zookeeper.service_

_no\_block: yes_  
_state: started_

_daemon\_reload: yes_

_- name: starting services via service module_  
_service:_

_state: started_

_name: zookeeper.service_

_- name: starting service launching a raw command on the remote server_

_shell: ‘systemctl start zookeeper.service’_

All these tasks where tested with kafka.service too.  
(Kafka needs Zookeeper to be operative first)

Since i tried multiple times by different ways to get the same output error, i modified the timeout attribute inside ansible.cfg, increasing it from the default values.

This changes didn’t fix the problem.

I also tried to start the service via sh having this command in the .sh file: _systemctl start zookeeper.service_ but this doesn’t get the job done.

The -vvvv option give this output:

_fatal: [172.22.1.96]: FAILED! =\> {_  
_“changed”: true,_  
_“cmd”: “/home/borja/inventory/Innovery/Zookeeper/launchService.sh”,_  
_“delta”: “0:00:25.044432”,_  
_“end”: “2019-05-28 08:27:26.373093”,_  
_“invocation”: {_  
_“module\_args”: {_  
_“\_raw\_params”: “/home/borja/inventory/Innovery/Zookeeper/launchService.sh”,_  
_“\_uses\_shell”: true,_  
_“argv”: null,_  
_“chdir”: null,_  
_“creates”: null,_  
_“executable”: null,_  
_“removes”: null,_  
_“stdin”: null,_  
_“warn”: true_  
_}_  
_},_  
_“msg”: “non-zero return code”,_  
_“rc”: 1,_  
_“start”: “2019-05-28 08:27:01.328661”,_  
_“stderr”: “Failed to start zookeeper.service: Connection timed out\nSee system logs and ‘systemctl status zookeeper.service’ for details.”,_  
_“stderr\_lines”: [_  
_“Failed to start zookeeper.service: Connection timed out”,_  
_“See system logs and ‘systemctl status zookeeper.service’ for details.”_  
_],_  
_“stdout”: “”,_  
_“stdout\_lines”: []_  
_}_

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [May 29, 2019, 4:15am UTC](https://forum.ansible.com/t/ansible-fails-to-start-services/30429/4 "2019-05-29T04:15:08Z")

</div>

Usually if things work manually but not via ansible it’s because ansible has a different set of environment variables.

Could that be it?
