ansible.builtin.service hangs

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

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

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

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

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

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 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”’

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