Not replacing invalid character(s) in group name warning

3,126 views
Skip to first unread message

Xinhuan Zheng

unread,
Dec 20, 2019, 4:08:02 PM12/20/19
to Ansible Project
Hello,

I'm using Ansible group_by for networking specific information configuration. I need to use group_by to collect data values from my group_var/subnet_<mysubnet> file.  My group_vars/subnet_192.168.101.0 matches group_by key. Here is my playbook:

  - name: Group system by subnet
    group_by:
      key: subnet_{{ansible_default_ipv4.network}}

While I run my playbook, I got this error:

TASK [os-networking : Group system by subnet] *************************************************************************************
task path: os-networking/tasks/main.yml:24
Not replacing invalid character(s) "set([u'.'])" in group name (subnet_192.168.101.0)
[DEPRECATION WARNING]: The TRANSFORM_INVALID_GROUP_CHARS settings is set to allow bad characters in group names by default, this
will change, but still be user configurable on deprecation. This feature will be removed in version 2.10. Deprecation warnings can
 be disabled by setting deprecation_warnings=False in ansible.cfg.
[WARNING]: Invalid characters were found in group names but not replaced, use -vvvv to see details

ok: [myserver] => {
    "add_group": "subnet_192.168.101.0",
    "changed": false,
    "parent_groups": [
        "all"
    ]
}

How should I fix this warning?

Thanks,

- Xinhuan

Kai Stian Olstad

unread,
Dec 21, 2019, 2:27:52 AM12/21/19
to ansible...@googlegroups.com
On 20.12.2019 22:08, Xinhuan Zheng wrote:
> - name: Group system by subnet
> group_by:
> key: subnet_{{ansible_default_ipv4.network}}
>
> While I run my playbook, I got this error:
>
> TASK [os-networking : Group system by subnet]
> *************************************************************************************
> task path: os-networking/tasks/main.yml:24
> Not replacing invalid character(s) "set([u'.'])" in group name
> (subnet_192.168.101.0)
> [DEPRECATION WARNING]: The TRANSFORM_INVALID_GROUP_CHARS settings is set to
> allow bad characters in group names by default, this
> will change, but still be user configurable on deprecation. This feature
> will be removed in version 2.10. Deprecation warnings can
> be disabled by setting deprecation_warnings=False in ansible.cfg.
> [WARNING]: Invalid characters were found in group names but not replaced,
> use -vvvv to see details
>
> How should I fix this warning?

Don't use dot in group name or set TRANSFORM_INVALID_GROUP_CHARS to a value of your choice.


--
Kai Stian Olstad

Xinhuan Zheng

unread,
Dec 26, 2019, 9:22:51 AM12/26/19
to Ansible Project
Hello,

The group names by subnet will have dot. How do I change that to avoid dot characters?

- Xinhuan

Kai Stian Olstad

unread,
Dec 26, 2019, 10:57:30 AM12/26/19
to ansible...@googlegroups.com
On 26.12.2019 15:22, Xinhuan Zheng wrote:
> The group names by subnet will have dot. How do I change that to avoid
> dot
> characters?

If you read the documentation about TRANSFORM_INVALID_GROUP_CHARS it
says how you can do it with that.

Alternative is to use the regex_replace filter or the
replace metode {{ ansible_default_ipv4.network.replace('.', '_') }}


--
Kai Stian Olstad

Xinhuan Zheng

unread,
Dec 27, 2019, 9:36:26 AM12/27/19
to Ansible Project
Hello Mr. Kai,

I used {{  ansible_default_ipv4.network.replace('.', '_') }} and created group_vars/subnet_xxx_xxx_xxx_xxx. It worked perfectly. Thank you very much for help!

- Xinhuan
Reply all
Reply to author
Forward
0 new messages