ansible-collections / community.general

Ansible Community General Collection
https://galaxy.ansible.com/ui/repo/published/community/general/
GNU General Public License v3.0
810 stars 1.49k forks source link

nmcli - Can't create connection for eth0 #8583

Open saltstack-admin opened 2 months ago

saltstack-admin commented 2 months ago

Summary

Hi,

I try to create a connection with the name "eth0-config", but I always get this error: "msg": "Error: unknown connection 'eth0-config'.\n", "name": "eth0-config", "rc": 10

Ansible version:

Network interface from the client I try to configure: [test@test-node]$ ip a show eth0 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000 link/ether 00:12:34:56:78:AB brd ff:ff:ff:ff:ff:ff

My Ansible task:

What am I doing wrong?

Issue Type

Bug Report

Component Name

nmcli

Ansible Version

$ ansible --version
ansible [core 2.14.14]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/test/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.9/site-packages/ansible
  ansible collection location = /home/test/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.9.18 (main, May 16 2024, 00:00:00) [GCC 11.4.1 20231218 (Red Hat 11.4.1-3)] (/usr/bin/python3)
  jinja version = 3.1.2
  libyaml = True

Community.general Version

$ ansible-galaxy collection list community.general
# /usr/share/ansible/collections/ansible_collections
Collection        Version
----------------- -------
community.general 7.5.0

Configuration

$ ansible-config dump --only-changed
CONFIG_FILE() = /etc/ansible/ansible.cfg

OS / Environment

ALMALinux 9.4

Steps to Reproduce

- name: configure default NIC
  nmcli:
    autoconnect: true
    conn_name: eth0-config
    ifname: eth0
    method4: manual
    type: ethernet
    ip4: "{{ ipv4_address_with_cidr }}"
    dns4: 
      - "{{ nameserver1 }}"
      - "{{ nameserver2 }}"
    dns4_search: "{{ dns_search_domains }}"
    gw4: "{{ ipv4_gateway }}"
    state: present

Expected Results

I expect, that a connection "eth0-config" is created using NIC "eth0".

Actual Results

fatal: [192.168.254.254]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "addr_gen_mode6": null,
            "ageingtime": 300,
            "arp_interval": null,
            "arp_ip_target": null,
            "autoconnect": true,
            "conn_name": "eth0-config",
            "dhcp_client_id": null,
            "dns4": [
                "mydns.local",
                "[]"
            ],
            "dns4_ignore_auto": false,
            "dns4_options": null,
            "dns4_search": [
                "mydomain.local"
            ],
            "dns6": null,
            "dns6_ignore_auto": false,
            "dns6_options": null,
            "dns6_search": null,
            "downdelay": null,
            "egress": null,
            "flags": null,
            "forwarddelay": 15,
            "gsm": null,
            "gw4": "192.168.254.1",
            "gw4_ignore_auto": false,
            "gw6": null,
            "gw6_ignore_auto": false,
            "hairpin": false,
            "hellotime": 2,
            "ifname": "eth0",
            "ignore_unsupported_suboptions": false,
            "ingress": null,
            "ip4": [
                "192.168.254.254/24"
            ],
            "ip6": null,
            "ip_privacy6": null,
            "ip_tunnel_dev": null,
            "ip_tunnel_input_key": null,
            "ip_tunnel_local": null,
            "ip_tunnel_output_key": null,
            "ip_tunnel_remote": null,
            "mac": null,
            "macvlan": null,
            "master": null,
            "maxage": 20,
            "may_fail4": true,
            "method4": "manual",
            "method6": null,
            "miimon": null,
            "mode": "balance-rr",
            "mtu": 1400,
            "never_default4": false,
            "path_cost": 100,
            "primary": null,
            "priority": 128,
            "route_metric4": null,
            "route_metric6": null,
            "routes4": null,
            "routes4_extended": null,
            "routes6": null,
            "routes6_extended": null,
            "routing_rules4": null,
            "runner": "roundrobin",
            "runner_fast_rate": null,
            "runner_hwaddr_policy": null,
            "slave_type": null,
            "slavepriority": 32,
            "ssid": null,
            "state": "present",
            "stp": true,
            "transport_mode": null,
            "type": "ethernet",
            "updelay": null,
            "vlandev": null,
            "vlanid": null,
            "vpn": null,
            "vxlan_id": null,
            "vxlan_local": null,
            "vxlan_remote": null,
            "wifi": null,
            "wifi_sec": null,
            "wireguard": null,
            "xmit_hash_policy": null,
            "zone": null
        }
    },
    "msg": "Error: unknown connection 'eth0-config'.\n",
    "name": "eth0-config",
    "rc": 10
}

Code of Conduct

ansibullbot commented 2 months ago

Files identified in the description:

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help

ansibullbot commented 2 months ago

cc @alcamie101 click here for bot help

saltstack-admin commented 1 month ago

Found the issue. nameserver2 is as empty var declared and our code did not check properly for it. That way Ansible send this command: nmcli add con type ethernet ipv4.dns 127.0.0.1, ipv4.gw ....... The error the module is displaying is misleading, in debug mode I got from nmcli the message "ipv4.dns2 is malformed".