ansible.builtin.service hangs

73 views
Skip to first unread message

Axel Rau

unread,
Oct 13, 2022, 5:19:26 AM10/13/22
to Ansible Project
The last task below does not complete.
- - -

- name: Enable/Disable servers
ansible.builtin.service:
name: '{{ ena_item }}'
enabled: '{{ i_am_master }}'
loop_control:
loop_var: ena_item
loop:
- mailman
- uwsgi
- nginx

- name: Start uwsgi if i_am_master
ansible.builtin.service:
name: uwsgi
state: started
when: i_am_master

- name: Stop servers if not if i_am_master
ansible.builtin.service:
name: '{{ ena_item }}'
state: stopped
loop_control:
loop_var: ena_item
loop:
- mailman
- uwsgi
- nginx
when: 'not i_am_master'

- - -

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

OS is FreeBSD 13.1

Axel
---
PGP-Key: CDE74120 ☀ computing @ chaos claudius

Todd Lewis

unread,
Oct 13, 2022, 6:37:05 AM10/13/22
to Ansible Project
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


Axel Rau

unread,
Oct 13, 2022, 1:24:30 PM10/13/22
to Ansible Project, Todd Lewis
Applying your patch does not solve my problem. It still hangs. )-(


Am 13.10.2022 um 12:37 schrieb Todd Lewis <uto...@gmail.com>:

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.

Matt Martz

unread,
Oct 13, 2022, 1:30:22 PM10/13/22
to ansible...@googlegroups.com, Todd Lewis
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:


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.

--
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 ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/DEE8795F-9941-4CDB-B285-B3D23C55C92B%40Chaos1.DE.


--
Matt Martz
@sivel
sivel.net

Brian Coca

unread,
Oct 13, 2022, 1:30:29 PM10/13/22
to ansible...@googlegroups.com, Todd Lewis
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


--
----------
Brian Coca

flowerysong

unread,
Oct 13, 2022, 1:38:36 PM10/13/22
to Ansible Project
On Thursday, October 13, 2022 at 6:37:05 AM UTC-4 uto...@gmail.com wrote:
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

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"'

Axel Rau

unread,
Oct 15, 2022, 3:28:47 PM10/15/22
to Ansible Project, Todd Lewis
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

Reply all
Reply to author
Forward
0 new messages