
    Vh                        d dl mZmZmZ eZdZdZdZd dl	m
Z
 d dlmZ d dlZ G d d	e      Z G d
 de      Zd Zedk(  r e        yy)    )absolute_importdivisionprint_functiona  
module: nmcli
author:
  - Chris Long (@alcamie101)
short_description: Manage Networking
requirements:
  - nmcli
extends_documentation_fragment:
  - community.general.attributes
description:
  - Manage the network devices. Create, modify and manage various connection and device type, for example V(ethernet), V(team),
    V(bond), V(vlan) and so on.
  - 'On CentOS 8 and Fedora >=29 like systems, the requirements can be met by installing the following packages: NetworkManager.'
  - 'On CentOS 7 and Fedora <=28 like systems, the requirements can be met by installing the following packages: NetworkManager-tui.'
  - 'On Ubuntu and Debian like systems, the requirements can be met by installing the following packages: network-manager.'
  - 'On openSUSE, the requirements can be met by installing the following packages: NetworkManager.'
attributes:
  check_mode:
    support: full
  diff_mode:
    support: full
options:
  state:
    description:
      - Whether the device should exist or not, taking action if the state is different from what is stated.
      - Using O(state=present) to create connection will automatically bring connection up.
      - Using O(state=up) and O(state=down) will not modify connection with other parameters. These states have been added
        in community.general 9.5.0.
    type: str
    required: true
    choices: [absent, present, up, down]
  autoconnect:
    description:
      - Whether the connection should start on boot.
      - Whether the connection profile can be automatically activated.
    type: bool
    default: true
  conn_name:
    description:
      - The name used to call the connection. Pattern is V(<type>[-<ifname>][-<num>]).
    type: str
    required: true
  conn_reload:
    description:
      - Whether the connection should be reloaded if it was modified.
    type: bool
    required: false
    default: false
    version_added: 9.5.0
  ifname:
    description:
      - The interface to bind the connection to.
      - The connection will only be applicable to this interface name.
      - A special value of V(*) can be used for interface-independent connections.
      - The ifname argument is mandatory for all connection types except bond, team, bridge, vlan and vpn.
      - This parameter defaults to O(conn_name) when left unset for all connection types except vpn that removes it.
    type: str
  type:
    description:
      - This is the type of device or network connection that you wish to create or modify.
      - Type V(dummy) is added in community.general 3.5.0.
      - Type V(gsm) is added in community.general 3.7.0.
      - Type V(infiniband) is added in community.general 2.0.0.
      - Type V(loopback) is added in community.general 8.1.0.
      - Type V(macvlan) is added in community.general 6.6.0.
      - Type V(ovs-bridge) is added in community.general 8.6.0.
      - Type V(ovs-interface) is added in community.general 8.6.0.
      - Type V(ovs-port) is added in community.general 8.6.0.
      - Type V(wireguard) is added in community.general 4.3.0.
      - Type V(vpn) is added in community.general 5.1.0.
      - Type V(vrf) is added in community.general 10.4.0.
      - Using V(bond-slave), V(bridge-slave), or V(team-slave) implies V(ethernet) connection type with corresponding O(slave_type)
        option.
      - If you want to control non-ethernet connection attached to V(bond), V(bridge), or V(team) consider using O(slave_type)
        option.
    type: str
    choices:
      - bond
      - bond-slave
      - bridge
      - bridge-slave
      - dummy
      - ethernet
      - generic
      - gre
      - infiniband
      - ipip
      - macvlan
      - sit
      - team
      - team-slave
      - vlan
      - vxlan
      - wifi
      - gsm
      - wireguard
      - ovs-bridge
      - ovs-port
      - ovs-interface
      - vpn
      - vrf
      - loopback
  mode:
    description:
      - This is the type of device or network connection that you wish to create for a bond or bridge.
    type: str
    choices: [802.3ad, active-backup, balance-alb, balance-rr, balance-tlb, balance-xor, broadcast]
    default: balance-rr
  transport_mode:
    description:
      - This option sets the connection type of Infiniband IPoIB devices.
    type: str
    choices: [datagram, connected]
    version_added: 5.8.0
  infiniband_mac:
    description:
      - MAC address of the Infiniband IPoIB devices.
    type: str
    version_added: 10.6.0
  slave_type:
    description:
      - Type of the device of this slave's master connection (for example V(bond)).
      - Type V(ovs-port) is added in community.general 8.6.0.
    type: str
    choices: ['bond', 'bridge', 'team', 'ovs-port', 'vrf']
    version_added: 7.0.0
  master:
    description:
      - Master <master (ifname, or connection UUID or conn_name) of bridge, team, bond, ovs-port master connection profile.
      - Mandatory if O(slave_type) is defined.
    type: str
  ip4:
    description:
      - List of IPv4 addresses to this interface.
      - Use the format V(192.0.2.24/24) or V(192.0.2.24).
      - If defined and O(method4) is not specified, automatically set C(ipv4.method) to V(manual).
    type: list
    elements: str
  gw4:
    description:
      - The IPv4 gateway for this interface.
      - Use the format V(192.0.2.1).
      - This parameter is mutually_exclusive with never_default4 parameter.
    type: str
  gw4_ignore_auto:
    description:
      - Ignore automatically configured IPv4 routes.
    type: bool
    default: false
    version_added: 3.2.0
  routes4:
    description:
      - The list of IPv4 routes.
      - Use the format V(192.0.3.0/24 192.0.2.1).
      - To specify more complex routes, use the O(routes4_extended) option.
    type: list
    elements: str
    version_added: 2.0.0
  routes4_extended:
    description:
      - The list of IPv4 routes.
    type: list
    elements: dict
    suboptions:
      ip:
        description:
          - IP or prefix of route.
          - Use the format V(192.0.3.0/24).
        type: str
        required: true
      next_hop:
        description:
          - Use the format V(192.0.2.1).
        type: str
      metric:
        description:
          - Route metric.
        type: int
      table:
        description:
          - The table to add this route to.
          - The default depends on C(ipv4.route-table).
        type: int
      cwnd:
        description:
          - The clamp for congestion window.
        type: int
      mtu:
        description:
          - If non-zero, only transmit packets of the specified size or smaller.
        type: int
      onlink:
        description:
          - Pretend that the nexthop is directly attached to this link, even if it does not match any interface prefix.
        type: bool
      tos:
        description:
          - The Type Of Service.
        type: int
  route_metric4:
    description:
      - Set metric level of ipv4 routes configured on interface.
    type: int
    version_added: 2.0.0
  routing_rules4:
    description:
      - Is the same as in an C(ip rule add) command, except always requires specifying a priority.
    type: list
    elements: str
    version_added: 3.3.0
  never_default4:
    description:
      - Set as default route.
      - This parameter is mutually_exclusive with gw4 parameter.
    type: bool
    default: false
    version_added: 2.0.0
  dns4:
    description:
      - A list of up to 3 DNS servers.
      - The entries must be IPv4 addresses, for example V(192.0.2.53).
    elements: str
    type: list
  dns4_search:
    description:
      - A list of DNS search domains.
    elements: str
    type: list
  dns4_options:
    description:
      - A list of DNS options.
    elements: str
    type: list
    version_added: 7.2.0
  dns4_ignore_auto:
    description:
      - Ignore automatically configured IPv4 name servers.
    type: bool
    default: false
    version_added: 3.2.0
  method4:
    description:
      - Configuration method to be used for IPv4.
      - If O(ip4) is set, C(ipv4.method) is automatically set to V(manual) and this parameter is not needed.
    type: str
    choices: [auto, link-local, manual, shared, disabled]
    version_added: 2.2.0
  may_fail4:
    description:
      - If you need O(ip4) configured before C(network-online.target) is reached, set this option to V(false).
      - This option applies when O(method4) is not V(disabled).
    type: bool
    default: true
    version_added: 3.3.0
  ip6:
    description:
      - List of IPv6 addresses to this interface.
      - Use the format V(abbe::cafe/128) or V(abbe::cafe).
      - If defined and O(method6) is not specified, automatically set C(ipv6.method) to V(manual).
    type: list
    elements: str
  gw6:
    description:
      - The IPv6 gateway for this interface.
      - Use the format V(2001:db8::1).
    type: str
  gw6_ignore_auto:
    description:
      - Ignore automatically configured IPv6 routes.
    type: bool
    default: false
    version_added: 3.2.0
  routes6:
    description:
      - The list of IPv6 routes.
      - Use the format V(fd12:3456:789a:1::/64 2001:dead:beef::1).
      - To specify more complex routes, use the O(routes6_extended) option.
    type: list
    elements: str
    version_added: 4.4.0
  routes6_extended:
    description:
      - The list of IPv6 routes but with parameters.
    type: list
    elements: dict
    suboptions:
      ip:
        description:
          - IP or prefix of route.
          - Use the format V(fd12:3456:789a:1::/64).
        type: str
        required: true
      next_hop:
        description:
          - Use the format V(2001:dead:beef::1).
        type: str
      metric:
        description:
          - Route metric.
        type: int
      table:
        description:
          - The table to add this route to.
          - The default depends on C(ipv6.route-table).
        type: int
      cwnd:
        description:
          - The clamp for congestion window.
        type: int
      mtu:
        description:
          - If non-zero, only transmit packets of the specified size or smaller.
        type: int
      onlink:
        description:
          - Pretend that the nexthop is directly attached to this link, even if it does not match any interface prefix.
        type: bool
  route_metric6:
    description:
      - Set metric level of IPv6 routes configured on interface.
    type: int
    version_added: 4.4.0
  dns6:
    description:
      - A list of up to 3 DNS servers.
      - The entries must be IPv6 addresses, for example V(2001:4860:4860::8888).
    elements: str
    type: list
  dns6_search:
    description:
      - A list of DNS search domains.
    elements: str
    type: list
  dns6_options:
    description:
      - A list of DNS options.
    elements: str
    type: list
    version_added: 7.2.0
  dns6_ignore_auto:
    description:
      - Ignore automatically configured IPv6 name servers.
    type: bool
    default: false
    version_added: 3.2.0
  method6:
    description:
      - Configuration method to be used for IPv6.
      - If O(ip6) is set, C(ipv6.method) is automatically set to V(manual) and this parameter is not needed.
      - V(disabled) was added in community.general 3.3.0.
    type: str
    choices: [ignore, auto, dhcp, link-local, manual, shared, disabled]
    version_added: 2.2.0
  ip_privacy6:
    description:
      - If enabled, it makes the kernel generate a temporary IPv6 address in addition to the public one.
    type: str
    choices: [disabled, prefer-public-addr, prefer-temp-addr, unknown]
    version_added: 4.2.0
  addr_gen_mode6:
    description:
      - Configure method for creating the address for use with IPv6 Stateless Address Autoconfiguration.
      - V(default) and V(default-or-eui64) have been added in community.general 6.5.0.
    type: str
    choices: [default, default-or-eui64, eui64, stable-privacy]
    version_added: 4.2.0
  mtu:
    description:
      - The connection MTU, for example V(9000). This can not be applied when creating the interface and is done once the
        interface has been created.
      - Can be used when modifying Team, VLAN, Ethernet (Future plans to implement wifi, gsm, pppoe, infiniband).
      - This parameter defaults to V(1500) when unset.
    type: int
  dhcp_client_id:
    description:
      - DHCP Client Identifier sent to the DHCP server.
    type: str
  primary:
    description:
      - This is only used with bond and is the primary interface name (for "active-backup" mode), this is the usually the
        'ifname'.
    type: str
  miimon:
    description:
      - This is only used with bond - miimon.
      - This parameter defaults to V(100) when unset.
    type: int
  downdelay:
    description:
      - This is only used with bond - downdelay.
    type: int
  updelay:
    description:
      - This is only used with bond - updelay.
    type: int
  xmit_hash_policy:
    description:
      - This is only used with bond - xmit_hash_policy type.
    type: str
    version_added: 5.6.0
  fail_over_mac:
    description:
      - This is only used with bond - fail_over_mac.
    type: str
    choices: [none, active, follow]
    version_added: 10.3.0
  arp_interval:
    description:
      - This is only used with bond - ARP interval.
    type: int
  arp_ip_target:
    description:
      - This is only used with bond - ARP IP target.
    type: str
  stp:
    description:
      - This is only used with bridge and controls whether Spanning Tree Protocol (STP) is enabled for this bridge.
    type: bool
    default: true
  priority:
    description:
      - This is only used with 'bridge' - sets STP priority.
    type: int
    default: 128
  forwarddelay:
    description:
      - This is only used with bridge - [forward-delay <2-30>] STP forwarding delay, in seconds.
    type: int
    default: 15
  hellotime:
    description:
      - This is only used with bridge - [hello-time <1-10>] STP hello time, in seconds.
    type: int
    default: 2
  maxage:
    description:
      - This is only used with bridge - [max-age <6-42>] STP maximum message age, in seconds.
    type: int
    default: 20
  ageingtime:
    description:
      - This is only used with bridge - [ageing-time <0-1000000>] the Ethernet MAC address aging time, in seconds.
    type: int
    default: 300
  mac:
    description:
      - MAC address of the connection.
      - Note this requires a recent kernel feature, originally introduced in 3.15 upstream kernel.
    type: str
  slavepriority:
    description:
      - This is only used with 'bridge-slave' - [<0-63>] - STP priority of this slave.
    type: int
    default: 32
  path_cost:
    description:
      - This is only used with 'bridge-slave' - [<1-65535>] - STP port cost for destinations using this slave.
    type: int
    default: 100
  hairpin:
    description:
      - This is only used with 'bridge-slave' - 'hairpin mode' for the slave, which allows frames to be sent back out through
        the slave the frame was received on.
      - The default change to V(false) in community.general 7.0.0. It used to be V(true) before.
    type: bool
    default: false
  runner:
    description:
      - This is the type of device or network connection that you wish to create for a team.
    type: str
    choices: [broadcast, roundrobin, activebackup, loadbalance, lacp]
    default: roundrobin
    version_added: 3.4.0
  runner_hwaddr_policy:
    description:
      - This defines the policy of how hardware addresses of team device and port devices should be set during the team lifetime.
    type: str
    choices: [same_all, by_active, only_active]
    version_added: 3.4.0
  runner_fast_rate:
    description:
      - Option specifies the rate at which our link partner is asked to transmit LACPDU packets. If this is V(true) then packets
        will be sent once per second. Otherwise they will be sent every 30 seconds.
      - Only allowed for O(runner=lacp).
    type: bool
    version_added: 6.5.0
  vlanid:
    description:
      - This is only used with VLAN - VLAN ID in range <0-4095>.
    type: int
  vlandev:
    description:
      - This is only used with VLAN - parent device this VLAN is on, can use ifname.
    type: str
  flags:
    description:
      - This is only used with VLAN - flags.
    type: str
  ingress:
    description:
      - This is only used with VLAN - VLAN ingress priority mapping.
    type: str
  egress:
    description:
      - This is only used with VLAN - VLAN egress priority mapping.
    type: str
  vxlan_id:
    description:
      - This is only used with VXLAN - VXLAN ID.
    type: int
  vxlan_remote:
    description:
      - This is only used with VXLAN - VXLAN destination IP address.
    type: str
  vxlan_local:
    description:
      - This is only used with VXLAN - VXLAN local IP address.
    type: str
  ip_tunnel_dev:
    description:
      - This is used with GRE/IPIP/SIT - parent device this GRE/IPIP/SIT tunnel, can use ifname.
    type: str
  ip_tunnel_remote:
    description:
      - This is used with GRE/IPIP/SIT - GRE/IPIP/SIT destination IP address.
    type: str
  ip_tunnel_local:
    description:
      - This is used with GRE/IPIP/SIT - GRE/IPIP/SIT local IP address.
    type: str
  ip_tunnel_input_key:
    description:
      - The key used for tunnel input packets.
      - Only used when O(type=gre).
    type: str
    version_added: 3.6.0
  ip_tunnel_output_key:
    description:
      - The key used for tunnel output packets.
      - Only used when O(type=gre).
    type: str
    version_added: 3.6.0
  table:
    description:
      - This is only used with VRF - VRF table number.
    type: int
    version_added: 10.4.0
  zone:
    description:
      - The trust level of the connection.
      - When updating this property on a currently activated connection, the change takes effect immediately.
    type: str
    version_added: 2.0.0
  wifi_sec:
    description:
      - The security configuration of the WiFi connection.
      - Note the list of suboption attributes may vary depending on which version of NetworkManager/nmcli is installed on
        the host.
      - 'An up-to-date list of supported attributes can be found here: U(https://networkmanager.dev/docs/api/latest/settings-802-11-wireless-security.html).'
      - 'For instance to use common WPA-PSK auth with a password: V({key-mgmt: wpa-psk, psk: my_password}).'
    type: dict
    suboptions:
      auth-alg:
        description:
          - When WEP is used (that is, if O(wifi_sec.key-mgmt) is V(none) or V(ieee8021x)) indicate the 802.11 authentication
            algorithm required by the AP here.
          - One of V(open) for Open System, V(shared) for Shared Key, or V(leap) for Cisco LEAP.
          - When using Cisco LEAP (that is, if O(wifi_sec.key-mgmt=ieee8021x) and O(wifi_sec.auth-alg=leap)) the O(wifi_sec.leap-username)
            and O(wifi_sec.leap-password) properties must be specified.
        type: str
        choices: [open, shared, leap]
      fils:
        description:
          - Indicates whether Fast Initial Link Setup (802.11ai) must be enabled for the connection.
          - One of V(0) (use global default value), V(1) (disable FILS), V(2) (enable FILS if the supplicant and the access
            point support it) or V(3) (enable FILS and fail if not supported).
          - When set to V(0) and no global default is set, FILS will be optionally enabled.
        type: int
        choices: [0, 1, 2, 3]
        default: 0
      group:
        description:
          - A list of group/broadcast encryption algorithms which prevents connections to Wi-Fi networks that do not utilize
            one of the algorithms in the list.
          - For maximum compatibility leave this property empty.
        type: list
        elements: str
        choices: [wep40, wep104, tkip, ccmp]
      key-mgmt:
        description:
          - Key management used for the connection.
          - One of V(none) (WEP or no password protection), V(ieee8021x) (Dynamic WEP), V(owe) (Opportunistic Wireless Encryption),
            V(wpa-psk) (WPA2 + WPA3 personal), V(sae) (WPA3 personal only), V(wpa-eap) (WPA2 + WPA3 enterprise) or V(wpa-eap-suite-b-192)
            (WPA3 enterprise only).
          - This property must be set for any Wi-Fi connection that uses security.
        type: str
        choices: [none, ieee8021x, owe, wpa-psk, sae, wpa-eap, wpa-eap-suite-b-192]
      leap-password-flags:
        description: Flags indicating how to handle the O(wifi_sec.leap-password) property.
        type: list
        elements: int
      leap-password:
        description: The login password for legacy LEAP connections (that is, if O(wifi_sec.key-mgmt=ieee8021x) and O(wifi_sec.auth-alg=leap)).
        type: str
      leap-username:
        description: The login username for legacy LEAP connections (that is, if O(wifi_sec.key-mgmt=ieee8021x) and O(wifi_sec.auth-alg=leap)).
        type: str
      pairwise:
        description:
          - A list of pairwise encryption algorithms which prevents connections to Wi-Fi networks that do not utilize one
            of the algorithms in the list.
          - For maximum compatibility leave this property empty.
        type: list
        elements: str
        choices: [tkip, ccmp]
      pmf:
        description:
          - Indicates whether Protected Management Frames (802.11w) must be enabled for the connection.
          - One of V(0) (use global default value), V(1) (disable PMF), V(2) (enable PMF if the supplicant and the access
            point support it) or V(3) (enable PMF and fail if not supported).
          - When set to V(0) and no global default is set, PMF will be optionally enabled.
        type: int
        choices: [0, 1, 2, 3]
        default: 0
      proto:
        description:
          - List of strings specifying the allowed WPA protocol versions to use.
          - Each element may be V(wpa) (allow WPA) or V(rsn) (allow WPA2/RSN).
          - If not specified, both WPA and RSN connections are allowed.
        type: list
        elements: str
        choices: [wpa, rsn]
      psk-flags:
        description: Flags indicating how to handle the O(wifi_sec.psk) property.
        type: list
        elements: int
      psk:
        description:
          - Pre-Shared-Key for WPA networks.
          - For WPA-PSK, it is either an ASCII passphrase of 8 to 63 characters that is (as specified in the 802.11i standard)
            hashed to derive the actual key, or the key in form of 64 hexadecimal character.
          - The WPA3-Personal networks use a passphrase of any length for SAE authentication.
        type: str
      wep-key-flags:
        description:
          - Flags indicating how to handle the O(wifi_sec.wep-key0), O(wifi_sec.wep-key1), O(wifi_sec.wep-key2), and O(wifi_sec.wep-key3)
            properties.
        type: list
        elements: int
      wep-key-type:
        description:
          - Controls the interpretation of WEP keys.
          - Allowed values are V(1), in which case the key is either a 10- or 26-character hexadecimal string, or a 5- or
            13-character ASCII password; or V(2), in which case the passphrase is provided as a string and will be hashed
            using the de-facto MD5 method to derive the actual WEP key.
        type: int
        choices: [1, 2]
      wep-key0:
        description:
          - Index 0 WEP key. This is the WEP key used in most networks.
          - See the O(wifi_sec.wep-key-type) property for a description of how this key is interpreted.
        type: str
      wep-key1:
        description:
          - Index 1 WEP key. This WEP index is not used by most networks.
          - See the O(wifi_sec.wep-key-type) property for a description of how this key is interpreted.
        type: str
      wep-key2:
        description:
          - Index 2 WEP key. This WEP index is not used by most networks.
          - See the O(wifi_sec.wep-key-type) property for a description of how this key is interpreted.
        type: str
      wep-key3:
        description:
          - Index 3 WEP key. This WEP index is not used by most networks.
          - See the O(wifi_sec.wep-key-type) property for a description of how this key is interpreted.
        type: str
      wep-tx-keyidx:
        description:
          - When static WEP is used (that is, if O(wifi_sec.key-mgmt=none)) and a non-default WEP key index is used by the
            AP, put that WEP key index here.
          - Valid values are V(0) (default key) through V(3).
          - Note that some consumer access points (like the Linksys WRT54G) number the keys V(1) to V(4).
        type: int
        choices: [0, 1, 2, 3]
        default: 0
      wps-method:
        description:
          - Flags indicating which mode of WPS is to be used if any.
          - There is little point in changing the default setting as NetworkManager will automatically determine whether it
            is feasible to start WPS enrollment from the Access Point capabilities.
          - WPS can be disabled by setting this property to a value of V(1).
        type: int
        default: 0
    version_added: 3.0.0
  ssid:
    description:
      - Name of the Wireless router or the access point.
    type: str
    version_added: 3.0.0
  wifi:
    description:
      - The configuration of the WiFi connection.
      - Note the list of suboption attributes may vary depending on which version of NetworkManager/nmcli is installed on
        the host.
      - 'An up-to-date list of supported attributes can be found here: U(https://networkmanager.dev/docs/api/latest/settings-802-11-wireless.html).'
      - 'For instance to create a hidden AP mode WiFi connection: V({hidden: true, mode: ap}).'
    type: dict
    suboptions:
      ap-isolation:
        description:
          - Configures AP isolation, which prevents communication between wireless devices connected to this AP.
          - This property can be set to a value different from V(-1) only when the interface is configured in AP mode.
          - If set to V(1), devices are not able to communicate with each other. This increases security because it protects
            devices against attacks from other clients in the network. At the same time, it prevents devices to access resources
            on the same wireless networks as file shares, printers, and so on.
          - If set to V(0), devices can talk to each other.
          - When set to V(-1), the global default is used; in case the global default is unspecified it is assumed to be V(0).
        type: int
        choices: [-1, 0, 1]
        default: -1
      assigned-mac-address:
        description:
          - The new field for the cloned MAC address.
          - It can be either a hardware address in ASCII representation, or one of the special values V(preserve), V(permanent),
            V(random) or V(stable).
          - This field replaces the deprecated O(wifi.cloned-mac-address) on D-Bus, which can only contain explicit hardware
            addresses.
          - Note that this property only exists in D-Bus API. libnm and nmcli continue to call this property C(cloned-mac-address).
        type: str
      band:
        description:
          - 802.11 frequency band of the network.
          - One of V(a) for 5GHz 802.11a or V(bg) for 2.4GHz 802.11.
          - This will lock associations to the Wi-Fi network to the specific band, so for example, if V(a) is specified, the
            device will not associate with the same network in the 2.4GHz band even if the network's settings are compatible.
          - This setting depends on specific driver capability and may not work with all drivers.
        type: str
        choices: [a, bg]
      bssid:
        description:
          - If specified, directs the device to only associate with the given access point.
          - This capability is highly driver dependent and not supported by all devices.
          - Note this property does not control the BSSID used when creating an Ad-Hoc network and is unlikely to in the future.
        type: str
      channel:
        description:
          - Wireless channel to use for the Wi-Fi connection.
          - The device will only join (or create for Ad-Hoc networks) a Wi-Fi network on the specified channel.
          - Because channel numbers overlap between bands, this property also requires the O(wifi.band) property to be set.
        type: int
        default: 0
      cloned-mac-address:
        description:
          - This D-Bus field is deprecated in favor of O(wifi.assigned-mac-address) which is more flexible and allows specifying
            special variants like V(random).
          - For libnm and nmcli, this field is called C(cloned-mac-address).
        type: str
      generate-mac-address-mask:
        description:
          - With O(wifi.cloned-mac-address) setting V(random) or V(stable), by default all bits of the MAC address are scrambled
            and a locally-administered, unicast MAC address is created. This property allows to specify that certain bits
            are fixed.
          - Note that the least significant bit of the first MAC address will always be unset to create a unicast MAC address.
          - If the property is V(null), it is eligible to be overwritten by a default connection setting.
          - If the value is still V(null) or an empty string, the default is to create a locally-administered, unicast MAC
            address.
          - If the value contains one MAC address, this address is used as mask. The set bits of the mask are to be filled
            with the current MAC address of the device, while the unset bits are subject to randomization.
          - Setting V(FE:FF:FF:00:00:00) means to preserve the OUI of the current MAC address and only randomize the lower
            3 bytes using the V(random) or V(stable) algorithm.
          - If the value contains one additional MAC address after the mask, this address is used instead of the current MAC
            address to fill the bits that shall not be randomized.
          - For example, a value of V(FE:FF:FF:00:00:00 68:F7:28:00:00:00) will set the OUI of the MAC address to 68:F7:28,
            while the lower bits are randomized.
          - A value of V(02:00:00:00:00:00 00:00:00:00:00:00) will create a fully scrambled globally-administered, burned-in
            MAC address.
          - If the value contains more than one additional MAC addresses, one of them is chosen randomly. For example, V(02:00:00:00:00:00
            00:00:00:00:00:00 02:00:00:00:00:00) will create a fully scrambled MAC address, randomly locally or globally administered.
        type: str
      hidden:
        description:
          - If V(true), indicates that the network is a non-broadcasting network that hides its SSID. This works both in infrastructure
            and AP mode.
          - In infrastructure mode, various workarounds are used for a more reliable discovery of hidden networks, such as
            probe-scanning the SSID. However, these workarounds expose inherent insecurities with hidden SSID networks, and
            thus hidden SSID networks should be used with caution.
          - In AP mode, the created network does not broadcast its SSID.
          - Note that marking the network as hidden may be a privacy issue for you (in infrastructure mode) or client stations
            (in AP mode), as the explicit probe-scans are distinctly recognizable on the air.
        type: bool
        default: false
      mac-address-blacklist:
        description:
          - A list of permanent MAC addresses of Wi-Fi devices to which this connection should never apply.
          - Each MAC address should be given in the standard hex-digits-and-colons notation (for example, V(00:11:22:33:44:55)).
        type: list
        elements: str
      mac-address-randomization:
        description:
          - One of V(0) (never randomize unless the user has set a global default to randomize and the supplicant supports
            randomization), V(1) (never randomize the MAC address), or V(2) (always randomize the MAC address).
          - This property is deprecated for O(wifi.cloned-mac-address).
        type: int
        default: 0
        choices: [0, 1, 2]
      mac-address:
        description:
          - If specified, this connection will only apply to the Wi-Fi device whose permanent MAC address matches.
          - This property does not change the MAC address of the device (for example for MAC spoofing).
        type: str
      mode:
        description: Wi-Fi network mode. If blank, V(infrastructure) is assumed.
        type: str
        choices: [infrastructure, mesh, adhoc, ap]
        default: infrastructure
      mtu:
        description: If non-zero, only transmit packets of the specified size or smaller, breaking larger packets up into
          multiple Ethernet frames.
        type: int
        default: 0
      powersave:
        description:
          - One of V(2) (disable Wi-Fi power saving), V(3) (enable Wi-Fi power saving), V(1) (do not touch currently configure
            setting) or V(0) (use the globally configured value).
          - All other values are reserved.
        type: int
        default: 0
        choices: [0, 1, 2, 3]
      rate:
        description:
          - If non-zero, directs the device to only use the specified bitrate for communication with the access point.
          - Units are in Kb/s, so for example V(5500) = 5.5 Mbit/s.
          - This property is highly driver dependent and not all devices support setting a static bitrate.
        type: int
        default: 0
      tx-power:
        description:
          - If non-zero, directs the device to use the specified transmit power.
          - Units are dBm.
          - This property is highly driver dependent and not all devices support setting a static transmit power.
        type: int
        default: 0
      wake-on-wlan:
        description:
          - The NMSettingWirelessWakeOnWLan options to enable. Not all devices support all options.
          - May be any combination of C(NM_SETTING_WIRELESS_WAKE_ON_WLAN_ANY) (V(0x2)), C(NM_SETTING_WIRELESS_WAKE_ON_WLAN_DISCONNECT)
            (V(0x4)), C(NM_SETTING_WIRELESS_WAKE_ON_WLAN_MAGIC) (V(0x8)), C(NM_SETTING_WIRELESS_WAKE_ON_WLAN_GTK_REKEY_FAILURE)
            (V(0x10)), C(NM_SETTING_WIRELESS_WAKE_ON_WLAN_EAP_IDENTITY_REQUEST) (V(0x20)), C(NM_SETTING_WIRELESS_WAKE_ON_WLAN_4WAY_HANDSHAKE)
            (V(0x40)), C(NM_SETTING_WIRELESS_WAKE_ON_WLAN_RFKILL_RELEASE) (V(0x80)), C(NM_SETTING_WIRELESS_WAKE_ON_WLAN_TCP)
            (V(0x100)) or the special values V(0x1) (to use global settings) and V(0x8000) (to disable management of Wake-on-LAN
            in NetworkManager).
          - Note the option values' sum must be specified in order to combine multiple options.
        type: int
        default: 1
    version_added: 3.5.0
  ignore_unsupported_suboptions:
    description:
      - Ignore suboptions which are invalid or unsupported by the version of NetworkManager/nmcli installed on the host.
      - Only O(wifi) and O(wifi_sec) options are currently affected.
    type: bool
    default: false
    version_added: 3.6.0
  gsm:
    description:
      - The configuration of the GSM connection.
      - Note the list of suboption attributes may vary depending on which version of NetworkManager/nmcli is installed on
        the host.
      - 'An up-to-date list of supported attributes can be found here: U(https://networkmanager.dev/docs/api/latest/settings-gsm.html).'
      - 'For instance to use apn, pin, username and password: V({apn: provider.apn, pin: 1234, username: apn.username, password:
        apn.password}).'
    type: dict
    version_added: 3.7.0
    suboptions:
      apn:
        description:
          - The GPRS Access Point Name specifying the APN used when establishing a data session with the GSM-based network.
          - The APN often determines how the user will be billed for their network usage and whether the user has access to
            the Internet or just a provider-specific walled-garden, so it is important to use the correct APN for the user's
            mobile broadband plan.
          - The APN may only be composed of the characters a-z, 0-9, ., and - per GSM 03.60 Section 14.9.
        type: str
      auto-config:
        description: When V(true), the settings such as O(gsm.apn), O(gsm.username), or O(gsm.password) will default to values
          that match the network the modem will register to in the Mobile Broadband Provider database.
        type: bool
        default: false
      device-id:
        description:
          - The device unique identifier (as given by the V(WWAN) management service) which this connection applies to.
          - If given, the connection will only apply to the specified device.
        type: str
      home-only:
        description:
          - When V(true), only connections to the home network will be allowed.
          - Connections to roaming networks will not be made.
        type: bool
        default: false
      mtu:
        description: If non-zero, only transmit packets of the specified size or smaller, breaking larger packets up into
          multiple Ethernet frames.
        type: int
        default: 0
      network-id:
        description:
          - The Network ID (GSM LAI format, ie MCC-MNC) to force specific network registration.
          - If the Network ID is specified, NetworkManager will attempt to force the device to register only on the specified
            network.
          - This can be used to ensure that the device does not roam when direct roaming control of the device is not otherwise
            possible.
        type: str
      number:
        description: Legacy setting that used to help establishing PPP data sessions for GSM-based modems.
        type: str
      password:
        description:
          - The password used to authenticate with the network, if required.
          - Many providers do not require a password, or accept any password.
          - But if a password is required, it is specified here.
        type: str
      password-flags:
        description:
          - NMSettingSecretFlags indicating how to handle the O(gsm.password) property.
          - 'Following choices are allowed: V(0) B(NONE): The system is responsible for providing and storing this secret
            (default), V(1) B(AGENT_OWNED): A user secret agent is responsible for providing and storing this secret; when
            it is required agents will be asked to retrieve it V(2) B(NOT_SAVED): This secret should not be saved, but should
            be requested from the user each time it is needed V(4) B(NOT_REQUIRED): In situations where it cannot be automatically
            determined that the secret is required (some VPNs and PPP providers do not require all secrets) this flag indicates
            that the specific secret is not required.'
        type: int
        choices: [0, 1, 2, 4]
        default: 0
      pin:
        description:
          - If the SIM is locked with a PIN it must be unlocked before any other operations are requested.
          - Specify the PIN here to allow operation of the device.
        type: str
      pin-flags:
        description:
          - NMSettingSecretFlags indicating how to handle the O(gsm.pin) property.
          - See O(gsm.password-flags) for NMSettingSecretFlags choices.
        type: int
        choices: [0, 1, 2, 4]
        default: 0
      sim-id:
        description:
          - The SIM card unique identifier (as given by the C(WWAN) management service) which this connection applies to.
          - If given, the connection will apply to any device also allowed by O(gsm.device-id) which contains a SIM card matching
            the given identifier.
        type: str
      sim-operator-id:
        description:
          - A MCC/MNC string like V(310260) or V(21601I) identifying the specific mobile network operator which this connection
            applies to.
          - If given, the connection will apply to any device also allowed by O(gsm.device-id) and O(gsm.sim-id) which contains
            a SIM card provisioned by the given operator.
        type: str
      username:
        description:
          - The username used to authenticate with the network, if required.
          - Many providers do not require a username, or accept any username.
          - But if a username is required, it is specified here.
  macvlan:
    description:
      - The configuration of the MAC VLAN connection.
      - Note the list of suboption attributes may vary depending on which version of NetworkManager/nmcli is installed on
        the host.
      - 'An up-to-date list of supported attributes can be found here: U(https://networkmanager.dev/docs/api/latest/settings-macvlan.html).'
    type: dict
    version_added: 6.6.0
    suboptions:
      mode:
        description:
          - The macvlan mode, which specifies the communication mechanism between multiple macvlans on the same lower device.
          - 'Following choices are allowed: V(1) B(vepa), V(2) B(bridge), V(3) B(private), V(4) B(passthru) and V(5) B(source).'
        type: int
        choices: [1, 2, 3, 4, 5]
        required: true
      parent:
        description:
          - If given, specifies the parent interface name or parent connection UUID from which this MAC-VLAN interface should
            be created. If this property is not specified, the connection must contain an "802-3-ethernet" setting with a
            "mac-address" property.
        type: str
        required: true
      promiscuous:
        description:
          - Whether the interface should be put in promiscuous mode.
        type: bool
      tap:
        description:
          - Whether the interface should be a MACVTAP.
        type: bool
  wireguard:
    description:
      - The configuration of the Wireguard connection.
      - Note the list of suboption attributes may vary depending on which version of NetworkManager/nmcli is installed on
        the host.
      - 'An up-to-date list of supported attributes can be found here: U(https://networkmanager.dev/docs/api/latest/settings-wireguard.html).'
      - 'For instance to configure a listen port: V({listen-port: 12345}).'
    type: dict
    version_added: 4.3.0
    suboptions:
      fwmark:
        description:
          - The 32-bit fwmark for outgoing packets.
          - The use of fwmark is optional and is by default off. Setting it to 0 disables it.
          - Note that O(wireguard.ip4-auto-default-route) or O(wireguard.ip6-auto-default-route) enabled, implies to automatically
            choose a fwmark.
        type: int
      ip4-auto-default-route:
        description:
          - Whether to enable special handling of the IPv4 default route.
          - If enabled, the IPv4 default route from O(wireguard.peer-routes) will be placed to a dedicated routing-table and
            two policy routing rules will be added.
          - The fwmark number is also used as routing-table for the default-route, and if fwmark is zero, an unused fwmark/table
            is chosen automatically. This corresponds to what wg-quick does with Table=auto and what WireGuard calls "Improved
            Rule-based Routing".
        type: bool
      ip6-auto-default-route:
        description:
          - Like O(wireguard.ip4-auto-default-route), but for the IPv6 default route.
        type: bool
      listen-port:
        description: The WireGuard connection listen-port. If not specified, the port will be chosen randomly when the interface
          comes up.
        type: int
      mtu:
        description:
          - If non-zero, only transmit packets of the specified size or smaller, breaking larger packets up into multiple
            fragments.
          - If zero a default MTU is used. Note that contrary to wg-quick's MTU setting, this does not take into account the
            current routes at the time of activation.
        type: int
      peer-routes:
        description:
          - Whether to automatically add routes for the AllowedIPs ranges of the peers.
          - If V(true) (the default), NetworkManager will automatically add routes in the routing tables according to C(ipv4.route-table)
            and C(ipv6.route-table). Usually you want this automatism enabled.
          - If V(false), no such routes are added automatically. In this case, the user may want to configure static routes
            in C(ipv4.routes) and C(ipv6.routes), respectively.
          - Note that if the peer's AllowedIPs is V(0.0.0.0/0) or V(::/0) and the profile's C(ipv4.never-default) or C(ipv6.never-default)
            setting is enabled, the peer route for this peer will not be added automatically.
        type: bool
      private-key:
        description: The 256 bit private-key in base64 encoding.
        type: str
      private-key-flags:
        description: C(NMSettingSecretFlags) indicating how to handle the O(wireguard.private-key) property.
        type: int
        choices: [0, 1, 2]
  vpn:
    description:
      - Configuration of a VPN connection (PPTP and L2TP).
      - In order to use L2TP you need to be sure that C(network-manager-l2tp) - and C(network-manager-l2tp-gnome) if host
        has UI - are installed on the host.
    type: dict
    version_added: 5.1.0
    suboptions:
      permissions:
        description: User that will have permission to use the connection.
        type: str
        required: true
      service-type:
        description: This defines the service type of connection.
        type: str
        required: true
      gateway:
        description: The gateway to connection. It can be an IP address (for example V(192.0.2.1)) or a FQDN address (for
          example V(vpn.example.com)).
        type: str
        required: true
      password-flags:
        description:
          - NMSettingSecretFlags indicating how to handle the C(vpn.password) property.
          - 'Following choices are allowed: V(0) B(NONE): The system is responsible for providing and storing this secret
            (default); V(1) B(AGENT_OWNED): A user secret agent is responsible for providing and storing this secret; when
            it is required agents will be asked to retrieve it; V(2) B(NOT_SAVED): This secret should not be saved, but should
            be requested from the user each time it is needed; V(4) B(NOT_REQUIRED): In situations where it cannot be automatically
            determined that the secret is required (some VPNs and PPP providers do not require all secrets) this flag indicates
            that the specific secret is not required.'
        type: int
        choices: [0, 1, 2, 4]
        default: 0
      user:
        description: Username provided by VPN administrator.
        type: str
        required: true
      ipsec-enabled:
        description:
          - Enable or disable IPSec tunnel to L2TP host.
          - This option is need when O(vpn.service-type) is V(org.freedesktop.NetworkManager.l2tp).
        type: bool
      ipsec-psk:
        description:
          - The pre-shared key in base64 encoding.
          - "You can encode using this Ansible jinja2 expression: V(\"0s{{ '[YOUR PRE-SHARED KEY]' | ansible.builtin.b64encode }}\")."
          - This is only used when O(vpn.ipsec-enabled=true).
        type: str
  sriov:
    description:
      - Allow to configure SR-IOV settings.
      - 'An up-to-date list of supported attributes can be found here:
        U(https://networkmanager.pages.freedesktop.org/NetworkManager/NetworkManager/settings-sriov.html).'
    type: dict
    version_added: 10.1.0
    suboptions:
      autoprobe-drivers:
        description:
          - Whether to autoprobe virtual functions by a compatible driver.
        type: int
      eswitch-encap-mode:
        description:
          - Select the eswitch encapsulation support.
        type: int
      eswitch-inline-mode:
        description:
          - Select the eswitch inline-mode of the device.
        type: int
      eswitch-mode:
        description:
          - Select the eswitch mode of the device.
        type: int
      total-vfs:
        description: Number of virtual functions to create. Consult your NIC documentation for the maximum number of VFs supported.
        type: int
      vfs:
        description:
          - 'Virtual function descriptors in the form: V(INDEX [ATTR=VALUE[ ATTR=VALUE]...]).'
          - Multiple VFs can be specified using a comma as separator, for example V(2 mac=00:11:22:33:44:55 spoof-check=true,3
            vlans=100).
        type: str
a2  
# These examples are using the following inventory:
#
# ## Directory layout:
#
# |_/inventory/cloud-hosts
# |           /group_vars/openstack-stage.yml
# |           /host_vars/controller-01.openstack.host.com
# |           /host_vars/controller-02.openstack.host.com
# |_/playbook/library/nmcli.py
# |          /playbook-add.yml
# |          /playbook-del.yml
# ```
#
# ## inventory examples
# ### groups_vars
# ```yml
# ---
# #devops_os_define_network
# storage_gw: "192.0.2.254"
# external_gw: "198.51.100.254"
# tenant_gw: "203.0.113.254"
#
# #Team vars
# nmcli_team:
#   - conn_name: tenant
#     ip4: '{{ tenant_ip }}'
#     gw4: '{{ tenant_gw }}'
#   - conn_name: external
#     ip4: '{{ external_ip }}'
#     gw4: '{{ external_gw }}'
#   - conn_name: storage
#     ip4: '{{ storage_ip }}'
#     gw4: '{{ storage_gw }}'
# nmcli_team_slave:
#   - conn_name: em1
#     ifname: em1
#     master: tenant
#   - conn_name: em2
#     ifname: em2
#     master: tenant
#   - conn_name: p2p1
#     ifname: p2p1
#     master: storage
#   - conn_name: p2p2
#     ifname: p2p2
#     master: external
#
# #bond vars
# nmcli_bond:
#   - conn_name: tenant
#     ip4: '{{ tenant_ip }}'
#     gw4: ''
#     mode: balance-rr
#   - conn_name: external
#     ip4: '{{ external_ip }}'
#     gw4: ''
#     mode: balance-rr
#   - conn_name: storage
#     ip4: '{{ storage_ip }}'
#     gw4: '{{ storage_gw }}'
#     mode: balance-rr
# nmcli_bond_slave:
#   - conn_name: em1
#     ifname: em1
#     master: tenant
#   - conn_name: em2
#     ifname: em2
#     master: tenant
#   - conn_name: p2p1
#     ifname: p2p1
#     master: storage
#   - conn_name: p2p2
#     ifname: p2p2
#     master: external
#
# #ethernet vars
# nmcli_ethernet:
#   - conn_name: em1
#     ifname: em1
#     ip4:
#       - '{{ tenant_ip }}'
#       - '{{ second_tenant_ip }}'
#     gw4: '{{ tenant_gw }}'
#   - conn_name: em2
#     ifname: em2
#     ip4: '{{ tenant_ip1 }}'
#     gw4: '{{ tenant_gw }}'
#   - conn_name: p2p1
#     ifname: p2p1
#     ip4: '{{ storage_ip }}'
#     gw4: '{{ storage_gw }}'
#   - conn_name: p2p2
#     ifname: p2p2
#     ip4: '{{ external_ip }}'
#     gw4: '{{ external_gw }}'
# ```
#
# ### host_vars
# ```yml
# ---
# storage_ip: "192.0.2.91/23"
# external_ip: "198.51.100.23/21"
# tenant_ip: "203.0.113.77/23"
# second_tenant_ip: "204.0.113.77/23"
# ```


## playbook-add.yml example

- hosts: openstack-stage
  remote_user: root
  tasks:

    - name: Install needed network manager libs
      ansible.builtin.package:
        name:
          - NetworkManager-libnm
          - nm-connection-editor
          - libsemanage-python
          - policycoreutils-python
        state: present

##### Working with all cloud nodes - Teaming
    - name: Try nmcli add team - conn_name only & ip4 gw4
      community.general.nmcli:
        type: team
        conn_name: '{{ item.conn_name }}'
        ip4: '{{ item.ip4 }}'
        gw4: '{{ item.gw4 }}'
        state: present
      with_items:
        - '{{ nmcli_team }}'

    - name: Try nmcli add teams-slave
      community.general.nmcli:
        type: team-slave
        conn_name: '{{ item.conn_name }}'
        ifname: '{{ item.ifname }}'
        master: '{{ item.master }}'
        state: present
      with_items:
        - '{{ nmcli_team_slave }}'

##### Working with all cloud nodes - Bonding
    - name: Try nmcli add bond - conn_name only & ip4 gw4 mode
      community.general.nmcli:
        type: bond
        conn_name: '{{ item.conn_name }}'
        ip4: '{{ item.ip4 }}'
        gw4: '{{ item.gw4 }}'
        mode: '{{ item.mode }}'
        state: present
      with_items:
        - '{{ nmcli_bond }}'

    - name: Try nmcli add bond-slave
      community.general.nmcli:
        type: bond-slave
        conn_name: '{{ item.conn_name }}'
        ifname: '{{ item.ifname }}'
        master: '{{ item.master }}'
        state: present
      with_items:
        - '{{ nmcli_bond_slave }}'

##### Working with all cloud nodes - Ethernet
    - name: Try nmcli add Ethernet - conn_name only & ip4 gw4
      community.general.nmcli:
        type: ethernet
        conn_name: '{{ item.conn_name }}'
        ip4: '{{ item.ip4 }}'
        gw4: '{{ item.gw4 }}'
        state: present
      with_items:
        - '{{ nmcli_ethernet }}'

## playbook-del.yml example
- hosts: openstack-stage
  remote_user: root
  tasks:

    - name: Try nmcli del team - multiple
      community.general.nmcli:
        conn_name: '{{ item.conn_name }}'
        state: absent
      with_items:
        - conn_name: em1
        - conn_name: em2
        - conn_name: p1p1
        - conn_name: p1p2
        - conn_name: p2p1
        - conn_name: p2p2
        - conn_name: tenant
        - conn_name: storage
        - conn_name: external
        - conn_name: team-em1
        - conn_name: team-em2
        - conn_name: team-p1p1
        - conn_name: team-p1p2
        - conn_name: team-p2p1
        - conn_name: team-p2p2

    - name: Add an Ethernet connection with static IP configuration
      community.general.nmcli:
        conn_name: my-eth1
        ifname: eth1
        type: ethernet
        ip4: 192.0.2.100/24
        gw4: 192.0.2.1
        state: present

    - name: Add an Team connection with static IP configuration
      community.general.nmcli:
        conn_name: my-team1
        ifname: my-team1
        type: team
        ip4: 192.0.2.100/24
        gw4: 192.0.2.1
        state: present
        autoconnect: true

    - name: Optionally, at the same time specify IPv6 addresses for the device
      community.general.nmcli:
        conn_name: my-eth1
        ifname: eth1
        type: ethernet
        ip4: 192.0.2.100/24
        gw4: 192.0.2.1
        ip6: 2001:db8::cafe
        gw6: 2001:db8::1
        state: present

    - name: Add two IPv4 DNS server addresses
      community.general.nmcli:
        conn_name: my-eth1
        type: ethernet
        dns4:
          - 192.0.2.53
          - 198.51.100.53
        state: present

    - name: Make a profile usable for all compatible Ethernet interfaces
      community.general.nmcli:
        ctype: ethernet
        name: my-eth1
        ifname: '*'
        state: present

    - name: Change the property of a setting e.g. MTU
      community.general.nmcli:
        conn_name: my-eth1
        mtu: 9000
        type: ethernet
        state: present

    - name: Change the property of a setting e.g. MTU and reload connection
      community.general.nmcli:
        conn_name: my-eth1
        mtu: 1500
        type: ethernet
        state: present
        conn_reload: true

    - name: Disable connection
      community.general.nmcli:
        conn_name: my-eth1
        state: down

    - name: Reload and enable connection
      community.general.nmcli:
        conn_name: my-eth1
        state: up
        conn_reload: true

    - name: Add second ip4 address
      community.general.nmcli:
        conn_name: my-eth1
        ifname: eth1
        type: ethernet
        ip4:
          - 192.0.2.100/24
          - 192.0.3.100/24
        state: present

    - name: Add second ip6 address
      community.general.nmcli:
        conn_name: my-eth1
        ifname: eth1
        type: ethernet
        ip6:
          - 2001:db8::cafe
          - 2002:db8::cafe
        state: present

    - name: Add VxLan
      community.general.nmcli:
        type: vxlan
        conn_name: vxlan_test1
        vxlan_id: 16
        vxlan_local: 192.168.1.2
        vxlan_remote: 192.168.1.5

    - name: Add gre
      community.general.nmcli:
        type: gre
        conn_name: gre_test1
        ip_tunnel_dev: eth0
        ip_tunnel_local: 192.168.1.2
        ip_tunnel_remote: 192.168.1.5

    - name: Add ipip
      community.general.nmcli:
        type: ipip
        conn_name: ipip_test1
        ip_tunnel_dev: eth0
        ip_tunnel_local: 192.168.1.2
        ip_tunnel_remote: 192.168.1.5

    - name: Add sit
      community.general.nmcli:
        type: sit
        conn_name: sit_test1
        ip_tunnel_dev: eth0
        ip_tunnel_local: 192.168.1.2
        ip_tunnel_remote: 192.168.1.5

    - name: Add zone
      community.general.nmcli:
        type: ethernet
        conn_name: my-eth1
        zone: external
        state: present

# nmcli exits with status 0 if it succeeds and exits with a status greater
# than zero when there is a failure. The following list of status codes may be
# returned:
#
#     - 0 Success - indicates the operation succeeded
#     - 1 Unknown or unspecified error
#     - 2 Invalid user input, wrong nmcli invocation
#     - 3 Timeout expired (see --wait option)
#     - 4 Connection activation failed
#     - 5 Connection deactivation failed
#     - 6 Disconnecting device failed
#     - 7 Connection deletion failed
#     - 8 NetworkManager is not running
#     - 9 nmcli and NetworkManager versions mismatch
#     - 10 Connection, device, or access point does not exist.

- name: Create the wifi connection
  community.general.nmcli:
    type: wifi
    conn_name: Brittany
    ifname: wlp4s0
    ssid: Brittany
    wifi_sec:
      key-mgmt: wpa-psk
      psk: my_password
    autoconnect: true
    state: present

- name: Create a hidden AP mode wifi connection
  community.general.nmcli:
    type: wifi
    conn_name: ChocoMaster
    ifname: wlo1
    ssid: ChocoMaster
    wifi:
      hidden: true
      mode: ap
    autoconnect: true
    state: present

- name: Create a gsm connection
  community.general.nmcli:
    type: gsm
    conn_name: my-gsm-provider
    ifname: cdc-wdm0
    gsm:
      apn: my.provider.apn
      username: my-provider-username
      password: my-provider-password
      pin: my-sim-pin
    autoconnect: true
    state: present

- name: Create a macvlan connection
  community.general.nmcli:
    type: macvlan
    conn_name: my-macvlan-connection
    ifname: mymacvlan0
    macvlan:
      mode: 2
      parent: eth1
    autoconnect: true
    state: present

- name: Create a wireguard connection
  community.general.nmcli:
    type: wireguard
    conn_name: my-wg-provider
    ifname: mywg0
    wireguard:
      listen-port: 51820
      private-key: my-private-key
    autoconnect: true
    state: present

- name: >-
    Create a VPN L2TP connection for ansible_user to connect on vpn.example.com
    authenticating with user 'brittany' and pre-shared key as 'Brittany123'
  community.general.nmcli:
    type: vpn
    conn_name: my-vpn-connection
    vpn:
      permissions: "{{ ansible_user }}"
      service-type: org.freedesktop.NetworkManager.l2tp
      gateway: vpn.example.com
      password-flags: 2
      user: brittany
      ipsec-enabled: true
      ipsec-psk: "0s{{ 'Brittany123' | ansible.builtin.b64encode }}"
    autoconnect: false
    state: present

## Creating bond attached to bridge example
- name: Create bond attached to bridge
  community.general.nmcli:
    type: bond
    conn_name: bond0
    slave_type: bridge
    master: br0
    state: present

- name: Create master bridge
  community.general.nmcli:
    type: bridge
    conn_name: br0
    method4: disabled
    method6: disabled
    state: present

## Creating vlan connection attached to bridge
- name: Create master bridge
  community.general.nmcli:
    type: bridge
    conn_name: br0
    state: present

- name: Create VLAN 5
  community.general.nmcli:
    type: vlan
    conn_name: eth0.5
    slave_type: bridge
    master: br0
    vlandev: eth0
    vlanid: 5
    state: present

## Creating VRF and adding VLAN interface to it
- name: Create VRF
  community.general.nmcli:
    type: vrf
    ifname: vrf10
    table: 10
    state: present
    conn_name: vrf10
    method4: disabled
    method6: disabled

- name: Create VLAN interface inside VRF
  community.general.nmcli:
    conn_name: "eth0.124"
    type: vlan
    vlanid: "124"
    vlandev: "eth0"
    master: "vrf10"
    slave_type: vrf
    state: "present"
    ip4: '192.168.124.50'
    gw4: '192.168.124.1'

## Defining ip rules while setting a static IP
## table 'production' is set with id 200 in this example.
- name: Set Static ips for interface with ip rules and routes
  community.general.nmcli:
    type: ethernet
    conn_name: 'eth0'
    ip4: '192.168.1.50'
    gw4: '192.168.1.1'
    state: present
    routes4_extended:
      - ip: "0.0.0.0/0"
        next_hop: "192.168.1.1"
        table: "production"
    routing_rules4:
      - "priority 0 from 192.168.1.50 table 200"

## Creating an OVS bridge and attaching a port
- name: Create OVS Bridge
  community.general.nmcli:
    conn_name: ovs-br-conn
    ifname: ovs-br
    type: ovs-bridge
    state: present

- name: Create OVS Port for OVS Bridge Interface
  community.general.nmcli:
    conn_name: ovs-br-interface-port-conn
    ifname: ovs-br-interface-port
    master: ovs-br
    type: ovs-port
    state: present

## Adding an ethernet interface to an OVS bridge port
- name: Add Ethernet Interface to OVS Port
  community.general.nmcli:
    conn_name: eno1
    ifname: eno1
    master: ovs-br-interface-port
    slave_type: ovs-port
    type: ethernet
    state: present
z#
)AnsibleModuleto_textNc                       e Zd Zy)NmcliModuleErrorN)__name__
__module____qualname__     k/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/nmcli.pyr
   r
     s    r   r
   c                      e Zd ZdZdZdZdZd Zd Zd*dZ	d Z
