# ansible.builtin.service hangs

**URL:** <https://forum.ansible.com/t/ansible-builtin-service-hangs/37220>\
**Category:** Ansible Project\
**Created:** [October 13, 2022, 9:19am UTC](https://forum.ansible.com/t/ansible-builtin-service-hangs/37220 "2022-10-13T09:19:11Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Axel\_Rau](https://avatars.discourse-cdn.com/v4/letter/a/ad7895/32.png) [@Axel\_Rau](https://forum.ansible.com/u/Axel_Rau)\
**Post date:** [October 13, 2022, 9:19am UTC](https://forum.ansible.com/t/ansible-builtin-service-hangs/37220/1 "2022-10-13T09:19:11Z")

</div>

The last task below does not complete.  
- - -

- name: Enable/Disable servers  
&nbsp;&nbsp;ansible.builtin.service:  
&nbsp;&nbsp;&nbsp;&nbsp;name: '{{ ena\_item }}'  
&nbsp;&nbsp;&nbsp;&nbsp;enabled: '{{ i\_am\_master }}'  
&nbsp;&nbsp;loop\_control:  
&nbsp;&nbsp;&nbsp;&nbsp;loop\_var: ena\_item  
&nbsp;&nbsp;loop:  
&nbsp;&nbsp;&nbsp;&nbsp;- mailman  
&nbsp;&nbsp;&nbsp;&nbsp;- uwsgi  
&nbsp;&nbsp;&nbsp;&nbsp;- nginx

- name: Start uwsgi if i\_am\_master  
&nbsp;&nbsp;ansible.builtin.service:  
&nbsp;&nbsp;&nbsp;&nbsp;name: uwsgi  
&nbsp;&nbsp;&nbsp;&nbsp;state: started  
&nbsp;&nbsp;when: i\_am\_master

- name: Stop servers if not if i\_am\_master  
&nbsp;&nbsp;ansible.builtin.service:  
&nbsp;&nbsp;&nbsp;&nbsp;name: '{{ ena\_item }}'  
&nbsp;&nbsp;&nbsp;&nbsp;state: stopped  
&nbsp;&nbsp;loop\_control:  
&nbsp;&nbsp;&nbsp;&nbsp;loop\_var: ena\_item  
&nbsp;&nbsp;loop:  
&nbsp;&nbsp;&nbsp;&nbsp;- mailman  
&nbsp;&nbsp;&nbsp;&nbsp;- uwsgi  
&nbsp;&nbsp;&nbsp;&nbsp;- nginx  
&nbsp;&nbsp;when: 'not i\_am\_master'

- - -

How can I debug this?  
What may be the reason?

OS is FreeBSD 13.1

Axel

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [October 13, 2022, 10:37am UTC](https://forum.ansible.com/t/ansible-builtin-service-hangs/37220/2 "2022-10-13T10:37:05Z")

</div>

Your last “when:” is wrong.

when: ‘not i\_am\_master’

A quoted when condition that contains no jinja mustaches is just a string, which is always true. You want

when: not i\_am\_master

---

<div class="post-metadata">

**Author:** ![Axel\_Rau](https://avatars.discourse-cdn.com/v4/letter/a/ad7895/32.png) [@Axel\_Rau](https://forum.ansible.com/u/Axel_Rau)\
**Post date:** [October 13, 2022, 5:24pm UTC](https://forum.ansible.com/t/ansible-builtin-service-hangs/37220/3 "2022-10-13T17:24:14Z")

</div>

Applying your patch does not solve my problem. It still hangs. )-(

> Your last “when:” is wrong.
> 
> when: ‘not i\_am\_master’
> 
> A quoted when condition that contains no jinja mustaches is just a string, which is always true. You want
> 
> when: not i\_am\_master

I’m missing a clear definition here: Where ends a simple expression and where start jinja ‚mustaches‘ ?  
Some examples:

when: x \> a or (y and z)  
when: " DEBUG is defined "  
when: “i.replication\_type == ‘p\_dynamic’”  
when: “(i\_am\_master is defined and i\_am\_master) or i.replication\_type == ‘l\_master’”  
when: “sdt.stat.exists and (i.replication\_type.startswith(‘l’) or i.replication\_type == ‘p\_master’)”

Any clear rule welcome.

Axel

---

<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:** [October 13, 2022, 5:28pm UTC](https://forum.ansible.com/t/ansible-builtin-service-hangs/37220/4 "2022-10-13T17:28:42Z")

</div>

the 'hanging' was irrespective of the bad conditional, that would only  
condition execution or not.

The reason it is hanging is probably due to the service itself, for  
that you need to examine the process on the host, likely culprit: the  
service is prompting for a response

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [October 13, 2022, 5:29pm UTC](https://forum.ansible.com/t/ansible-builtin-service-hangs/37220/5 "2022-10-13T17:29:27Z")

</div>

It is not super easy to diagnose a hanging module. I wrote up some instructions using gdb a few weeks back that may help in figuring out why the module is hanging:

[https://gist.github.com/sivel/5076af99d310dbda3188722f02cddeb4](https://gist.github.com/sivel/5076af99d310dbda3188722f02cddeb4)

Most often, when a process like this hangs, it is often due to the underlying command asking for some input, that the module is not designed to handle. Or the service is just taking a long time to stop for some reason.

---

<div class="post-metadata">

**Author:** ![flowerysong1](https://avatars.discourse-cdn.com/v4/letter/f/ecae2f/32.png) [@flowerysong1](https://forum.ansible.com/u/flowerysong1)\
**Post date:** [October 13, 2022, 5:38pm UTC](https://forum.ansible.com/t/ansible-builtin-service-hangs/37220/6 "2022-10-13T17:38:35Z")

</div>

You are incorrect. Unquoted scalars and quoted scalars are just different YAML representations of the same data; once it’s parsed these two are completely identical. You have to have two levels of quotes (the YAML quotes and a quoted string as the Jinja expression) in order for it to be treated as always true:

when: ‘“not i\_am”’

---

<div class="post-metadata">

**Author:** ![Axel\_Rau](https://avatars.discourse-cdn.com/v4/letter/a/ad7895/32.png) [@Axel\_Rau](https://forum.ansible.com/u/Axel_Rau)\
**Post date:** [October 15, 2022, 7:28pm UTC](https://forum.ansible.com/t/ansible-builtin-service-hangs/37220/7 "2022-10-15T19:28:29Z")

</div>

I did not succeed in setting this up in FreeBSD.  
I could build Python3.9 with debug symbols but gdb failed to load them.

I finally found the cause for my problem:  
The rc script of mailman contained a  
su -l  
Replacing this by  
su  
fixed it.

Thanks all who responded,  
Axel
