Hello,
I have a question about required_if:
From the documentation (Ansible module architecture — Ansible Community Documentation):
required_if:
Must be a sequence of sequences. Every inner sequence describes one conditional dependency. Every sequence must have three or four values. The first two values are the option’s name and the option’s value which describes the condition. The further elements of the sequence are only needed if the option of that name has precisely this value.
If you want that all options in a list of option names are specified if the condition is met, use one of the following forms:
('option_name', option_value, ('option_a', 'option_b', ...)),
('option_name', option_value, ('option_a', 'option_b', ...), False),
So I made a spec with the following (partial) content:
update=dict(
type="dict",
required=True,
options=dict(
accountname=dict(type="str", required=False),
passwordpolicy=dict(type="str", required=False),
reset_passwordpolicy=dict(type="bool", required=False),
totp_secret=dict(type="str", required=False, no_log=True),
reset_totp=dict(type="bool", required=False),
disable_passwordreset=dict(type="bool", required=False),
notes=dict(type="list", required=False, elements="str"),
append_notes=dict(type="bool", required=False, default=False),
),
mutually_exclusive=[
("passwordpolicy", "resetpasswordpolicy"),
("totp_secret", "reset_totp"),
],
required_if=[("append_notes", True, ("notes"))],
)
However, this results in: append_notes is True but all of the following are missing: n, o, t, e, s found in update
.
When I change the required_if to required_if=[("append_notes", True, ["notes"])]
(so with []
around the 3rd parameter instead of ()
) everything works.
Is this a documentation error? An error on my side?
Python version used: 3.12.11
Ansible version used: 2.18.9