d+d	Zed
        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zd Zed        Zed        Zed        Zed        Zd Zd Zd Zd Z d Z!d Z"d Z#d  Z$ed!        Z%d" Z&d# Z'd$ Z(d% Z)d& Z*d' Z+d( Z,d) Z-y),Nmclia  
    This is the generic nmcli manipulation class that is subclassed based on platform.
    A subclass may wish to override the following action methods:-
            - create_connection()
            - delete_connection()
            - edit_connection()
            - modify_connection()
            - show_connection()
            - up_connection()
            - down_connection()
    All subclasses MUST define platform and distribution (which may be None).
    GenericN)z&802-11-wireless-security.leap-passwordz802-11-wireless-security.pskz!802-11-wireless-security.wep-key0z!802-11-wireless-security.wep-key1z!802-11-wireless-security.wep-key2z!802-11-wireless-security.wep-key3c                 T   || _         |j                  d   | _        |j                  d   | _        |j                  d   | _        |j                  d   | _        |j                  d   | _        |j                  d   | _        |j                  d   | _        |j                  d   | _	        |j                  d	   | _
        |j                  d
   | _        |j                  d   | _        |j                  d   | _        |j                  d   | _        |j                  d   | _        |j                  d   | _        |j                  d   | _        |j                  d   | _        |j                  d   | _        |j                  d   | _        |j                  d   | _        |j                  d   | _        |j                  d   | _        |j                  d   | _        |j                  d   | _        |j                  d   | _        |j                  d   | _        |j                  d   | _        |j                  d   | _        |j                  d   | _        |j                  d   | _        |j                  d   | _         |j                  d    | _!        |j                  d!   | _"        |j                  d"   | _#        |j                  d#   | _$        |j                  d$   | _%        |j                  d%   | _&        |j                  d&   | _'        |j                  d'   | _(        |j                  d(   | _)        |j                  d)   | _*        |j                  d*   | _+        |j                  d+   | _,        |j                  d,   | _-        |j                  d-   | _.        |j                  d.   | _/        |j                  d/   | _0        |j                  d0   | _1        |j                  d1   | _2        |j                  d2   | _3        |j                  d3   | _4        |j                  d4   | _5        |j                  d5   | _6        |j                  d6   | _7        |j                  d7   | _8        |j                  d8   | _9        |j                  d9   | _:        |j                  d:   | _;        |j                  d;   | _<        |j                  d<   | _=        |j                  d=   | _>        |j                  d>   | _?        |j                  d?   | _@        |j                  d@   | _A        |j                  dA   | _B        |j                  dB   | _C        |j                  dC   | _D        |j                  dD   | _E        |j                  dE   | _F        |j                  dF   | _G        |j                  dG   | _H        |j                  dH   | _I        | j                   j                  dIdJ      | _K        |j                  dK   | _L        |j                  dL   | _M        |j                  dM   | _N        |j                  dN   | _O        |j                  dO   | _P        |j                  dP   | _Q        |j                  dQ   | _R        |j                  dR   | _S        |j                  dS   | _T        |j                  dT   | _U        |j                  dU   | _V        |j                  dV   | _W        | j.                  r| j.                  | _X        n=| j                  dWv r| j                  sdX| _X        n| j                  rdY| _X        nd | _X        | jF                  r| jF                  | _Y        n=| j                  dWv r| j2                  sdX| _Y        n| j2                  rdY| _Y        nd | _Y        | j                  dZk(  r|j                  d[   | _Z        g | _[        | j                          y )\Nstateignore_unsupported_suboptionsautoconnect	conn_nameconn_reload
slave_typemasterifnametypeip4gw4gw4_ignore_autoroutes4routes4_extendedroute_metric4routing_rules4never_default4dns4dns4_searchdns4_optionsdns4_ignore_automethod4	may_fail4ip6gw6gw6_ignore_autoroutes6routes6_extendedroute_metric6dns6dns6_searchdns6_optionsdns6_ignore_automethod6ip_privacy6addr_gen_mode6mtustpprioritymodemiimonprimary	downdelayupdelayxmit_hash_policyfail_over_macarp_intervalarp_ip_targetslavepriorityforwarddelay	hellotimemaxage
ageingtimehairpin	path_costmacrunnerrunner_hwaddr_policyrunner_fast_ratevlanidvlandevflagsingressegressvxlan_idvxlan_localvxlan_remoteip_tunnel_devip_tunnel_localip_tunnel_remoteip_tunnel_input_keyip_tunnel_output_keynmcliTdhcp_client_idzonessidwifiwifi_secgsmmacvlan	wireguardvpntransport_modeinfiniband_macsriov)dummyrd   re   disabledmanualvrftable)]moduleparamsr   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r\   get_bin_path	nmcli_binr^   r_   r`   ra   rb   rc   rd   re   rf   rg   rh   ri   ipv4_methodipv6_methodrn   edit_commandsextra_options_validation)selfro   s     r   __init__zNmcli.__init__  sT   ]]7+
-3]];Z-[*!==7{3!==7 --5mmH-mmH-MM&)	=='=='%}}->?}}Y/ &.@ A#]]?;$mm,<=$mm,<=MM&)	!==7"MM.9 &.@ A}}Y/{3=='=='%}}->?}}Y/ &.@ A#]]?;MM&)	!==7"MM.9 &.@ A}}Y/!==7$mm,<==='=='j1MM&)	mmH-}}Y/{3}}Y/ &.@ A#]]?;"MM.9#]]?;#]]?;"MM.9{3mmH- --5}}Y/{3=='mmH-$*MM2H$I! &.@ AmmH-}}Y/]]7+
}}Y/mmH-j1!==7"MM.9#]]?;%}}->? &.@ A#)==1F#G $*MM2H$I!11'4@$mm,<=MM&)	MM&)	MM&)	j1=='}}Y/{3=='$mm,<=$mm,<=]]7+
<<#||DYY;;DHH)DXX'D#D<<#||DYY;;DHH)DXX'D#D99w/DJ%%'r   c                     | j                   dvr7| j                  *| j                  | j                  j	                  d       yyyy)zh Additional validation of options set passed to module that cannot be implemented in module's argspecs. )bridge-slave
team-slave
bond-slaveNz;'master' option is required when 'slave_type' is specified.msg)r   r   r   ro   	fail_jsonrw   s    r   rv   zNmcli.extra_options_validation  sG    99HH{{"t'B%%*g%h (C" Ir   c                     t        |t              r|D cg c]  }t        |       }}nt        |      }| j                  j	                  |||      S c c}w )N)use_unsafe_shelldata)
isinstancelistr   ro   run_command)rw   cmdr   r   items        r   execute_commandzNmcli.execute_command%  sO    c4 -01T74=1C1#,C{{&&s=MTX&YY 2s   Ac                 z    |xs g }| j                   ddg|z   }dj                  |      }| j                  ||      S )Nconedit
)r   )rr   joinr   )rw   commands	argumentsr   r   s        r   execute_edit_commandszNmcli.execute_edit_commands,  sD    O	~~uf-	9yy"##Cd#33r   c                    | j                   | j                  d}| j                  r| j                  r| j                  dk(  s| j
                  dk(  r|j                  i d| j                  | j                        d| j                  d| j                  d| j                  d| j                  d	| j                  d
| j                  d| j                  d| j!                  | j"                  | j$                        d| j&                  d| j(                  d| j*                  d| j,                  d| j.                  d| j1                  | j2                        d| j4                  d| j6                  | j8                  | j:                  | j<                  | j>                  | j!                  | j@                  | jB                        | jD                  | jF                  | jH                  | jJ                  d	       | j,                  r,| j,                  dk7  r|j                  d| j.                  i       | jL                  r'|j                  | jN                  | jL                  i       | jP                  r'|j                  | jR                  | jT                  i       | jV                  r(|j                  | j                  | j                  d       | j
                  dk(  rw|j                  | jX                  | jZ                  | j\                  | j^                  | j`                  | jb                  | jd                  | jf                  | jh                  d	       n| j
                  dk(  r| j                  rS| j                  dk7  rD| jj                  jm                  d| j
                  d| j                  d| j
                  d       | j                  s| jj                  jo                  d        |j                  d!di       n| j
                  d"k(  r|j                  | jp                  | jr                  | jt                  | jv                  | jx                  | jz                  d#       | jz                  rp|j                  d$| jx                  i       nQ| j
                  d%k(  rT|j                  | j|                  | j~                  d&       | j                  |j                  d'| j                  i       n| j
                  d(k(  r| j                  rS| j                  d"k7  rD| jj                  jm                  d| j
                  d| j                  d| j
                  d)       | j                  s.| jj                  jo                  d*       |j                  d!d"i       | jj                  jo                  d+       |j                  | j                  | j                  | j                  d,       n| j
                  d-k(  r| j                  rS| j                  d%k7  rD| jj                  jm                  d| j
                  d| j                  d| j
                  d.       | j                  s{| jj                  jo                  d/       |j                  d!d%i       nK| j                  rx|j                  | j                  | j
                  | j                  | j                  d0       | j
                  d1k(  r|j                  | j                  | j                  d2       n| j
                  d3k(  rK|j                  | j                  | j                  | j                  | j                  | j                  d4       nm| j
                  d5k(  r5|j                  | j                  | j                  | j                  d6       n)| j
                  d7k(  r|j                  | j                  | j                  r| j                  dn| j                  nd d8       | j                  r8| j                  j                         D ]  \  }}|j                  d9|z  |i        | j                  r| j                  j                         D ]  \  }}|j                  d:|z  |i        nK| j
                  d;k(  rG| j                  r/| j                  j                         D ]  \  }}|j                  d<|z  |i        n| j
                  d=k(  ra| j                  r:| j                  j                         D ]  \  }}|j                  d>|z  |i        n| j                  d?k(  rt        d@      | j
                  dAk(  rG| j                  ri| j                  j                         D ]  \  }}|j                  dB|z  |i        n/| j
                  dCk(  r| j                  rdD}| j                  j                         D ]  \  }}|dEk(  r|j                  dF|i       nN|dGk(  r|j                  dH|i       n5|dDk7  r|dIz  }t        |t              r| j                  |      }||dJ|z  }|j                  dK|i        nt| j
                  dLk(  r9|j                  dM| j                  i       | j                  r<| j                  |dN<   n,| j
                  dk(  r|j                  dO| j                  i       | j
                  dPk(  rD| j                  r8| j                  j                         D ]  \  }}|j                  dQ|z  |i        |j                         D ]  \  }}| j                  |      }d }|t        u r| j                  }|r9|dRv rt        }nB|| jR                  k(  r| j                  }n&|dSk(  r!| j                  }n|t        u r| j                  }t        |      s ||      ||<    |S )TN)connection.autoconnectzconnection.zonerm   ovs-interfaceipv4.addresseszipv4.dhcp-client-idipv4.dnsipv4.dns-searchipv4.dns-optionsipv4.ignore-auto-dnszipv4.gatewayipv4.ignore-auto-routesipv4.routeszipv4.route-metricipv4.routing-rulesipv4.never-defaultzipv4.methodipv4.may-failipv6.addressesipv6.dnsipv6.dns-search)	ipv6.dns-optionsipv6.ignore-auto-dnszipv6.gatewayipv6.ignore-auto-routesipv6.routeszipv6.route-metriczipv6.methodipv6.ip6-privacyzipv6.addr-gen-moderk   )zconnection.masterconnection.slave-typebond)	zarp-intervalzarp-ip-targetr?   r=   r<   r>   r@   rA   rB   r|   zConnection type 'z' cannot be combined with 'z&' slave-type. Allowed slave-type for 'z' is 'bond'.r}   zkConnection 'slave-type' property automatically set to 'bond' because of using 'bond-slave' connection type.r   bridge)zbridge.ageing-timezbridge.forward-delayzbridge.hello-timezbridge.max-agebridge.priority
bridge.stpr   team)zteam.runnerzteam.runner-hwaddr-policyteam.runner-fast-raterz   z' is 'bridge'.zoConnection 'slave-type' property automatically set to 'bridge' because of using 'bridge-slave' connection type.zConnection type as 'bridge-slave' implies 'ethernet' connection with 'bridge' slave-type. Consider using slave_type='bridge' with necessary type.)zbridge-port.path-costbridge-port.hairpin-modezbridge-port.priorityr{   z' is 'team'.zkConnection 'slave-type' property automatically set to 'team' because of using 'team-slave' connection type.)zip-tunnel.localzip-tunnel.modezip-tunnel.parentzip-tunnel.remotegre)zip-tunnel.input-keyzip-tunnel.output-keyvlan)vlan.idzvlan.parentz
vlan.flagszvlan.ingresszvlan.egressvxlan)vxlan.idzvxlan.localzvxlan.remotera   )z802-11-wireless.ssidr   z802-11-wireless.%sz802-11-wireless-security.%src   zgsm.%srd   z
macvlan.%spresentz=type is macvlan but all of the following are missing: macvlanre   zwireguard.%srf    zservice-typezvpn.service-typepermissionszconnection.permissionsz, =vpn.data
infinibandzinfiniband.transport-modezinfiniband.mac-addressrn   ethernetzsriov.%s)r   r   r   )jr   r_   ip_conn_typer   r   r   updateenforce_ipv4_cidr_notationr   r^   r&   r'   r(   r)   r   r    enforce_routes_formatr!   r"   r#   r$   r%   rs   r+   enforce_ipv6_cidr_notationr,   r2   r3   r4   r5   r-   r.   r/   r0   r1   rt   r7   r8   rL   mac_settingmtu_conn_typemtu_settingr9   slave_conn_typerC   rD   r?   r=   r<   r>   r@   rA   rB   ro   r   warnrI   rF   rG   rH   r;   r:   rM   rN   rO   rK   rJ   rE   tunnel_conn_typerY   rX   rZ   r[   r\   rP   rQ   rR   rS   rT   rU   rV   rW   r`   ra   itemsrb   rc   rd   r   r
   re   rf   r   boolbool_to_stringrg   rh   rn   ri   settings_typer   mtu_to_stringip6_privacy_to_numr   list_to_stringcallable)	rw   detect_changeoptionsnamevaluevpn_data_valuessettingsetting_typeconvert_funcs	            r   connection_optionszNmcli.connection_options2  s
    '+&6&6#yy
 t{{doo6NTXT]T]apTpNN  $"A"A$(("K%t':': DII "4#3#3	
 #D$5$5 '(=(=  *4+?+? t99$,,H]H]^ $T%7%7 %d&9&9 %d&9&9 t//   !$"A"A$(("K  DII!" "4#3#3#$ %)$5$5(,(=(= $+/+?+?#99$,,H]H]^%)%7%7#//$($4$4&*&9&95 < D$4$4
$B@A 88NND,,dhh78NND,,dhh78 NN%)[[)-  99NN $ 1 1!%!3!3!^^++		<<<<$($9$9!%!3!3
 
 YY,&4??f#<%%-1YY+T% ( ??   "R S+V   YY("NN&*oo(,(9(9%)^^"&++#'=="hh  xx 14==ABYY& NN#{{-1-F-F  $$0+T-B-B   YY.(4??h#>%%-1YY+T% ( ??   "T U 7BCKKJ NN)-,0LL(,(:(: 
 YY,&4??f#<%%-1YY+T% ( ??   "R S+V   ""NN#'#7#7"&))$($6$6$($9$9	  yyE!+/+C+C,0,E,E   YY& NN;;#||"jj $#{{  YY'!NN MM#// $ 1 1 
 YY& NN(,		eiepepDOO4K&QUQ`Q`vz  yy#'99??#4 KD%NN,t3U$  }}#'==#6#6#8 KD%NN5<e$  YY%xx#'88>>#3 KD%NN 4$  YY)#||#'<<#5#5#7 KD%NN$t+U$  y(&'fggYY+%~~#'>>#7#7#9 KD%NN&-u$  YY%xx"$#'88>>#3 KD%~-.(  .4e(  +b0+t3O%eT2$($7$7$>E'dE+BBNN"O$ #( YY,&NN+T-@-@  ""484G4G01YY%NN  99
"zz#'::#3#3#5 KD%NN"T)5$  &mmo 	7NGU--g6LLt##2255#*L 0 00#'#5#5L 22#'#:#:L%#22%#/#6 )	7, r   c                     | j                   dv S )N)r   r   rj   r   z802-3-ethernetgenericr   r   ipipsitr   r   ra   802-11-wirelessrc   rd   re   rf   loopbackr   rm   r   r   s    r   r   zNmcli.ip_conn_type9  s    yy 
 
 	
r   c                 $    | j                   dk(  ryy)Nr   zbridge.mac-addressz!802-3-ethernet.cloned-mac-addressr   r   s    r   r   zNmcli.mac_settingS  s    99 '6r   c                     | j                   dv S )N)r   r|   rj   r   r   r{   r   r   r   s    r   r   zNmcli.mtu_conn_typeZ  s    yy 
 
 	
r   c                 $    | j                   dk(  ryy)Nr   zinfiniband.mtuz802-3-ethernet.mtur   r   s    r   r   zNmcli.mtu_settingf  s    99$#'r   c                     | syt        |       S )Nautor   )r9   s    r   r   zNmcli.mtu_to_stringm  s    3<r   c                 ^    ddddd}| y | |vrt        dj                  |             ||    S )N0z1 (enabled, prefer public IP)z 2 (enabled, prefer temporary IP)z-1rk   zprefer-public-addrzprefer-temp-addrunknownz'{privacy} is invalid ip_privacy6 option)privacy)AssertionErrorformat)r   ip6_privacy_valuess     r   r   zNmcli.ip6_privacy_to_numt  sQ     "A B	
 ?,, !J!Q!QZa!Q!bcc!'**r   c                     | j                   dv S )N)r   r   r   r   r   ra   r|   rz   r{   ra   r   ovs-portr   r   r   s    r   r   zNmcli.slave_conn_type  s    yy 
 
 	
r   c                     | j                   dv S )N)r   r   r   r   r   s    r   r   zNmcli.tunnel_conn_type  s    yy 
 
 	
r   c                 D    | y | D cg c]  }d|v r|n|dz    c}S c c}w )N/z/32r   )ip4_addressesaddresss     r   r   z Nmcli.enforce_ipv4_cidr_notation  s.     N[\73'>w>\\\   c                 D    | y | D cg c]  }d|v r|n|dz    c}S c c}w )Nr   z/128r   )ip6_addressesr   s     r   r   z Nmcli.enforce_ipv6_cidr_notation  s/     O\]G3'>w/??]]]r   c                 X    ||S ||D cg c]  }| j                  |       c}S y c c}w N)route_to_string)rw   routesroutes_extendedroutes       r   r   zNmcli.enforce_routes_format  s8    M(=LMED((/MM Ns   'c                 F   d}|| d   z  }| j                  d      |d| d   z   z  }| j                  d      |dt        | d         z   z  }t        | j                               D ]9  \  }}|dvs||dj	                  |t        |      j                               z  }; |S )Nr   ipnext_hop metric)r   r   r   z {0}={1})getstrsortedr   r   lower)r   
result_str	attributer   s       r   r   zNmcli.route_to_string  s    
eDk!
99Z ,#j 111J99X*#E(O 444J &u{{} 5 	OIu <<ARj//	3u:;K;K;MNN
	O r   c                 
    | ryy)Nyesnor   )booleans    r   r   zNmcli.bool_to_string  s    r   c                 *    | y dj                  |       S )N,)r   )lsts    r   r   zNmcli.list_to_string  s    ;88C= r   c                 6    | dv rt         S | dv rt        S t        S )N)r   r   r   r   r   r   r   r   r   z802-11-wireless.hiddenr   )r   r   r   r   r   r   r   r   r   r   r   z802-11-wireless-security.groupz,802-11-wireless-security.leap-password-flagsz!802-11-wireless-security.pairwisez802-11-wireless-security.protoz"802-11-wireless-security.psk-flagsz&802-11-wireless-security.wep-key-flagsz%802-11-wireless.mac-address-blacklist)r   r   r  )r   s    r   r   zNmcli.settings_type  s1     
0 
0 K B B$ K
r   c                     g }|D ]N  }i }t        j                  d|      D ]   \  }}|dk(  r||d<   |dk(  r||d<   |||<   " |j                  |       P |D cg c]  }| j                  |       c}S c c}w )Nz([\w-]*)\s?=\s?([^\s,}]*)nhr   mtr   )refindallappendr   )rw   
raw_valuesroutes_params	raw_valueroute_params	parameterr   s          r   get_route_paramszNmcli.get_route_params  s    # 		/IL$&JJ/KY$W 4 	5$/4L,$&-2L*.3L+4   .		/ HUU|$$\2UUUs   A5c                     | j                   dddddg}| j                  |      \  }}}|dk7  rt        |      |j                         S )Nz--fieldsr   z--terser   showr   )rr   r   r
   
splitlines)rw   r   rcouterrs        r   list_connection_infozNmcli.list_connection_info	  sM    ~~z69eVL--c2S#7"3''~~r   c                 :    | j                   | j                         v S r   )r   r   r   s    r   connection_existszNmcli.connection_exists	  s    ~~!:!:!<<<r   c                 X    | j                   dd| j                  g}| j                  |      S )Nr   downrr   r   r   rw   r   s     r   down_connectionzNmcli.down_connection	  s)    ~~ufdnn=##C((r   c                 X    | j                   dd| j                  g}| j                  |      S )Nr   upr%  r&  s     r   up_connectionzNmcli.up_connection	  s)    ~~udDNN;##C((r   c                 B    | j                   ddg}| j                  |      S )Nr   reload)rr   r   r&  s     r   reload_connectionzNmcli.reload_connection	  s#    ~~uh/##C((r   c                 t   |dk(  r[| j                   dddg}| j                  r|j                  d       n|j                  | j                         |j                  d       n1|dk(  r| j                   ddg}n| j                  j                  d	       j                  | j                         |dk(  r| j                  | j                  }n| j                  }d
|i}| j                  dk(  r| j                  |d
= |j                  | j                                |j                         D ]~  \  }}|	|| j                  v r| xj                  d|d|gz  c_        4|dk(  r|j                  dd|z  g       P|dk(  r|j                  dd|z  g       l|j                  ||g        | j                  |      S )Ncreater   addr   z	ip-tunnelzcon-namemodifyzInvalid nmcli command.r}   connection.interface-namerf   set r   rA   z+bond.optionszxmit_hash_policy=%srB   zfail_over_mac=%s)rr   r   r  r   ro   r   r   r   r   r   r   SECRET_OPTIONSru   extendr   )rw   nmcli_commandr   r   r   keyr   s          r   connection_updatezNmcli.connection_update	  s   H$>>5%8C$$

;'

499%JJz"h&>>5(3CKK!!&>!?

4>>" H$)<^^F[[F (

 99$++"534t..01 "--/ 	)JC $---&&#u+E*FF&,,JJ1F1NOP/)JJ1Ce1KLM

C<(	) ##C((r   c                     | j                  d      }|d   dk(  r| j                  r| j                         }| j                  r| j	                         }|S )Nr/  r   )r8  ru   edit_connectioncreate_connection_upr*  rw   statuss     r   create_connectionzNmcli.create_connectionE	  sO    ''1!9>d00))+F$$'')Fr   c                     | j                   dv r&| j                  | j                  | j                  yy| j                   dk(  r| j                  | j                  yy)N)r   rj   r   r   ra   Tr   F)r   r9   r&   r2   r   s    r   r;  zNmcli.create_connection_upM	  sZ    99KK$$))*?TYYEZ  YY& 		%499+@r   c                 X    | j                   dd| j                  g}| j                  |      S )Nr   delr%  r&  s     r   remove_connectionzNmcli.remove_connectionW	  s)    ~~ueT^^<##C((r   c                 p    | j                  d      }|d   dk(  r| j                  r| j                         }|S )Nr1  r   )r8  ru   r:  r<  s     r   modify_connectionzNmcli.modify_connection\	  s8    ''1!9>d00))+Fr   c                 `    | j                   ddgz   }| j                  || j                  g      S )Nsavequitr   )ru   r   r   )rw   r   s     r   r:  zNmcli.edit_connectionb	  s4    %%(88))(t~~>N)OOr   c                    | j                   ddd| j                  g}| j                  |      \  }}}|dk7  rt        |      t	        j
                  d      }t               }|j                         D ]b  }|j                  dd      }|d   j                         }	| j                  |	      }
|	s=t        |      dkD  sL|d   j                         }|dk(  r|
t        k(  rg ||	<   sd ||	<   y|	d	k(  rI|j                  d
      }|D ]2  }|j                  dd      }t        |      dkD  s$|d   }|d   }|||<   4 |	dv r1|j                  d      D cg c]  }|j                          c}||	<   |
t        k(  r2|j                  d
      D cg c]  }|j                          c}||	<   7|j                  |      }||j                  d      }n|}|||	<   e |S c c}w c c}w )Nz--show-secretsr   r  r   z^([-]?\d+) \((\w+)\)$:   z--zbond.optionsr  r   r   r   ;)rr   r   r   r
   r  compiledictr  splitstripr   lenlstripr   matchgroup)rw   r   r  r  r  p_enum_value	conn_infolinepairr7  key_typer  optsopt
alias_pair	alias_keyalias_valuesm_enumr   s                       r   show_connectionzNmcli.show_connectionf	  s   ~~/O--c2S#7"3''zz":;F	NN$ 	+D::c1%Dq'--/C))#.Hs4y1} GNN,	$4')+	#)-	#N*$??3/D# ?%(YYsA%6
z?Q.(21I*4Q-K3>Ii0? ::9B9M%NAaggi%NIcN%9B9M%NAaggi%NIcN)//	:F) &Q )%*IcN=	+@  &O%Ns   GGc                    g }|dk(  rd}d}d|d|d|g}ng }|d|z  dd	gz  }| j                  |d
| j                  g      \  }}}|dk7  rt        |      |j                         D ]_  }	d|z  }
|	j	                  |
      s|	j                  dd      }|d   j                         j                  |
d      }|j                  |       a |S )N802-11-wireless-securitypsk	FAKEVALUEr3  .r   zprint %srG  r  r   rH  r   z%s.rJ  rK  r   )	r   r   r
   r  
startswithrP  rQ  replacer  )rw   r   
propertiesset_property	set_valuer   r  r  r  rX  prefixrY  propertys                r   get_supported_propertieszNmcli.get_supported_properties	  s    
00 L#I*1<KLHHZ')659933HQUQZQZH[3\S#7"3''NN$ 	,DW_F'zz#q)7==?2262>!!(+	, r   c                    |dk(  rd}n
|dk(  rd}n|}| j                  |      }g }t        | |      j                         D ]  \  }}||vs|j                  |        |rxg }|D ]  }|j                  |d|        ddj	                  |      z  }| j
                  r| j                  j                  |       |S | j                  j                  |       |S )	Nr   ra   rd  rb   rg  z&Invalid or unsupported option(s): "%s"z", "r}   )	ro  getattrr   r  r   r   ro   r   r   )	rw   r   setting_keysupported_propertiesunsupported_propertiesrn  r   msg_optionsr~   s	            r    check_for_unsupported_propertiesz&Nmcli.check_for_unsupported_properties	  s    '' K22$K!K#<<WE!#&t[9??A 	8OHe33&--h7	8 "K2 F""k8#DEF ;V[[=UUC11  % &% %%#%.%%r   c           	          d}t               }t               }|j                         D ]  \  }}|dg fvr|s||v r||   }|dk(  r>|<t        j                  d|      }	|	r$t	        t        |	j                  d      d            }|dv r|| j                  |      }|| j                  k(  r"|j                         }|r|j                         }|dk(  r|r|j                  d	      }|| j                  k(  r| j                  d| _        |d
k(  rG|r!t        d |j                  d      D              }t        d |j                  d      D              }nd }t        |t               r8t        |t               r(|dv r	|||k7  z  }nk|t        |      t        |      k7  z  }nPt#        || j                  k(  | j$                  dk(  |d u |dk(  | j                  d u g      rd }nt'        |      }||k7  rd}|||<   |||<    ||d}
||
fS )NFr   z802-11-wireless.wake-on-wlanz0x([0-9A-Fa-f]+)rK     rL  zgsm.apn"r   c              3   j   K   | ]+  }t        j                  d d|j                         d       - yw)z\s*=\s*r   rK  )countN)r  subrQ  .0parts     r   	<genexpr>z-Nmcli._compare_conn_params.<locals>.<genexpr>	  s0       /Dbfrvvj#tzz|[\/]/]  /Ds   13r  c              3   <   K   | ]  }|j                           y wr   )rQ  r}  s     r   r  z-Nmcli._compare_conn_params.<locals>.<genexpr>	  s     "MD4::<"Ms   )r   r   r   r   r   r   rj   r   T)beforeafter)rO  r   r  rT  r  intrU  r  r   upperrQ  r   r9   r  rP  r   r   allr   r   )rw   rW  r   changeddiff_before
diff_afterr7  r   current_valuerT  diffs              r   _compare_conn_paramszNmcli._compare_conn_params	  s:   fV
!--/ 6	$JC QG#Ei )#88]=VHH%7GE(+CA,C(D88]=V$($9$9-$HM$***!KKME$(5(;(;(=)# %(5(;(;C(@$***txx/? DH*$$(.  /Djwj}j}  B  kC  /D  )D""MEKK<L"MME !%-.:eT3J||
 }55Gvm4uEEGcT---tyyG/C]VZEZ\aek\kmqmumuy}m}~ E)"G,K#JsOm6	$r "
 r   c                 R   d| j                   i}| j                  dk(  r| j                   |d= | j                  s/| j                         j                  d      }|r|dk(  rd}|| _        |j	                  | j                  d             | j                  | j                         |      S )Nr2  rf   zconnection.typer   ra   T)r   )r   r   rb  r   r   r   r  )rw   r   current_con_types      r   is_connection_changedzNmcli.is_connection_changed
  s    '

 99$++"534yy#33599:KL#'88'-$,	t..T.BC(()=)=)?IIr   )FN)F).r   r   r   __doc__platformdistributionr4  rx   rv   r   r   r   rn  r   r   r   r   staticmethodr   r   r   r   r   r   r   r   r   r   r   r  r   r"  r'  r*  r-  r8  r>  r;  rB  rD  r:  rb  ro  rv  r  r  r   r   r   r   r     s    HLNo(biZ4EN 
 
2 7 7 	
 	
 ( (     + +  
 
" 
 
 ] ]
 ^ ^
     ! !    DV =))),)\  )
P+Z4&8AFJr   r   c                     t        t        di dt        dd      dt        dd      dt        ddg d	
      dt        dd      dt        dd      dt        d      dt        dg d      dt        d      dt        dg d      dt        dd      dt        d      dt        dd      dt        dd      dt        ddt        t        dd      t        d      t        d      t        d      t        d      t        d      t        d      t        d                   d!t        d      d"t        dd      d#t        dd      d$t        dd      d%t        dd      d&t        dd      d't        dd      d(t        dg d)      d*t        dd      d+t        d      d,t        dd      d-t        d      d.t        dd      d/t        dd      d0t        dd      d1t        dd      d2t        dd      d3t        dd      d4t        ddt        t        dd      t        d      t        d      t        d      t        d      t        d      t        d      5             d6t        d      d7t        dg d8      d9t        dg d:      d;t        dg d<      d=t        dd>g d?@      dAt        d      dBt        d      dCt        d      dDt        d      dEt        dg dF      dGt        d      dHt        d      dIt        d      dJt        d      dKt        d      dLt        d      dMt        dd      dNt        ddO      dPt        ddQ      dRt        ddS      dTt        ddU      dVt        ddW      dXt        ddY      dZt        dd      d[t        dd\      d]t        dd^g d_@      d`t        dg da      dbt        d      dct        d      ddt        d      det        d      dft        d      dgt        d      dht        d      dit        d      djt        d      dkt        d      dlt        d      dmt        d      dnt        ddo      dpt        ddo      dqt        d      drt        d      dst        ddo      dtt        d      dut        dt        t        dg dvdw      t        dd      t        d      t        d      x      y      dzt        d      d{t        d      d|t        d      d}t        d      d~t        dddg      dt        d      d#dgddgd4d3ggddrdqgfgd      } t        dddd      | _        t        |       }d\  }}}|j                  |j
                  d}|j                  |j                  j                  d       |j                  dk(  rn|j                  r+|j                  dk(  s|j                  j                  d       |j                  +|j                  dk7  r|j                  j                  d       |j                  dk(  s|j                  dk(  rj|j                  )|j                  j                  d|j                  z         |j                  )|j                  j                  d|j                  z         |j                  drk(  ri }|j                  r@dq|j                  v r| j!                  d       |j                  dq= |j#                  d      |dr<   |j$                  r|j#                  d      |ds<   |j&                  r.|r,|j)                         D ]  \  }}|D ]  }	t+        ||      |	=   	 |j
                  dk(  r|j-                         r| j.                  r| j1                  d       |j3                         \  }}}|j5                         \  }}}|dk7  r| j                  d|j                  z  ||       n|j
                  dk(  rB|j-                         r|j7                         \  }
}| j8                  r||d<   |
rZd|d<   | j.                  r | j0                  dddi| |j;                         \  }}}|j<                  r:|j?                         \  }}}n%d|d<   | j.                  r | j0                  dddi| |j-                         sTd|j                  d|j                  d|d<   | j.                  r | j0                  dddi| |jA                         \  }}}|V|dk7  rP| j                  |j                  ||       n0|j
                  dk(  r|j-                         r| j.                  r| j1                  d       |j<                  r|j?                         \  }}}|jC                         \  }}}|dk7  r| j                  d|j                  z  ||       n|j
                  dk(  r|j-                         rx| j.                  r| j1                  d       |j<                  r|j?                         \  }}}|j3                         \  }}}|dk7  r!| j                  d|j                  z  ||       |d|d<   nd|d<   |r||d<   |r||d<    | j0                  di | y # tD        $ r0}| j                  |j                  tG        |             Y d }~bd }~ww xY w)Nr   r   F)r   defaultr   Tr   r  )absentr   r)  r$  )r   requiredchoicesr   )r   r  r   r   r   r   )r   r   r   r   rm   )r   r  r   r   )r   r|   r   rz   rj   r   r   r   r   r   r   r   r{   r   r   ra   rc   rd   re   rf   r   r   z
ovs-bridger   rm   r   r   )r   elementsr   r    r!   r"   rO  r  )r   r   r   rn   toscwndr9   onlink)r   r  r   r#   r$   r%   r&   r'   r(   r)   r*   )r   
link-localrl   sharedrk   r+   r^   r,   r-   r.   r2   r3   r4   r5   r/   r0   )r   r   r   rn   r  r9   r  r1   r6   )ignorer   dhcpr  rl   r  rk   r7   r   r8   )r  zdefault-or-eui64eui64zstable-privacyr<   
balance-rr)z802.3adzactive-backupzbalance-albr  zbalance-tlbzbalance-xor	broadcast)r   r  r  r=   r?   r@   rA   rB   )noneactivefollowrC   rD   r>   r9   rL   r_   r:   r;      rE       rF      rG      rH      rI   i,  rJ   rK   d   rM   
roundrobin)r  r  activebackuploadbalancelacprN   )same_all	by_activeonly_activerO   rP   rQ   rR   rS   rT   rU   rV   rW   rX   rY   rZ   r[   )r   no_logr\   r`   ra   rb   rc   rd   )rK  r           )r   r  r  )r<   parentpromiscuoustap)r   r   re   rf   ri   rn   rg   datagram	connectedrh   )argument_specmutually_exclusiverequired_ifsupports_check_modeC)LANGLC_ALLLC_MESSAGESLC_CTYPE)Nr   r   )r   r   z(Please specify a name for the connectionr}   r   r  z<Runner-hwaddr-policy is only allowed for runner activebackupr  z0runner-fast-rate is only allowed for runner lacpr{   z4Please specify a name for the master when type is %szCPlease specify an interface name for the connection when type is %szDIgnoring option 'wifi.ssid', it must be specified with option 'ssid'r   rd  r  )r  r   zNo Connection named %s exists)r   r~   r  r   r  z-Connections do exist so we are modifying themExistsr  z-Connections already exist and no changes madezConnection z	 of Type z is being added
Connectionr)  r$  )r   r~   stdoutstderrr   )$r   rO  run_command_environ_updater   r   r   ro   r   r   rN   rM   rO   r   r   r   ra   r   rv  rb   r   r   rq  r"  
check_mode	exit_jsonr'  rB  r  _diffrD  r   r-  r>  r*  r
   r  )ro   r]   r  r  r  resultrt  rr  rj  rn  r  r  es                r   mainr   
  s    Y
*.FE*JY
&$7Y
 ED:]^Y
 5	Y

 &%8Y
 U#Y
 0]^Y
 U#Y
 5Y
J &51KY
L % MY
N !fe<OY
P fu5QY
R "v+1*.)-54)H/3/?-1u-=,0e,<*.E*:+/U+;*.E*:-1v->	+$%SY
j E*kY
l  Ve<mY
n  VU;oY
p 6E2qY
r &59sY
t 6E:uY
v "vu=wY
x e-cdyY
z 5{Y
|  U+}Y
~ &51Y
@ % AY
B !fe<CY
D 6E2EY
F &59GY
H 6E:IY
J "vu=KY
L fu5MY
N "v+1*.)-54)H/3/?-1u-=,0e,<+/U+;*.E*:-1v->+$
%OY
d E*eY
f e-uvgY
h %1rsiY
j  U4nokY
n 5, CDoY
r U#sY
t &uY
v e$wY
x "u-yY
z E3OP{Y
| 5)}Y
~ E*Y
@ e$AY
D % EY
F % GY
H 5!IY
L &$/MY
N uc2OY
P E26QY
R 5"5SY
T q1UY
V UB/WY
X 4YY
Z fe4[Y
\ s3]Y
` UL%giaY
f "&5:b!cgY
j "v.kY
n U#oY
p e$qY
r E"sY
t e$uY
v U#wY
z u%{Y
| %(}Y
~ 5)Y
B E*CY
D !e,EY
F "u-GY
J !%% =KY
L "&5!>MY
P 5!QY
R 6"SY
T vd3UY
V &!WY
X fd#'UOVZ#[%)ut%D*.F*;"&F"3	/5 6YY
b 'cY
d &!eY
f F#gY
h E"iY
l  UZ4MNmY
n  U+oY
t .u5/;/;= fj12 `FB )-#cs]`(aF%&ME#NRc ??U[[AF #MNzzV%%elln.LLL""'e"f!!-%,,&2HLL""'Y"Zzz\!U%5%5%?<<LL""']`e`j`j'j"k<<LL""'lotoyoy'y"zzzV!#::#bcJJv&-2-S-STe-f"6*>>161W1WXr1s":...3I+A+G+G+I >'Z * >H{3H=>>:;;;("&&($$$$T$2!&!6!6!8S#!&!8!8!:S#7$$+JU__+\cfkm$n[[I%&&( % ; ; =<<%)F6N (WF8$(((((@@@%*%<%<%>NRc(().)@)@)BS#'VF8$(((((AA&A**,UZUdUdfkfpfp(q|$$$$F$$<T<V<!&!8!8!:S#~"'  eoo32 F[[D &&($$$$T$2$$%*%<%<%>NRc!&!4!4!6S#7$$+JU__+\cfkm$n[[F"&&($$$$T$2$$%*%<%<%>NRc!&!6!6!8S#7$$+JU__+\cfkm$n
 
z!y y
x
xFv  ;eoo3q6::;s   Ll 	m!&mm__main__)
__future__r   r   r   r   __metaclass__DOCUMENTATIONEXAMPLESRETURNansible.module_utils.basicr   +ansible.module_utils.common.text.convertersr   r  	Exceptionr
   objectr   r  r   r   r   r   <module>r     so    A @l\#L\
 5 ? 		y 	IJF IJXL^ zF r   