set module_defaults globally?

37 views
Skip to first unread message

Dick Visser

unread,
May 28, 2024, 8:06:29 AMMay 28
to ansible...@googlegroups.com
Hii


The highest level at which this can be set is play level.
But I have many plays, so I'd have to edit all those plays and explicitly define them.
I can use a variable for it (I think) but still it's a lot of extra code.

Is there a way to set this globally, in some (single) configuration/file?

Thx

Dick

Brian Coca

unread,
May 28, 2024, 1:51:15 PMMay 28
to ansible...@googlegroups.com
At that point copy the module into a custom one and set the defaults you want.

--
----------
Brian Coca (he/him/yo)

Felix Fontein

unread,
May 29, 2024, 1:43:06 AMMay 29
to ansible...@googlegroups.com
Hi Brian and Dick,

> At that point copy the module into a custom one and set the defaults
> you want.

that doesn't sound very sustainable, especially if this is the case for
multiple modules in multiple collections.

It might be helpful to allow module defaults to be included instead of
having to re-specify them in every play (include_module_defaults:
my-defaults.yaml).

You'll still have to add that include to all your plays then, but at
least you only have to do it once (and even can use a linting rule to
make sure that all your plays include that default) and have a single
place where to fill these defaults in.

Cheers,
Felix

Vladimir Botka

unread,
May 29, 2024, 9:44:50 AMMay 29
to ansible...@googlegroups.com
On Wed, 29 May 2024 07:42:37 +0200
"'Felix Fontein' via Ansible Project"
<ansible...@googlegroups.com> wrote:

Hi all,

> > At that point copy the module into a custom one and set
> > the defaults you want.
>
> ... allow module defaults to be included instead of
> having to re-specify them in every play
> (include_module_defaults: my-defaults.yaml).

FWIW, a substitution would solve many use-cases

```yaml
- hosts: all
module_defaults: "{{ mdefaults }}"
...
```

Unfortunately, it fails:

ERROR! The field 'module_defaults' is supposed to be a
dictionary or list of dictionaries, the keys of which must
be static action, module, or group names. Only the values
may contain templates. For example: {'ping': "{{
ping_defaults }}"}

--
Vladimir Botka

Vladimir Botka

unread,
May 29, 2024, 9:59:43 AMMay 29
to ansible...@googlegroups.com
On Tue, 28 May 2024 14:05:51 +0200
Dick Visser <dnmv...@gmail.com> wrote:

> I can use a variable for it (I think) ...

Top level keys must be static. Quoting from ansible-core
2.12 Release notes:
https://github.com/ansible/ansible/blob/stable-2.12/changelogs/CHANGELOG-v2.12.rst#breaking-changes--porting-guide

Breaking Changes / Porting Guide:

* Action, module, and group names in module_defaults must
be static values. Their values can still be templates.

--
Vladimir Botka
Reply all
Reply to author
Forward
0 new messages