Skip to content

community.general.nmcli not supporting UTF-8 conn_name due to locale #10384

Open
@Vigilans

Description

@Vigilans

Summary

Locale for community.general.nmcli is set to fixed value (still preserves in current main branch):

module.run_command_environ_update = dict(LANG='C', LC_ALL='C', LC_MESSAGES='C', LC_CTYPE='C')

Issue Type

Bug Report

Component Name

nmcli

Ansible Version

$ ansible --version
ansible [core 2.16.14]

Community.general Version

$ ansible-galaxy collection list community.general
Collection        Version
----------------- -------
community.general 9.5.0

Configuration

OS / Environment

No response

Steps to Reproduce

        - name: Configure NetworkManager connection
          community.general.nmcli:
            conn_name: "{{ ansible_primary_interface_connection.name | default(ansible_primary_interface) }}"
            ifname: "{{ ansible_primary_interface }}"
            type: ethernet
            ip4: "{{ ansible_network_ip }}/{{ ansible_network_prefix }}"
            gw4: "{{ ansible_network_gateway }}"
            dns4: "{{ online_dns }}"
            route_metric4: "{{ metric }}"
            state: present

Expected Results

community.general.nmcli will modify existing connection (UTF-8 name) if already exists

Actual Results

community.general.nmcli will always create new connection (UTF-8 name) no matter whether it exists.

Adding some debug code to result:

TASK [system.network : Configure NetworkManager connection] ******************************************************************************************************************************
changed: [ubuntu-Precision-7920-Tower] => {"Connection": "Connection 有线连接 1 of Type ethernet is being added", "changed": true, "conn_name": "有线连接 1", "debug_conn_name": "有线连接 1", "debug_connection_info": ["???? 1", "br-646e2caad030", "docker0", "VPN 1"], "state": "present", "stdout": "Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/42)\n", "stdout_lines": ["Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/42)"]}

In nmcli command output invoked from module, 有线连接 1 becomes ???? 1 which makes connection_exists check always fail:

def list_connection_info(self):
cmd = [self.nmcli_bin, '--fields', 'name', '--terse', 'con', 'show']
(rc, out, err) = self.execute_command(cmd)
if rc != 0:
raise NmcliModuleError(err)
return out.splitlines()
def connection_exists(self):
return self.conn_name in self.list_connection_info()

Code of Conduct

  • I agree to follow the Ansible Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis issue/PR relates to a bugmodulemodulepluginsplugin (any type)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions