2020-03-09 10:11:07 +01:00
|
|
|
#!/usr/bin/python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2022-08-05 12:28:29 +02:00
|
|
|
# Copyright (c) 2015, Chris Long <alcamie@gmail.com> <chlong@redhat.com>
|
|
|
|
# Copyright (c) 2017, Ansible Project
|
|
|
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
2020-03-09 10:11:07 +01:00
|
|
|
|
|
|
|
from __future__ import absolute_import, division, print_function
|
|
|
|
__metaclass__ = type
|
|
|
|
|
|
|
|
DOCUMENTATION = r'''
|
|
|
|
---
|
|
|
|
module: nmcli
|
|
|
|
author:
|
2023-02-20 17:28:47 +01:00
|
|
|
- Chris Long (@alcamie101)
|
2020-03-09 10:11:07 +01:00
|
|
|
short_description: Manage Networking
|
|
|
|
requirements:
|
2023-02-20 17:28:47 +01:00
|
|
|
- nmcli
|
|
|
|
extends_documentation_fragment:
|
|
|
|
- community.general.attributes
|
2020-03-09 10:11:07 +01:00
|
|
|
description:
|
2020-10-23 07:13:39 +02:00
|
|
|
- 'Manage the network devices. Create, modify and manage various connection and device type e.g., ethernet, teams, bonds, vlans etc.'
|
|
|
|
- '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.'
|
2023-02-20 17:28:47 +01:00
|
|
|
attributes:
|
|
|
|
check_mode:
|
|
|
|
support: full
|
|
|
|
diff_mode:
|
|
|
|
support: full
|
2020-03-09 10:11:07 +01:00
|
|
|
options:
|
|
|
|
state:
|
|
|
|
description:
|
|
|
|
- Whether the device should exist or not, taking action if the state is different from what is stated.
|
|
|
|
type: str
|
|
|
|
required: true
|
|
|
|
choices: [ absent, present ]
|
|
|
|
autoconnect:
|
|
|
|
description:
|
|
|
|
- Whether the connection should start on boot.
|
|
|
|
- Whether the connection profile can be automatically activated
|
|
|
|
type: bool
|
2022-08-24 20:00:11 +02:00
|
|
|
default: true
|
2020-03-09 10:11:07 +01:00
|
|
|
conn_name:
|
|
|
|
description:
|
|
|
|
- The name used to call the connection. Pattern is <type>[-<ifname>][-<num>].
|
|
|
|
type: str
|
|
|
|
required: true
|
|
|
|
ifname:
|
|
|
|
description:
|
|
|
|
- The interface to bind the connection to.
|
|
|
|
- The connection will only be applicable to this interface name.
|
2023-06-15 15:47:40 +02:00
|
|
|
- A special value of V('*') can be used for interface-independent connections.
|
2022-06-06 21:16:27 +02:00
|
|
|
- The ifname argument is mandatory for all connection types except bond, team, bridge, vlan and vpn.
|
2023-06-15 15:47:40 +02:00
|
|
|
- This parameter defaults to O(conn_name) when left unset for all connection types except vpn that removes it.
|
2020-03-09 10:11:07 +01:00
|
|
|
type: str
|
|
|
|
type:
|
|
|
|
description:
|
|
|
|
- This is the type of device or network connection that you wish to create or modify.
|
2023-06-15 15:47:40 +02:00
|
|
|
- Type V(dummy) is added in community.general 3.5.0.
|
|
|
|
- Type V(gsm) is added in community.general 3.7.0.
|
2023-11-23 06:18:57 +01:00
|
|
|
- Type V(infiniband) is added in community.general 2.0.0.
|
2023-11-22 09:26:04 +01:00
|
|
|
- Type V(loopback) is added in community.general 8.1.0.
|
2023-06-15 15:47:40 +02:00
|
|
|
- Type V(macvlan) is added in community.general 6.6.0.
|
2024-04-09 08:01:00 +02:00
|
|
|
- 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.
|
2023-06-15 15:47:40 +02:00
|
|
|
- Type V(wireguard) is added in community.general 4.3.0.
|
|
|
|
- Type V(vpn) is added in community.general 5.1.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.
|
2020-03-09 10:11:07 +01:00
|
|
|
type: str
|
2023-04-16 13:22:11 +02:00
|
|
|
choices: [ bond, bond-slave, bridge, bridge-slave, dummy, ethernet, generic, gre, infiniband, ipip, macvlan, sit, team, team-slave, vlan, vxlan,
|
2024-04-09 08:01:00 +02:00
|
|
|
wifi, gsm, wireguard, ovs-bridge, ovs-port, ovs-interface, vpn, loopback ]
|
2020-03-09 10:11:07 +01:00
|
|
|
mode:
|
|
|
|
description:
|
2021-07-14 08:24:27 +02:00
|
|
|
- This is the type of device or network connection that you wish to create for a bond or bridge.
|
2020-03-09 10:11:07 +01:00
|
|
|
type: str
|
|
|
|
choices: [ 802.3ad, active-backup, balance-alb, balance-rr, balance-tlb, balance-xor, broadcast ]
|
|
|
|
default: balance-rr
|
2022-10-23 11:30:48 +02:00
|
|
|
transport_mode:
|
|
|
|
description:
|
|
|
|
- This option sets the connection type of Infiniband IPoIB devices.
|
|
|
|
type: str
|
|
|
|
choices: [ datagram, connected ]
|
|
|
|
version_added: 5.8.0
|
2023-05-08 19:44:30 +02:00
|
|
|
slave_type:
|
|
|
|
description:
|
2023-06-15 15:47:40 +02:00
|
|
|
- Type of the device of this slave's master connection (for example V(bond)).
|
2024-04-09 08:01:00 +02:00
|
|
|
- Type V(ovs-port) is added in community.general 8.6.0.
|
2023-05-08 19:44:30 +02:00
|
|
|
type: str
|
2024-04-09 08:01:00 +02:00
|
|
|
choices: [ 'bond', 'bridge', 'team', 'ovs-port' ]
|
2023-05-08 19:44:30 +02:00
|
|
|
version_added: 7.0.0
|
2020-03-09 10:11:07 +01:00
|
|
|
master:
|
|
|
|
description:
|
2024-04-09 08:01:00 +02:00
|
|
|
- Master <master (ifname, or connection UUID or conn_name) of bridge, team, bond, ovs-port master connection profile.
|
2023-06-15 15:47:40 +02:00
|
|
|
- Mandatory if O(slave_type) is defined.
|
2020-03-09 10:11:07 +01:00
|
|
|
type: str
|
|
|
|
ip4:
|
|
|
|
description:
|
2021-11-19 07:07:35 +01:00
|
|
|
- List of IPv4 addresses to this interface.
|
2023-06-15 15:47:40 +02:00
|
|
|
- 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).
|
2021-11-19 07:07:35 +01:00
|
|
|
type: list
|
|
|
|
elements: str
|
2020-03-09 10:11:07 +01:00
|
|
|
gw4:
|
|
|
|
description:
|
|
|
|
- The IPv4 gateway for this interface.
|
2023-06-15 15:47:40 +02:00
|
|
|
- Use the format V(192.0.2.1).
|
2020-12-01 20:39:56 +01:00
|
|
|
- This parameter is mutually_exclusive with never_default4 parameter.
|
2020-03-09 10:11:07 +01:00
|
|
|
type: str
|
2021-06-01 22:04:09 +02:00
|
|
|
gw4_ignore_auto:
|
|
|
|
description:
|
|
|
|
- Ignore automatically configured IPv4 routes.
|
|
|
|
type: bool
|
|
|
|
default: false
|
|
|
|
version_added: 3.2.0
|
2020-12-01 20:39:56 +01:00
|
|
|
routes4:
|
|
|
|
description:
|
2022-04-05 06:58:02 +02:00
|
|
|
- The list of IPv4 routes.
|
2023-06-15 15:47:40 +02:00
|
|
|
- Use the format V(192.0.3.0/24 192.0.2.1).
|
|
|
|
- To specify more complex routes, use the O(routes4_extended) option.
|
2020-12-01 20:39:56 +01:00
|
|
|
type: list
|
|
|
|
elements: str
|
|
|
|
version_added: 2.0.0
|
2022-04-05 06:58:02 +02:00
|
|
|
routes4_extended:
|
|
|
|
description:
|
|
|
|
- The list of IPv4 routes.
|
|
|
|
type: list
|
|
|
|
elements: dict
|
|
|
|
suboptions:
|
|
|
|
ip:
|
|
|
|
description:
|
|
|
|
- IP or prefix of route.
|
2023-06-15 15:47:40 +02:00
|
|
|
- Use the format V(192.0.3.0/24).
|
2022-04-05 06:58:02 +02:00
|
|
|
type: str
|
|
|
|
required: true
|
|
|
|
next_hop:
|
|
|
|
description:
|
2023-06-15 15:47:40 +02:00
|
|
|
- Use the format V(192.0.2.1).
|
2022-04-05 06:58:02 +02:00
|
|
|
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
|
2020-12-01 20:39:56 +01:00
|
|
|
route_metric4:
|
|
|
|
description:
|
|
|
|
- Set metric level of ipv4 routes configured on interface.
|
|
|
|
type: int
|
|
|
|
version_added: 2.0.0
|
2021-06-19 14:42:05 +02:00
|
|
|
routing_rules4:
|
|
|
|
description:
|
2023-10-25 08:45:45 +02:00
|
|
|
- Is the same as in an C(ip rule add) command, except always requires specifying a priority.
|
2021-09-29 06:49:49 +02:00
|
|
|
type: list
|
|
|
|
elements: str
|
2021-06-19 14:42:05 +02:00
|
|
|
version_added: 3.3.0
|
2020-12-01 20:39:56 +01:00
|
|
|
never_default4:
|
|
|
|
description:
|
|
|
|
- Set as default route.
|
|
|
|
- This parameter is mutually_exclusive with gw4 parameter.
|
|
|
|
type: bool
|
2022-08-24 20:00:11 +02:00
|
|
|
default: false
|
2020-12-01 20:39:56 +01:00
|
|
|
version_added: 2.0.0
|
2020-03-09 10:11:07 +01:00
|
|
|
dns4:
|
|
|
|
description:
|
2022-06-04 08:42:07 +02:00
|
|
|
- A list of up to 3 DNS servers.
|
2023-06-15 15:47:40 +02:00
|
|
|
- The entries must be IPv4 addresses, for example V(192.0.2.53).
|
2020-10-23 07:13:39 +02:00
|
|
|
elements: str
|
2020-03-09 10:11:07 +01:00
|
|
|
type: list
|
|
|
|
dns4_search:
|
|
|
|
description:
|
|
|
|
- A list of DNS search domains.
|
2020-10-23 07:13:39 +02:00
|
|
|
elements: str
|
2020-03-09 10:11:07 +01:00
|
|
|
type: list
|
2023-07-13 22:26:42 +02:00
|
|
|
dns4_options:
|
|
|
|
description:
|
|
|
|
- A list of DNS options.
|
|
|
|
elements: str
|
|
|
|
type: list
|
|
|
|
version_added: 7.2.0
|
2021-06-01 22:04:09 +02:00
|
|
|
dns4_ignore_auto:
|
|
|
|
description:
|
|
|
|
- Ignore automatically configured IPv4 name servers.
|
|
|
|
type: bool
|
|
|
|
default: false
|
|
|
|
version_added: 3.2.0
|
2021-03-02 12:46:21 +01:00
|
|
|
method4:
|
|
|
|
description:
|
|
|
|
- Configuration method to be used for IPv4.
|
2023-06-15 15:47:40 +02:00
|
|
|
- If O(ip4) is set, C(ipv4.method) is automatically set to V(manual) and this parameter is not needed.
|
2021-03-02 12:46:21 +01:00
|
|
|
type: str
|
|
|
|
choices: [auto, link-local, manual, shared, disabled]
|
|
|
|
version_added: 2.2.0
|
2021-06-19 14:42:05 +02:00
|
|
|
may_fail4:
|
|
|
|
description:
|
2023-06-15 15:47:40 +02:00
|
|
|
- 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).
|
2021-06-19 14:42:05 +02:00
|
|
|
type: bool
|
|
|
|
default: true
|
|
|
|
version_added: 3.3.0
|
2020-03-09 10:11:07 +01:00
|
|
|
ip6:
|
|
|
|
description:
|
2021-12-09 21:17:32 +01:00
|
|
|
- List of IPv6 addresses to this interface.
|
2023-06-15 15:47:40 +02:00
|
|
|
- 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).
|
2021-12-09 21:17:32 +01:00
|
|
|
type: list
|
|
|
|
elements: str
|
2020-03-09 10:11:07 +01:00
|
|
|
gw6:
|
|
|
|
description:
|
|
|
|
- The IPv6 gateway for this interface.
|
2023-06-15 15:47:40 +02:00
|
|
|
- Use the format V(2001:db8::1).
|
2020-03-09 10:11:07 +01:00
|
|
|
type: str
|
2021-06-01 22:04:09 +02:00
|
|
|
gw6_ignore_auto:
|
|
|
|
description:
|
|
|
|
- Ignore automatically configured IPv6 routes.
|
|
|
|
type: bool
|
|
|
|
default: false
|
|
|
|
version_added: 3.2.0
|
2022-01-23 13:02:03 +01:00
|
|
|
routes6:
|
|
|
|
description:
|
|
|
|
- The list of IPv6 routes.
|
2023-06-15 15:47:40 +02:00
|
|
|
- Use the format V(fd12:3456:789a:1::/64 2001:dead:beef::1).
|
|
|
|
- To specify more complex routes, use the O(routes6_extended) option.
|
2022-01-23 13:02:03 +01:00
|
|
|
type: list
|
|
|
|
elements: str
|
|
|
|
version_added: 4.4.0
|
2022-04-05 06:58:02 +02:00
|
|
|
routes6_extended:
|
|
|
|
description:
|
|
|
|
- The list of IPv6 routes but with parameters.
|
|
|
|
type: list
|
|
|
|
elements: dict
|
|
|
|
suboptions:
|
|
|
|
ip:
|
|
|
|
description:
|
|
|
|
- IP or prefix of route.
|
2023-06-15 15:47:40 +02:00
|
|
|
- Use the format V(fd12:3456:789a:1::/64).
|
2022-04-05 06:58:02 +02:00
|
|
|
type: str
|
|
|
|
required: true
|
|
|
|
next_hop:
|
|
|
|
description:
|
2023-06-15 15:47:40 +02:00
|
|
|
- Use the format V(2001:dead:beef::1).
|
2022-04-05 06:58:02 +02:00
|
|
|
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
|
2022-01-23 13:02:03 +01:00
|
|
|
route_metric6:
|
|
|
|
description:
|
|
|
|
- Set metric level of IPv6 routes configured on interface.
|
|
|
|
type: int
|
|
|
|
version_added: 4.4.0
|
2020-03-09 10:11:07 +01:00
|
|
|
dns6:
|
|
|
|
description:
|
2022-06-04 08:42:07 +02:00
|
|
|
- A list of up to 3 DNS servers.
|
2023-06-15 15:47:40 +02:00
|
|
|
- The entries must be IPv6 addresses, for example V(2001:4860:4860::8888).
|
2020-10-23 07:13:39 +02:00
|
|
|
elements: str
|
2020-03-09 10:11:07 +01:00
|
|
|
type: list
|
|
|
|
dns6_search:
|
|
|
|
description:
|
|
|
|
- A list of DNS search domains.
|
2020-10-23 07:13:39 +02:00
|
|
|
elements: str
|
2020-03-09 10:11:07 +01:00
|
|
|
type: list
|
2023-07-13 22:26:42 +02:00
|
|
|
dns6_options:
|
|
|
|
description:
|
|
|
|
- A list of DNS options.
|
|
|
|
elements: str
|
|
|
|
type: list
|
|
|
|
version_added: 7.2.0
|
2021-06-01 22:04:09 +02:00
|
|
|
dns6_ignore_auto:
|
|
|
|
description:
|
|
|
|
- Ignore automatically configured IPv6 name servers.
|
|
|
|
type: bool
|
|
|
|
default: false
|
|
|
|
version_added: 3.2.0
|
2021-03-02 12:46:21 +01:00
|
|
|
method6:
|
|
|
|
description:
|
|
|
|
- Configuration method to be used for IPv6
|
2023-06-15 15:47:40 +02:00
|
|
|
- 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.
|
2021-03-02 12:46:21 +01:00
|
|
|
type: str
|
2021-06-19 14:42:05 +02:00
|
|
|
choices: [ignore, auto, dhcp, link-local, manual, shared, disabled]
|
2021-03-02 12:46:21 +01:00
|
|
|
version_added: 2.2.0
|
2021-12-04 18:41:14 +01:00
|
|
|
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.
|
2023-06-15 15:47:40 +02:00
|
|
|
- V(default) and V(default-or-eui64) have been added in community.general 6.5.0.
|
2021-12-04 18:41:14 +01:00
|
|
|
type: str
|
2023-03-24 07:55:58 +01:00
|
|
|
choices: [default, default-or-eui64, eui64, stable-privacy]
|
2021-12-04 18:41:14 +01:00
|
|
|
version_added: 4.2.0
|
2020-03-09 10:11:07 +01:00
|
|
|
mtu:
|
|
|
|
description:
|
|
|
|
- The connection MTU, e.g. 9000. This can't be applied when creating the interface and is done once the interface has been created.
|
2021-09-05 18:28:04 +02:00
|
|
|
- Can be used when modifying Team, VLAN, Ethernet (Future plans to implement wifi, gsm, pppoe, infiniband)
|
2023-06-15 15:47:40 +02:00
|
|
|
- This parameter defaults to V(1500) when unset.
|
2020-03-09 10:11:07 +01:00
|
|
|
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.
|
2023-06-15 15:47:40 +02:00
|
|
|
- This parameter defaults to V(100) when unset.
|
2020-03-09 10:11:07 +01:00
|
|
|
type: int
|
|
|
|
downdelay:
|
|
|
|
description:
|
|
|
|
- This is only used with bond - downdelay.
|
|
|
|
type: int
|
|
|
|
updelay:
|
|
|
|
description:
|
|
|
|
- This is only used with bond - updelay.
|
|
|
|
type: int
|
2022-09-08 07:45:23 +02:00
|
|
|
xmit_hash_policy:
|
|
|
|
description:
|
|
|
|
- This is only used with bond - xmit_hash_policy type.
|
|
|
|
type: str
|
|
|
|
version_added: 5.6.0
|
2020-03-09 10:11:07 +01:00
|
|
|
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
|
2022-08-24 20:00:11 +02:00
|
|
|
default: true
|
2020-03-09 10:11:07 +01:00
|
|
|
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:
|
2021-04-19 19:02:48 +02:00
|
|
|
- MAC address of the connection.
|
2020-03-09 10:11:07 +01:00
|
|
|
- Note this requires a recent kernel feature, originally introduced in 3.15 upstream kernel.
|
2020-10-23 07:13:39 +02:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
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 via 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.
|
2023-06-15 15:47:40 +02:00
|
|
|
- The default change to V(false) in community.general 7.0.0. It used to be V(true) before.
|
2020-03-09 10:11:07 +01:00
|
|
|
type: bool
|
2023-04-26 07:32:00 +02:00
|
|
|
default: false
|
2021-07-14 08:24:27 +02:00
|
|
|
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
|
2023-03-26 09:27:00 +02:00
|
|
|
runner_fast_rate:
|
|
|
|
description:
|
|
|
|
- Option specifies the rate at which our link partner is asked to transmit LACPDU
|
2023-06-15 15:47:40 +02:00
|
|
|
packets. If this is V(true) then packets will be sent once per second. Otherwise they
|
2023-03-26 09:27:00 +02:00
|
|
|
will be sent every 30 seconds.
|
2023-06-15 15:47:40 +02:00
|
|
|
- Only allowed for O(runner=lacp).
|
2023-03-26 09:27:00 +02:00
|
|
|
type: bool
|
|
|
|
version_added: 6.5.0
|
2020-03-09 10:11:07 +01:00
|
|
|
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:
|
2021-08-26 08:16:36 +02:00
|
|
|
- This is used with GRE/IPIP/SIT - parent device this GRE/IPIP/SIT tunnel, can use ifname.
|
2020-03-09 10:11:07 +01:00
|
|
|
type: str
|
|
|
|
ip_tunnel_remote:
|
|
|
|
description:
|
2021-08-26 08:16:36 +02:00
|
|
|
- This is used with GRE/IPIP/SIT - GRE/IPIP/SIT destination IP address.
|
2020-03-09 10:11:07 +01:00
|
|
|
type: str
|
|
|
|
ip_tunnel_local:
|
|
|
|
description:
|
2021-08-26 08:16:36 +02:00
|
|
|
- This is used with GRE/IPIP/SIT - GRE/IPIP/SIT local IP address.
|
2020-03-09 10:11:07 +01:00
|
|
|
type: str
|
2021-08-26 08:16:36 +02:00
|
|
|
ip_tunnel_input_key:
|
|
|
|
description:
|
|
|
|
- The key used for tunnel input packets.
|
2023-06-15 15:47:40 +02:00
|
|
|
- Only used when O(type=gre).
|
2021-08-26 08:16:36 +02:00
|
|
|
type: str
|
|
|
|
version_added: 3.6.0
|
|
|
|
ip_tunnel_output_key:
|
|
|
|
description:
|
|
|
|
- The key used for tunnel output packets.
|
2023-06-15 15:47:40 +02:00
|
|
|
- Only used when O(type=gre).
|
2021-08-26 08:16:36 +02:00
|
|
|
type: str
|
|
|
|
version_added: 3.6.0
|
2020-12-05 16:18:29 +01:00
|
|
|
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
|
2021-04-18 10:59:23 +02:00
|
|
|
wifi_sec:
|
|
|
|
description:
|
2021-08-20 21:45:30 +02:00
|
|
|
- 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:
|
2021-08-07 15:20:44 +02:00
|
|
|
U(https://networkmanager.dev/docs/api/latest/settings-802-11-wireless-security.html).'
|
|
|
|
- 'For instance to use common WPA-PSK auth with a password:
|
2023-06-15 15:47:40 +02:00
|
|
|
V({key-mgmt: wpa-psk, psk: my_password}).'
|
2021-04-18 10:59:23 +02:00
|
|
|
type: dict
|
2021-08-20 21:45:30 +02:00
|
|
|
suboptions:
|
|
|
|
auth-alg:
|
|
|
|
description:
|
2023-06-15 15:47:40 +02:00
|
|
|
- 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
|
2021-08-20 21:45:30 +02:00
|
|
|
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.
|
2023-06-15 15:47:40 +02:00
|
|
|
- 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)
|
2021-08-20 21:45:30 +02:00
|
|
|
(enable FILS and fail if not supported).
|
2023-06-15 15:47:40 +02:00
|
|
|
- When set to V(0) and no global default is set, FILS will be optionally enabled.
|
2021-08-20 21:45:30 +02:00
|
|
|
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.
|
2023-06-15 15:47:40 +02:00
|
|
|
- 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).
|
2021-08-20 21:45:30 +02:00
|
|
|
- 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:
|
2023-06-15 15:47:40 +02:00
|
|
|
description: Flags indicating how to handle the O(wifi_sec.leap-password) property.
|
2021-08-20 21:45:30 +02:00
|
|
|
type: list
|
|
|
|
elements: int
|
|
|
|
leap-password:
|
2023-06-15 15:47:40 +02:00
|
|
|
description: The login password for legacy LEAP connections (that is, if O(wifi_sec.key-mgmt=ieee8021x) and O(wifi_sec.auth-alg=leap)).
|
2021-08-20 21:45:30 +02:00
|
|
|
type: str
|
|
|
|
leap-username:
|
2023-06-15 15:47:40 +02:00
|
|
|
description: The login username for legacy LEAP connections (that is, if O(wifi_sec.key-mgmt=ieee8021x) and O(wifi_sec.auth-alg=leap)).
|
2021-08-20 21:45:30 +02:00
|
|
|
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.
|
2023-06-15 15:47:40 +02:00
|
|
|
- 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.
|
2021-08-20 21:45:30 +02:00
|
|
|
type: int
|
|
|
|
choices: [ 0, 1, 2, 3 ]
|
|
|
|
default: 0
|
|
|
|
proto:
|
|
|
|
description:
|
|
|
|
- List of strings specifying the allowed WPA protocol versions to use.
|
2023-06-15 15:47:40 +02:00
|
|
|
- Each element may be V(wpa) (allow WPA) or V(rsn) (allow WPA2/RSN).
|
2021-08-20 21:45:30 +02:00
|
|
|
- If not specified, both WPA and RSN connections are allowed.
|
|
|
|
type: list
|
|
|
|
elements: str
|
|
|
|
choices: [ wpa, rsn ]
|
|
|
|
psk-flags:
|
2023-06-15 15:47:40 +02:00
|
|
|
description: Flags indicating how to handle the O(wifi_sec.psk) property.
|
2021-08-20 21:45:30 +02:00
|
|
|
type: list
|
|
|
|
elements: int
|
|
|
|
psk:
|
|
|
|
description:
|
|
|
|
- Pre-Shared-Key for WPA networks.
|
2023-06-15 15:47:40 +02:00
|
|
|
- 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
|
2021-08-20 21:45:30 +02:00
|
|
|
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:
|
2023-06-15 15:47:40 +02:00
|
|
|
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.
|
2021-08-20 21:45:30 +02:00
|
|
|
type: list
|
|
|
|
elements: int
|
|
|
|
wep-key-type:
|
|
|
|
description:
|
|
|
|
- Controls the interpretation of WEP keys.
|
2023-06-15 15:47:40 +02:00
|
|
|
- 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
|
2021-08-20 21:45:30 +02:00
|
|
|
actual WEP key.
|
|
|
|
type: int
|
|
|
|
choices: [ 1, 2 ]
|
|
|
|
wep-key0:
|
|
|
|
description:
|
|
|
|
- Index 0 WEP key. This is the WEP key used in most networks.
|
2023-06-15 15:47:40 +02:00
|
|
|
- See the O(wifi_sec.wep-key-type) property for a description of how this key is interpreted.
|
2021-08-20 21:45:30 +02:00
|
|
|
type: str
|
|
|
|
wep-key1:
|
|
|
|
description:
|
|
|
|
- Index 1 WEP key. This WEP index is not used by most networks.
|
2023-06-15 15:47:40 +02:00
|
|
|
- See the O(wifi_sec.wep-key-type) property for a description of how this key is interpreted.
|
2021-08-20 21:45:30 +02:00
|
|
|
type: str
|
|
|
|
wep-key2:
|
|
|
|
description:
|
|
|
|
- Index 2 WEP key. This WEP index is not used by most networks.
|
2023-06-15 15:47:40 +02:00
|
|
|
- See the O(wifi_sec.wep-key-type) property for a description of how this key is interpreted.
|
2021-08-20 21:45:30 +02:00
|
|
|
type: str
|
|
|
|
wep-key3:
|
|
|
|
description:
|
|
|
|
- Index 3 WEP key. This WEP index is not used by most networks.
|
2023-06-15 15:47:40 +02:00
|
|
|
- See the O(wifi_sec.wep-key-type) property for a description of how this key is interpreted.
|
2021-08-20 21:45:30 +02:00
|
|
|
type: str
|
|
|
|
wep-tx-keyidx:
|
|
|
|
description:
|
2023-06-15 15:47:40 +02:00
|
|
|
- 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).
|
2021-08-20 21:45:30 +02:00
|
|
|
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.
|
2023-06-15 15:47:40 +02:00
|
|
|
- WPS can be disabled by setting this property to a value of V(1).
|
2021-08-20 21:45:30 +02:00
|
|
|
type: int
|
|
|
|
default: 0
|
2021-04-18 10:59:23 +02:00
|
|
|
version_added: 3.0.0
|
|
|
|
ssid:
|
|
|
|
description:
|
|
|
|
- Name of the Wireless router or the access point.
|
|
|
|
type: str
|
|
|
|
version_added: 3.0.0
|
2021-08-04 08:16:11 +02:00
|
|
|
wifi:
|
|
|
|
description:
|
2021-08-20 21:45:30 +02:00
|
|
|
- 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:
|
2021-08-04 08:16:11 +02:00
|
|
|
U(https://networkmanager.dev/docs/api/latest/settings-802-11-wireless.html).'
|
2021-08-07 15:20:44 +02:00
|
|
|
- 'For instance to create a hidden AP mode WiFi connection:
|
2023-06-15 15:47:40 +02:00
|
|
|
V({hidden: true, mode: ap}).'
|
2021-08-04 08:16:11 +02:00
|
|
|
type: dict
|
2021-08-20 21:45:30 +02:00
|
|
|
suboptions:
|
|
|
|
ap-isolation:
|
|
|
|
description:
|
|
|
|
- Configures AP isolation, which prevents communication between wireless devices connected to this AP.
|
2023-06-15 15:47:40 +02:00
|
|
|
- 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
|
2021-08-20 21:45:30 +02:00
|
|
|
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, etc.
|
2023-06-15 15:47:40 +02:00
|
|
|
- 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).
|
2021-08-20 21:45:30 +02:00
|
|
|
type: int
|
|
|
|
choices: [ -1, 0, 1 ]
|
|
|
|
default: -1
|
|
|
|
assigned-mac-address:
|
|
|
|
description:
|
|
|
|
- The new field for the cloned MAC address.
|
2023-06-15 15:47:40 +02:00
|
|
|
- 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).
|
2021-08-20 21:45:30 +02:00
|
|
|
type: str
|
|
|
|
band:
|
|
|
|
description:
|
|
|
|
- 802.11 frequency band of the network.
|
2023-06-15 15:47:40 +02:00
|
|
|
- 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
|
2021-08-20 21:45:30 +02:00
|
|
|
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.
|
2023-06-15 15:47:40 +02:00
|
|
|
- Because channel numbers overlap between bands, this property also requires the O(wifi.band) property to be set.
|
2021-08-20 21:45:30 +02:00
|
|
|
type: int
|
|
|
|
default: 0
|
|
|
|
cloned-mac-address:
|
|
|
|
description:
|
2023-06-15 15:47:40 +02:00
|
|
|
- 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).
|
2021-08-20 21:45:30 +02:00
|
|
|
type: str
|
|
|
|
generate-mac-address-mask:
|
|
|
|
description:
|
2023-06-15 15:47:40 +02:00
|
|
|
- With O(wifi.cloned-mac-address) setting V(random) or V(stable), by default all bits of the MAC address are scrambled and a
|
2021-08-20 21:45:30 +02:00
|
|
|
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.
|
2023-06-15 15:47:40 +02:00
|
|
|
- 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.
|
2021-08-20 21:45:30 +02:00
|
|
|
- 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.
|
2023-06-15 15:47:40 +02:00
|
|
|
- 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.
|
2021-08-20 21:45:30 +02:00
|
|
|
- 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.
|
2023-06-15 15:47:40 +02:00
|
|
|
- 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
|
2021-08-20 21:45:30 +02:00
|
|
|
randomized.
|
2023-06-15 15:47:40 +02:00
|
|
|
- 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.
|
2021-08-20 21:45:30 +02:00
|
|
|
- If the value contains more than one additional MAC addresses, one of them is chosen randomly. For example,
|
2023-06-15 15:47:40 +02:00
|
|
|
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
|
2021-08-20 21:45:30 +02:00
|
|
|
administered.
|
|
|
|
type: str
|
|
|
|
hidden:
|
|
|
|
description:
|
2023-06-15 15:47:40 +02:00
|
|
|
- If V(true), indicates that the network is a non-broadcasting network that hides its SSID. This works both in infrastructure and AP mode.
|
2021-08-20 21:45:30 +02:00
|
|
|
- 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.
|
2023-06-15 15:47:40 +02:00
|
|
|
- Each MAC address should be given in the standard hex-digits-and-colons notation (for example, V(00:11:22:33:44:55)).
|
2021-08-20 21:45:30 +02:00
|
|
|
type: list
|
|
|
|
elements: str
|
|
|
|
mac-address-randomization:
|
|
|
|
description:
|
2023-06-15 15:47:40 +02:00
|
|
|
- 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).
|
2021-08-20 21:45:30 +02:00
|
|
|
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:
|
2023-06-15 15:47:40 +02:00
|
|
|
description: Wi-Fi network mode. If blank, V(infrastructure) is assumed.
|
2021-08-20 21:45:30 +02:00
|
|
|
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:
|
2023-06-15 15:47:40 +02:00
|
|
|
- One of V(2) (disable Wi-Fi power saving), V(3) (enable Wi-Fi power saving), V(1) (don't touch currently configure setting) or V(0) (use
|
2021-08-20 21:45:30 +02:00
|
|
|
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.
|
2023-06-15 15:47:40 +02:00
|
|
|
- Units are in Kb/s, so for example V(5500) = 5.5 Mbit/s.
|
2021-08-20 21:45:30 +02:00
|
|
|
- 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.
|
2023-06-15 15:47:40 +02:00
|
|
|
- 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).
|
2021-08-20 21:45:30 +02:00
|
|
|
- Note the option values' sum must be specified in order to combine multiple options.
|
|
|
|
type: int
|
|
|
|
default: 1
|
2021-08-04 08:16:11 +02:00
|
|
|
version_added: 3.5.0
|
2021-08-20 21:45:30 +02:00
|
|
|
ignore_unsupported_suboptions:
|
|
|
|
description:
|
|
|
|
- Ignore suboptions which are invalid or unsupported by the version of NetworkManager/nmcli installed on the host.
|
2023-06-15 15:47:40 +02:00
|
|
|
- Only O(wifi) and O(wifi_sec) options are currently affected.
|
2021-08-20 21:45:30 +02:00
|
|
|
type: bool
|
|
|
|
default: false
|
|
|
|
version_added: 3.6.0
|
2021-09-05 18:28:04 +02:00
|
|
|
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:
|
2023-06-15 15:47:40 +02:00
|
|
|
V({apn: provider.apn, pin: 1234, username: apn.username, password: apn.password}).'
|
2021-09-05 18:28:04 +02:00
|
|
|
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:
|
2023-06-15 15:47:40 +02:00
|
|
|
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
|
2021-09-05 18:28:04 +02:00
|
|
|
the modem will register to in the Mobile Broadband Provider database.
|
|
|
|
type: bool
|
|
|
|
default: false
|
|
|
|
device-id:
|
|
|
|
description:
|
2023-06-15 15:47:40 +02:00
|
|
|
- The device unique identifier (as given by the V(WWAN) management service) which this connection applies to.
|
2021-09-05 18:28:04 +02:00
|
|
|
- If given, the connection will only apply to the specified device.
|
|
|
|
type: str
|
|
|
|
home-only:
|
|
|
|
description:
|
2023-06-15 15:47:40 +02:00
|
|
|
- When V(true), only connections to the home network will be allowed.
|
2021-09-05 18:28:04 +02:00
|
|
|
- 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:
|
2023-06-15 15:47:40 +02:00
|
|
|
- NMSettingSecretFlags indicating how to handle the O(gsm.password) property.
|
2021-09-05 18:28:04 +02:00
|
|
|
- 'Following choices are allowed:
|
2023-06-15 15:47:40 +02:00
|
|
|
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
|
2021-09-05 18:28:04 +02:00
|
|
|
asked to retrieve it
|
2023-06-15 15:47:40 +02:00
|
|
|
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
|
2021-09-05 18:28:04 +02:00
|
|
|
(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:
|
2023-06-15 15:47:40 +02:00
|
|
|
- NMSettingSecretFlags indicating how to handle the O(gsm.pin) property.
|
|
|
|
- See O(gsm.password-flags) for NMSettingSecretFlags choices.
|
2021-09-05 18:28:04 +02:00
|
|
|
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.
|
2023-06-15 15:47:40 +02:00
|
|
|
- 'If given, the connection will apply to any device also allowed by O(gsm.device-id) which contains a SIM card matching
|
2021-09-05 18:28:04 +02:00
|
|
|
the given identifier.'
|
|
|
|
type: str
|
|
|
|
sim-operator-id:
|
|
|
|
description:
|
2023-06-15 15:47:40 +02:00
|
|
|
- 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
|
2021-09-05 18:28:04 +02:00
|
|
|
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.
|
2023-04-16 13:22:11 +02:00
|
|
|
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.
|
2023-06-15 15:47:40 +02:00
|
|
|
- '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)'
|
2023-04-16 13:22:11 +02:00
|
|
|
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
|
2022-01-08 14:13:50 +01:00
|
|
|
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:
|
2023-06-15 15:47:40 +02:00
|
|
|
V({listen-port: 12345}).'
|
2022-01-08 14:13:50 +01:00
|
|
|
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.
|
2023-06-15 15:47:40 +02:00
|
|
|
- Note that O(wireguard.ip4-auto-default-route) or O(wireguard.ip6-auto-default-route) enabled, implies to automatically choose a fwmark.
|
2022-01-08 14:13:50 +01:00
|
|
|
type: int
|
|
|
|
ip4-auto-default-route:
|
|
|
|
description:
|
|
|
|
- Whether to enable special handling of the IPv4 default route.
|
2023-06-15 15:47:40 +02:00
|
|
|
- If enabled, the IPv4 default route from O(wireguard.peer-routes) will be placed to a dedicated routing-table and two policy
|
2022-01-08 14:13:50 +01:00
|
|
|
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:
|
2023-06-15 15:47:40 +02:00
|
|
|
- Like O(wireguard.ip4-auto-default-route), but for the IPv6 default route.
|
2022-01-08 14:13:50 +01:00
|
|
|
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.
|
2023-06-15 15:47:40 +02:00
|
|
|
- If V(true) (the default), NetworkManager will automatically add routes in the routing tables according to C(ipv4.route-table) and
|
2022-01-08 14:13:50 +01:00
|
|
|
C(ipv6.route-table). Usually you want this automatism enabled.
|
2023-06-15 15:47:40 +02:00
|
|
|
- If V(false), no such routes are added automatically. In this case, the user may want to configure static routes in C(ipv4.routes)
|
2022-01-08 14:13:50 +01:00
|
|
|
and C(ipv6.routes), respectively.
|
2023-06-15 15:47:40 +02:00
|
|
|
- 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)
|
2022-01-08 14:13:50 +01:00
|
|
|
setting is enabled, the peer route for this peer won't be added automatically.
|
|
|
|
type: bool
|
|
|
|
private-key:
|
|
|
|
description: The 256 bit private-key in base64 encoding.
|
|
|
|
type: str
|
|
|
|
private-key-flags:
|
2023-06-15 15:47:40 +02:00
|
|
|
description: C(NMSettingSecretFlags) indicating how to handle the O(wireguard.private-key) property.
|
2022-01-08 14:13:50 +01:00
|
|
|
type: int
|
|
|
|
choices: [ 0, 1, 2 ]
|
2022-06-06 21:16:27 +02:00
|
|
|
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:
|
2023-06-15 15:47:40 +02:00
|
|
|
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)).
|
2022-06-06 21:16:27 +02:00
|
|
|
type: str
|
|
|
|
required: true
|
|
|
|
password-flags:
|
|
|
|
description:
|
2023-06-15 15:47:40 +02:00
|
|
|
- NMSettingSecretFlags indicating how to handle the C(vpn.password) property.
|
2022-06-06 21:16:27 +02:00
|
|
|
- 'Following choices are allowed:
|
2023-06-15 15:47:40 +02:00
|
|
|
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
|
2022-06-06 21:16:27 +02:00
|
|
|
asked to retrieve it;
|
2023-06-15 15:47:40 +02:00
|
|
|
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
|
2022-06-06 21:16:27 +02:00
|
|
|
(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.
|
2023-06-15 15:47:40 +02:00
|
|
|
- This option is need when O(vpn.service-type) is V(org.freedesktop.NetworkManager.l2tp).
|
2022-06-06 21:16:27 +02:00
|
|
|
type: bool
|
|
|
|
ipsec-psk:
|
|
|
|
description:
|
|
|
|
- The pre-shared key in base64 encoding.
|
|
|
|
- >
|
2023-06-15 15:47:40 +02:00
|
|
|
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).
|
2022-06-06 21:16:27 +02:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
'''
|
|
|
|
|
|
|
|
EXAMPLES = r'''
|
|
|
|
# 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
|
2021-11-19 07:07:35 +01:00
|
|
|
# ip4:
|
|
|
|
# - '{{ tenant_ip }}'
|
|
|
|
# - '{{ second_tenant_ip }}'
|
2020-03-09 10:11:07 +01:00
|
|
|
# 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"
|
2021-11-19 07:07:35 +01:00
|
|
|
# second_tenant_ip: "204.0.113.77/23"
|
2020-03-09 10:11:07 +01:00
|
|
|
# ```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## playbook-add.yml example
|
|
|
|
|
|
|
|
---
|
|
|
|
- hosts: openstack-stage
|
|
|
|
remote_user: root
|
|
|
|
tasks:
|
|
|
|
|
2020-05-16 15:07:51 +02:00
|
|
|
- name: Install needed network manager libs
|
2020-07-14 17:28:08 +02:00
|
|
|
ansible.builtin.package:
|
2020-03-09 10:11:07 +01:00
|
|
|
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
|
2020-07-13 21:50:31 +02:00
|
|
|
community.general.nmcli:
|
2020-03-09 10:11:07 +01:00
|
|
|
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
|
2020-07-13 21:50:31 +02:00
|
|
|
community.general.nmcli:
|
2020-03-09 10:11:07 +01:00
|
|
|
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
|
2020-07-13 21:50:31 +02:00
|
|
|
community.general.nmcli:
|
2020-03-09 10:11:07 +01:00
|
|
|
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
|
2020-07-13 21:50:31 +02:00
|
|
|
community.general.nmcli:
|
2020-03-09 10:11:07 +01:00
|
|
|
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
|
2020-07-13 21:50:31 +02:00
|
|
|
community.general.nmcli:
|
2020-03-09 10:11:07 +01:00
|
|
|
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
|
2020-07-13 21:50:31 +02:00
|
|
|
community.general.nmcli:
|
2020-03-09 10:11:07 +01:00
|
|
|
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
|
2020-07-13 21:50:31 +02:00
|
|
|
community.general.nmcli:
|
2020-06-15 13:34:17 +02:00
|
|
|
conn_name: my-eth1
|
|
|
|
ifname: eth1
|
|
|
|
type: ethernet
|
|
|
|
ip4: 192.0.2.100/24
|
|
|
|
gw4: 192.0.2.1
|
|
|
|
state: present
|
2020-03-09 10:11:07 +01:00
|
|
|
|
|
|
|
- name: Add an Team connection with static IP configuration
|
2020-07-13 21:50:31 +02:00
|
|
|
community.general.nmcli:
|
2020-03-09 10:11:07 +01:00
|
|
|
conn_name: my-team1
|
|
|
|
ifname: my-team1
|
|
|
|
type: team
|
|
|
|
ip4: 192.0.2.100/24
|
|
|
|
gw4: 192.0.2.1
|
|
|
|
state: present
|
2022-08-24 20:00:11 +02:00
|
|
|
autoconnect: true
|
2020-03-09 10:11:07 +01:00
|
|
|
|
|
|
|
- name: Optionally, at the same time specify IPv6 addresses for the device
|
2020-07-13 21:50:31 +02:00
|
|
|
community.general.nmcli:
|
2020-03-09 10:11:07 +01:00
|
|
|
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
|
2020-07-13 21:50:31 +02:00
|
|
|
community.general.nmcli:
|
2020-03-09 10:11:07 +01:00
|
|
|
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
|
2020-07-13 21:50:31 +02:00
|
|
|
community.general.nmcli:
|
2020-03-09 10:11:07 +01:00
|
|
|
ctype: ethernet
|
|
|
|
name: my-eth1
|
|
|
|
ifname: '*'
|
|
|
|
state: present
|
|
|
|
|
|
|
|
- name: Change the property of a setting e.g. MTU
|
2020-07-13 21:50:31 +02:00
|
|
|
community.general.nmcli:
|
2020-03-09 10:11:07 +01:00
|
|
|
conn_name: my-eth1
|
|
|
|
mtu: 9000
|
|
|
|
type: ethernet
|
|
|
|
state: present
|
|
|
|
|
2021-11-19 07:07:35 +01:00
|
|
|
- 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
|
|
|
|
|
2021-11-28 21:09:49 +01:00
|
|
|
- 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
|
|
|
|
|
2020-03-09 10:11:07 +01:00
|
|
|
- name: Add VxLan
|
2020-07-13 21:50:31 +02:00
|
|
|
community.general.nmcli:
|
2020-03-09 10:11:07 +01:00
|
|
|
type: vxlan
|
|
|
|
conn_name: vxlan_test1
|
|
|
|
vxlan_id: 16
|
|
|
|
vxlan_local: 192.168.1.2
|
|
|
|
vxlan_remote: 192.168.1.5
|
|
|
|
|
2021-08-26 08:16:36 +02:00
|
|
|
- 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
|
|
|
|
|
2020-03-09 10:11:07 +01:00
|
|
|
- name: Add ipip
|
2020-07-13 21:50:31 +02:00
|
|
|
community.general.nmcli:
|
2020-03-09 10:11:07 +01:00
|
|
|
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
|
2020-07-13 21:50:31 +02:00
|
|
|
community.general.nmcli:
|
2020-03-09 10:11:07 +01:00
|
|
|
type: sit
|
|
|
|
conn_name: sit_test1
|
|
|
|
ip_tunnel_dev: eth0
|
|
|
|
ip_tunnel_local: 192.168.1.2
|
|
|
|
ip_tunnel_remote: 192.168.1.5
|
|
|
|
|
2020-12-05 16:18:29 +01:00
|
|
|
- name: Add zone
|
|
|
|
community.general.nmcli:
|
|
|
|
type: ethernet
|
|
|
|
conn_name: my-eth1
|
|
|
|
zone: external
|
|
|
|
state: present
|
|
|
|
|
2020-03-09 10:11:07 +01:00
|
|
|
# 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.
|
2021-04-18 10:59:23 +02:00
|
|
|
|
|
|
|
- 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
|
|
|
|
|
2021-08-04 08:16:11 +02:00
|
|
|
- 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
|
|
|
|
|
2021-09-05 18:28:04 +02:00
|
|
|
- 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
|
|
|
|
|
2023-04-16 13:22:11 +02:00
|
|
|
- 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
|
|
|
|
|
2022-01-08 14:13:50 +01:00
|
|
|
- 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
|
|
|
|
|
2022-06-06 21:16:27 +02:00
|
|
|
- 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 }}"
|
2022-09-03 12:02:03 +02:00
|
|
|
service-type: org.freedesktop.NetworkManager.l2tp
|
2022-06-06 21:16:27 +02:00
|
|
|
gateway: vpn.example.com
|
|
|
|
password-flags: 2
|
|
|
|
user: brittany
|
|
|
|
ipsec-enabled: true
|
|
|
|
ipsec-psk: "0s{{ 'Brittany123' | ansible.builtin.b64encode }}"
|
|
|
|
autoconnect: false
|
|
|
|
state: present
|
|
|
|
|
2023-05-08 19:44:30 +02:00
|
|
|
## 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
|
2023-10-25 08:45:45 +02:00
|
|
|
|
|
|
|
## 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"
|
2024-04-09 08:01:00 +02:00
|
|
|
|
|
|
|
## 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
|
2020-03-09 10:11:07 +01:00
|
|
|
'''
|
|
|
|
|
|
|
|
RETURN = r"""#
|
|
|
|
"""
|
|
|
|
|
2020-10-23 07:13:39 +02:00
|
|
|
from ansible.module_utils.basic import AnsibleModule
|
2021-06-26 23:59:11 +02:00
|
|
|
from ansible.module_utils.common.text.converters import to_text
|
2020-06-30 05:43:39 +02:00
|
|
|
import re
|
|
|
|
|
|
|
|
|
|
|
|
class NmcliModuleError(Exception):
|
|
|
|
pass
|
2020-03-09 10:11:07 +01:00
|
|
|
|
|
|
|
|
|
|
|
class Nmcli(object):
|
|
|
|
"""
|
|
|
|
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()
|
2021-08-20 21:45:30 +02:00
|
|
|
- edit_connection()
|
2020-03-09 10:11:07 +01:00
|
|
|
- modify_connection()
|
|
|
|
- show_connection()
|
|
|
|
- up_connection()
|
|
|
|
- down_connection()
|
|
|
|
All subclasses MUST define platform and distribution (which may be None).
|
|
|
|
"""
|
|
|
|
|
|
|
|
platform = 'Generic'
|
|
|
|
distribution = None
|
|
|
|
|
2021-08-08 18:35:52 +02:00
|
|
|
SECRET_OPTIONS = (
|
|
|
|
'802-11-wireless-security.leap-password',
|
|
|
|
'802-11-wireless-security.psk',
|
|
|
|
'802-11-wireless-security.wep-key0',
|
|
|
|
'802-11-wireless-security.wep-key1',
|
|
|
|
'802-11-wireless-security.wep-key2',
|
|
|
|
'802-11-wireless-security.wep-key3'
|
|
|
|
)
|
|
|
|
|
2020-03-09 10:11:07 +01:00
|
|
|
def __init__(self, module):
|
|
|
|
self.module = module
|
|
|
|
self.state = module.params['state']
|
2021-08-20 21:45:30 +02:00
|
|
|
self.ignore_unsupported_suboptions = module.params['ignore_unsupported_suboptions']
|
2020-03-09 10:11:07 +01:00
|
|
|
self.autoconnect = module.params['autoconnect']
|
|
|
|
self.conn_name = module.params['conn_name']
|
2023-05-08 19:44:30 +02:00
|
|
|
self.slave_type = module.params['slave_type']
|
2020-03-09 10:11:07 +01:00
|
|
|
self.master = module.params['master']
|
|
|
|
self.ifname = module.params['ifname']
|
|
|
|
self.type = module.params['type']
|
|
|
|
self.ip4 = module.params['ip4']
|
|
|
|
self.gw4 = module.params['gw4']
|
2021-06-01 22:04:09 +02:00
|
|
|
self.gw4_ignore_auto = module.params['gw4_ignore_auto']
|
2020-12-01 20:39:56 +01:00
|
|
|
self.routes4 = module.params['routes4']
|
2022-04-05 06:58:02 +02:00
|
|
|
self.routes4_extended = module.params['routes4_extended']
|
2020-12-01 20:39:56 +01:00
|
|
|
self.route_metric4 = module.params['route_metric4']
|
2021-06-19 14:42:05 +02:00
|
|
|
self.routing_rules4 = module.params['routing_rules4']
|
2020-12-01 20:39:56 +01:00
|
|
|
self.never_default4 = module.params['never_default4']
|
2020-10-23 07:13:39 +02:00
|
|
|
self.dns4 = module.params['dns4']
|
|
|
|
self.dns4_search = module.params['dns4_search']
|
2023-07-13 22:26:42 +02:00
|
|
|
self.dns4_options = module.params['dns4_options']
|
2021-06-01 22:04:09 +02:00
|
|
|
self.dns4_ignore_auto = module.params['dns4_ignore_auto']
|
2021-03-02 12:46:21 +01:00
|
|
|
self.method4 = module.params['method4']
|
2021-06-19 14:42:05 +02:00
|
|
|
self.may_fail4 = module.params['may_fail4']
|
2020-03-09 10:11:07 +01:00
|
|
|
self.ip6 = module.params['ip6']
|
|
|
|
self.gw6 = module.params['gw6']
|
2021-06-01 22:04:09 +02:00
|
|
|
self.gw6_ignore_auto = module.params['gw6_ignore_auto']
|
2022-01-23 13:02:03 +01:00
|
|
|
self.routes6 = module.params['routes6']
|
2022-04-05 06:58:02 +02:00
|
|
|
self.routes6_extended = module.params['routes6_extended']
|
2022-01-23 13:02:03 +01:00
|
|
|
self.route_metric6 = module.params['route_metric6']
|
2020-10-23 07:13:39 +02:00
|
|
|
self.dns6 = module.params['dns6']
|
|
|
|
self.dns6_search = module.params['dns6_search']
|
2023-07-13 22:26:42 +02:00
|
|
|
self.dns6_options = module.params['dns6_options']
|
2021-06-01 22:04:09 +02:00
|
|
|
self.dns6_ignore_auto = module.params['dns6_ignore_auto']
|
2021-03-02 12:46:21 +01:00
|
|
|
self.method6 = module.params['method6']
|
2021-12-04 18:41:14 +01:00
|
|
|
self.ip_privacy6 = module.params['ip_privacy6']
|
|
|
|
self.addr_gen_mode6 = module.params['addr_gen_mode6']
|
2020-03-09 10:11:07 +01:00
|
|
|
self.mtu = module.params['mtu']
|
|
|
|
self.stp = module.params['stp']
|
|
|
|
self.priority = module.params['priority']
|
|
|
|
self.mode = module.params['mode']
|
|
|
|
self.miimon = module.params['miimon']
|
|
|
|
self.primary = module.params['primary']
|
|
|
|
self.downdelay = module.params['downdelay']
|
|
|
|
self.updelay = module.params['updelay']
|
2022-09-08 07:45:23 +02:00
|
|
|
self.xmit_hash_policy = module.params['xmit_hash_policy']
|
2020-03-09 10:11:07 +01:00
|
|
|
self.arp_interval = module.params['arp_interval']
|
|
|
|
self.arp_ip_target = module.params['arp_ip_target']
|
|
|
|
self.slavepriority = module.params['slavepriority']
|
|
|
|
self.forwarddelay = module.params['forwarddelay']
|
|
|
|
self.hellotime = module.params['hellotime']
|
|
|
|
self.maxage = module.params['maxage']
|
|
|
|
self.ageingtime = module.params['ageingtime']
|
2023-04-26 07:32:00 +02:00
|
|
|
self.hairpin = module.params['hairpin']
|
2020-03-09 10:11:07 +01:00
|
|
|
self.path_cost = module.params['path_cost']
|
|
|
|
self.mac = module.params['mac']
|
2021-07-14 08:24:27 +02:00
|
|
|
self.runner = module.params['runner']
|
|
|
|
self.runner_hwaddr_policy = module.params['runner_hwaddr_policy']
|
2023-03-26 09:27:00 +02:00
|
|
|
self.runner_fast_rate = module.params['runner_fast_rate']
|
2020-03-09 10:11:07 +01:00
|
|
|
self.vlanid = module.params['vlanid']
|
|
|
|
self.vlandev = module.params['vlandev']
|
|
|
|
self.flags = module.params['flags']
|
|
|
|
self.ingress = module.params['ingress']
|
|
|
|
self.egress = module.params['egress']
|
|
|
|
self.vxlan_id = module.params['vxlan_id']
|
|
|
|
self.vxlan_local = module.params['vxlan_local']
|
|
|
|
self.vxlan_remote = module.params['vxlan_remote']
|
|
|
|
self.ip_tunnel_dev = module.params['ip_tunnel_dev']
|
|
|
|
self.ip_tunnel_local = module.params['ip_tunnel_local']
|
|
|
|
self.ip_tunnel_remote = module.params['ip_tunnel_remote']
|
2021-08-26 08:16:36 +02:00
|
|
|
self.ip_tunnel_input_key = module.params['ip_tunnel_input_key']
|
|
|
|
self.ip_tunnel_output_key = module.params['ip_tunnel_output_key']
|
2020-03-09 10:11:07 +01:00
|
|
|
self.nmcli_bin = self.module.get_bin_path('nmcli', True)
|
|
|
|
self.dhcp_client_id = module.params['dhcp_client_id']
|
2020-12-05 16:18:29 +01:00
|
|
|
self.zone = module.params['zone']
|
2021-04-18 10:59:23 +02:00
|
|
|
self.ssid = module.params['ssid']
|
2021-08-04 08:16:11 +02:00
|
|
|
self.wifi = module.params['wifi']
|
2021-04-18 10:59:23 +02:00
|
|
|
self.wifi_sec = module.params['wifi_sec']
|
2021-09-05 18:28:04 +02:00
|
|
|
self.gsm = module.params['gsm']
|
2023-04-16 13:22:11 +02:00
|
|
|
self.macvlan = module.params['macvlan']
|
2022-01-08 14:13:50 +01:00
|
|
|
self.wireguard = module.params['wireguard']
|
2022-06-06 21:16:27 +02:00
|
|
|
self.vpn = module.params['vpn']
|
2022-10-23 11:30:48 +02:00
|
|
|
self.transport_mode = module.params['transport_mode']
|
2020-03-09 10:11:07 +01:00
|
|
|
|
2021-03-02 12:46:21 +01:00
|
|
|
if self.method4:
|
|
|
|
self.ipv4_method = self.method4
|
2023-04-16 13:22:11 +02:00
|
|
|
elif self.type in ('dummy', 'macvlan', 'wireguard') and not self.ip4:
|
2021-08-05 14:25:42 +02:00
|
|
|
self.ipv4_method = 'disabled'
|
2021-03-02 12:46:21 +01:00
|
|
|
elif self.ip4:
|
2020-06-30 05:43:39 +02:00
|
|
|
self.ipv4_method = 'manual'
|
|
|
|
else:
|
|
|
|
self.ipv4_method = None
|
|
|
|
|
2021-03-02 12:46:21 +01:00
|
|
|
if self.method6:
|
|
|
|
self.ipv6_method = self.method6
|
2023-04-16 13:22:11 +02:00
|
|
|
elif self.type in ('dummy', 'macvlan', 'wireguard') and not self.ip6:
|
2021-08-05 14:25:42 +02:00
|
|
|
self.ipv6_method = 'disabled'
|
2021-03-02 12:46:21 +01:00
|
|
|
elif self.ip6:
|
2020-06-30 05:43:39 +02:00
|
|
|
self.ipv6_method = 'manual'
|
|
|
|
else:
|
|
|
|
self.ipv6_method = None
|
|
|
|
|
2021-08-08 18:35:52 +02:00
|
|
|
self.edit_commands = []
|
|
|
|
|
2023-05-08 19:44:30 +02:00
|
|
|
self.extra_options_validation()
|
|
|
|
|
|
|
|
def extra_options_validation(self):
|
|
|
|
""" Additional validation of options set passed to module that cannot be implemented in module's argspecs. """
|
|
|
|
if self.type not in ("bridge-slave", "team-slave", "bond-slave"):
|
|
|
|
if self.master is None and self.slave_type is not None:
|
|
|
|
self.module.fail_json(msg="'master' option is required when 'slave_type' is specified.")
|
|
|
|
|
2020-03-09 10:11:07 +01:00
|
|
|
def execute_command(self, cmd, use_unsafe_shell=False, data=None):
|
2020-06-15 13:32:55 +02:00
|
|
|
if isinstance(cmd, list):
|
|
|
|
cmd = [to_text(item) for item in cmd]
|
|
|
|
else:
|
|
|
|
cmd = to_text(cmd)
|
2020-03-09 10:11:07 +01:00
|
|
|
return self.module.run_command(cmd, use_unsafe_shell=use_unsafe_shell, data=data)
|
|
|
|
|
2021-08-20 21:45:30 +02:00
|
|
|
def execute_edit_commands(self, commands, arguments):
|
|
|
|
arguments = arguments or []
|
|
|
|
cmd = [self.nmcli_bin, 'con', 'edit'] + arguments
|
|
|
|
data = "\n".join(commands)
|
|
|
|
return self.execute_command(cmd, data=data)
|
|
|
|
|
2020-10-23 07:13:39 +02:00
|
|
|
def connection_options(self, detect_change=False):
|
|
|
|
# Options common to multiple connection types.
|
|
|
|
options = {
|
|
|
|
'connection.autoconnect': self.autoconnect,
|
2020-12-05 16:18:29 +01:00
|
|
|
'connection.zone': self.zone,
|
2020-10-23 07:13:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# IP address options.
|
2024-04-09 08:01:00 +02:00
|
|
|
# The ovs-interface type can be both ip_conn_type and have a master
|
|
|
|
if (self.ip_conn_type and not self.master) or self.type == "ovs-interface":
|
2020-10-23 07:13:39 +02:00
|
|
|
options.update({
|
2021-11-28 21:09:49 +01:00
|
|
|
'ipv4.addresses': self.enforce_ipv4_cidr_notation(self.ip4),
|
2020-10-23 07:13:39 +02:00
|
|
|
'ipv4.dhcp-client-id': self.dhcp_client_id,
|
|
|
|
'ipv4.dns': self.dns4,
|
|
|
|
'ipv4.dns-search': self.dns4_search,
|
2023-07-13 22:26:42 +02:00
|
|
|
'ipv4.dns-options': self.dns4_options,
|
2021-06-01 22:04:09 +02:00
|
|
|
'ipv4.ignore-auto-dns': self.dns4_ignore_auto,
|
2020-10-23 07:13:39 +02:00
|
|
|
'ipv4.gateway': self.gw4,
|
2021-06-01 22:04:09 +02:00
|
|
|
'ipv4.ignore-auto-routes': self.gw4_ignore_auto,
|
2022-04-05 06:58:02 +02:00
|
|
|
'ipv4.routes': self.enforce_routes_format(self.routes4, self.routes4_extended),
|
2020-12-01 20:39:56 +01:00
|
|
|
'ipv4.route-metric': self.route_metric4,
|
2021-06-19 14:42:05 +02:00
|
|
|
'ipv4.routing-rules': self.routing_rules4,
|
2020-12-01 20:39:56 +01:00
|
|
|
'ipv4.never-default': self.never_default4,
|
2020-10-23 07:13:39 +02:00
|
|
|
'ipv4.method': self.ipv4_method,
|
2021-06-19 14:42:05 +02:00
|
|
|
'ipv4.may-fail': self.may_fail4,
|
2021-11-28 21:09:49 +01:00
|
|
|
'ipv6.addresses': self.enforce_ipv6_cidr_notation(self.ip6),
|
2020-10-23 07:13:39 +02:00
|
|
|
'ipv6.dns': self.dns6,
|
|
|
|
'ipv6.dns-search': self.dns6_search,
|
2023-07-13 22:26:42 +02:00
|
|
|
'ipv6.dns-options': self.dns6_options,
|
2021-06-01 22:04:09 +02:00
|
|
|
'ipv6.ignore-auto-dns': self.dns6_ignore_auto,
|
2020-10-23 07:13:39 +02:00
|
|
|
'ipv6.gateway': self.gw6,
|
2021-06-01 22:04:09 +02:00
|
|
|
'ipv6.ignore-auto-routes': self.gw6_ignore_auto,
|
2022-04-05 06:58:02 +02:00
|
|
|
'ipv6.routes': self.enforce_routes_format(self.routes6, self.routes6_extended),
|
2022-01-23 13:02:03 +01:00
|
|
|
'ipv6.route-metric': self.route_metric6,
|
2020-10-23 07:13:39 +02:00
|
|
|
'ipv6.method': self.ipv6_method,
|
2021-12-04 18:41:14 +01:00
|
|
|
'ipv6.ip6-privacy': self.ip_privacy6,
|
|
|
|
'ipv6.addr-gen-mode': self.addr_gen_mode6
|
2020-10-23 07:13:39 +02:00
|
|
|
})
|
2023-03-26 09:28:06 +02:00
|
|
|
# when 'method' is disabled the 'may_fail' no make sense but accepted by nmcli with keeping 'yes'
|
|
|
|
# force ignoring to save idempotency
|
|
|
|
if self.ipv4_method and self.ipv4_method != 'disabled':
|
|
|
|
options.update({'ipv4.may-fail': self.may_fail4})
|
2020-10-23 07:13:39 +02:00
|
|
|
|
|
|
|
# Layer 2 options.
|
2021-04-19 19:02:48 +02:00
|
|
|
if self.mac:
|
2020-10-23 07:13:39 +02:00
|
|
|
options.update({self.mac_setting: self.mac})
|
|
|
|
|
|
|
|
if self.mtu_conn_type:
|
|
|
|
options.update({self.mtu_setting: self.mtu})
|
|
|
|
|
|
|
|
# Connections that can have a master.
|
|
|
|
if self.slave_conn_type:
|
|
|
|
options.update({
|
|
|
|
'connection.master': self.master,
|
2023-05-08 19:44:30 +02:00
|
|
|
'connection.slave-type': self.slave_type,
|
2020-10-23 07:13:39 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
# Options specific to a connection type.
|
|
|
|
if self.type == 'bond':
|
|
|
|
options.update({
|
|
|
|
'arp-interval': self.arp_interval,
|
|
|
|
'arp-ip-target': self.arp_ip_target,
|
|
|
|
'downdelay': self.downdelay,
|
|
|
|
'miimon': self.miimon,
|
|
|
|
'mode': self.mode,
|
|
|
|
'primary': self.primary,
|
|
|
|
'updelay': self.updelay,
|
2022-09-08 07:45:23 +02:00
|
|
|
'xmit_hash_policy': self.xmit_hash_policy,
|
2020-10-23 07:13:39 +02:00
|
|
|
})
|
Fix: nmcli - Ensure slave-type for bond-slave (#1882)
* Fix: nmcli - Ensure slave-type for bond-slave
Hello 🙂
When using bond-slave type, by default command sent to nmcl is:
['/usr/bin/nmcli', 'con', 'add', 'type', 'bond-slave', 'con-name', 'enp129s0f0', 'connection.interface-name', 'enp129s0f0', 'connection.autoconnect', 'yes', 'connection.master', 'bond0']
Which is not enough, nmcli will complain that connection.slave-type is missing. This small fix solve this issue.
If this change is approved, I will add the changelog fragment.
* Fix: nmcli - Adding changelog fragment for 1882
* Update changelogs/fragments/1882-fix-nmcli-ensure-slave-type-for-bond-slave.yml
Co-authored-by: Felix Fontein <felix@fontein.de>
Co-authored-by: Felix Fontein <felix@fontein.de>
2021-03-04 07:49:38 +01:00
|
|
|
elif self.type == 'bond-slave':
|
2023-05-08 19:44:30 +02:00
|
|
|
if self.slave_type and self.slave_type != 'bond':
|
|
|
|
self.module.fail_json(msg="Connection type '%s' cannot be combined with '%s' slave-type. "
|
|
|
|
"Allowed slave-type for '%s' is 'bond'."
|
|
|
|
% (self.type, self.slave_type, self.type)
|
|
|
|
)
|
|
|
|
if not self.slave_type:
|
|
|
|
self.module.warn("Connection 'slave-type' property automatically set to 'bond' "
|
|
|
|
"because of using 'bond-slave' connection type.")
|
|
|
|
options.update({
|
|
|
|
'connection.slave-type': 'bond',
|
|
|
|
})
|
2020-10-23 07:13:39 +02:00
|
|
|
elif self.type == 'bridge':
|
|
|
|
options.update({
|
|
|
|
'bridge.ageing-time': self.ageingtime,
|
|
|
|
'bridge.forward-delay': self.forwarddelay,
|
|
|
|
'bridge.hello-time': self.hellotime,
|
|
|
|
'bridge.max-age': self.maxage,
|
|
|
|
'bridge.priority': self.priority,
|
|
|
|
'bridge.stp': self.stp,
|
|
|
|
})
|
2023-10-25 23:01:32 +02:00
|
|
|
# priority make sense when stp enabled, otherwise nmcli keeps bridge-priority to 32768 regrdless of input.
|
2023-03-26 09:28:51 +02:00
|
|
|
# force ignoring to save idempotency
|
|
|
|
if self.stp:
|
|
|
|
options.update({'bridge.priority': self.priority})
|
2021-07-14 08:24:27 +02:00
|
|
|
elif self.type == 'team':
|
|
|
|
options.update({
|
|
|
|
'team.runner': self.runner,
|
|
|
|
'team.runner-hwaddr-policy': self.runner_hwaddr_policy,
|
|
|
|
})
|
2023-03-26 09:27:00 +02:00
|
|
|
if self.runner_fast_rate is not None:
|
|
|
|
options.update({
|
|
|
|
'team.runner-fast-rate': self.runner_fast_rate,
|
|
|
|
})
|
2020-10-23 07:13:39 +02:00
|
|
|
elif self.type == 'bridge-slave':
|
2023-05-08 19:44:30 +02:00
|
|
|
if self.slave_type and self.slave_type != 'bridge':
|
|
|
|
self.module.fail_json(msg="Connection type '%s' cannot be combined with '%s' slave-type. "
|
|
|
|
"Allowed slave-type for '%s' is 'bridge'."
|
|
|
|
% (self.type, self.slave_type, self.type)
|
|
|
|
)
|
|
|
|
if not self.slave_type:
|
|
|
|
self.module.warn("Connection 'slave-type' property automatically set to 'bridge' "
|
|
|
|
"because of using 'bridge-slave' connection type.")
|
|
|
|
options.update({'connection.slave-type': 'bridge'})
|
|
|
|
self.module.warn(
|
|
|
|
"Connection type as 'bridge-slave' implies 'ethernet' connection with 'bridge' slave-type. "
|
|
|
|
"Consider using slave_type='bridge' with necessary type."
|
|
|
|
)
|
2020-10-23 07:13:39 +02:00
|
|
|
options.update({
|
|
|
|
'bridge-port.path-cost': self.path_cost,
|
|
|
|
'bridge-port.hairpin-mode': self.hairpin,
|
|
|
|
'bridge-port.priority': self.slavepriority,
|
|
|
|
})
|
2021-06-28 20:46:44 +02:00
|
|
|
elif self.type == 'team-slave':
|
2023-05-08 19:44:30 +02:00
|
|
|
if self.slave_type and self.slave_type != 'team':
|
|
|
|
self.module.fail_json(msg="Connection type '%s' cannot be combined with '%s' slave-type. "
|
|
|
|
"Allowed slave-type for '%s' is 'team'."
|
|
|
|
% (self.type, self.slave_type, self.type)
|
|
|
|
)
|
|
|
|
if not self.slave_type:
|
|
|
|
self.module.warn("Connection 'slave-type' property automatically set to 'team' "
|
|
|
|
"because of using 'team-slave' connection type.")
|
|
|
|
options.update({
|
|
|
|
'connection.slave-type': 'team',
|
|
|
|
})
|
2020-10-23 07:13:39 +02:00
|
|
|
elif self.tunnel_conn_type:
|
|
|
|
options.update({
|
|
|
|
'ip-tunnel.local': self.ip_tunnel_local,
|
|
|
|
'ip-tunnel.mode': self.type,
|
|
|
|
'ip-tunnel.parent': self.ip_tunnel_dev,
|
|
|
|
'ip-tunnel.remote': self.ip_tunnel_remote,
|
|
|
|
})
|
2021-08-26 08:16:36 +02:00
|
|
|
if self.type == 'gre':
|
|
|
|
options.update({
|
|
|
|
'ip-tunnel.input-key': self.ip_tunnel_input_key,
|
|
|
|
'ip-tunnel.output-key': self.ip_tunnel_output_key
|
|
|
|
})
|
2020-10-23 07:13:39 +02:00
|
|
|
elif self.type == 'vlan':
|
|
|
|
options.update({
|
|
|
|
'vlan.id': self.vlanid,
|
|
|
|
'vlan.parent': self.vlandev,
|
2021-12-13 21:43:54 +01:00
|
|
|
'vlan.flags': self.flags,
|
|
|
|
'vlan.ingress': self.ingress,
|
|
|
|
'vlan.egress': self.egress,
|
2020-10-23 07:13:39 +02:00
|
|
|
})
|
|
|
|
elif self.type == 'vxlan':
|
|
|
|
options.update({
|
|
|
|
'vxlan.id': self.vxlan_id,
|
|
|
|
'vxlan.local': self.vxlan_local,
|
|
|
|
'vxlan.remote': self.vxlan_remote,
|
|
|
|
})
|
2021-04-18 10:59:23 +02:00
|
|
|
elif self.type == 'wifi':
|
|
|
|
options.update({
|
2021-08-04 08:16:11 +02:00
|
|
|
'802-11-wireless.ssid': self.ssid,
|
2024-01-28 13:39:43 +01:00
|
|
|
'connection.slave-type': ('bond' if self.slave_type is None else self.slave_type) if self.master else None,
|
2021-04-18 10:59:23 +02:00
|
|
|
})
|
2021-08-04 08:16:11 +02:00
|
|
|
if self.wifi:
|
|
|
|
for name, value in self.wifi.items():
|
|
|
|
options.update({
|
|
|
|
'802-11-wireless.%s' % name: value
|
|
|
|
})
|
2021-08-07 15:20:44 +02:00
|
|
|
if self.wifi_sec:
|
|
|
|
for name, value in self.wifi_sec.items():
|
|
|
|
options.update({
|
|
|
|
'802-11-wireless-security.%s' % name: value
|
|
|
|
})
|
2021-09-05 18:28:04 +02:00
|
|
|
elif self.type == 'gsm':
|
|
|
|
if self.gsm:
|
|
|
|
for name, value in self.gsm.items():
|
|
|
|
options.update({
|
|
|
|
'gsm.%s' % name: value,
|
|
|
|
})
|
2023-04-16 13:22:11 +02:00
|
|
|
elif self.type == 'macvlan':
|
|
|
|
if self.macvlan:
|
|
|
|
for name, value in self.macvlan.items():
|
|
|
|
options.update({
|
|
|
|
'macvlan.%s' % name: value,
|
|
|
|
})
|
|
|
|
elif self.state == 'present':
|
|
|
|
raise NmcliModuleError('type is macvlan but all of the following are missing: macvlan')
|
2022-01-08 14:13:50 +01:00
|
|
|
elif self.type == 'wireguard':
|
|
|
|
if self.wireguard:
|
|
|
|
for name, value in self.wireguard.items():
|
|
|
|
options.update({
|
|
|
|
'wireguard.%s' % name: value,
|
|
|
|
})
|
2022-06-06 21:16:27 +02:00
|
|
|
elif self.type == 'vpn':
|
|
|
|
if self.vpn:
|
|
|
|
vpn_data_values = ''
|
|
|
|
for name, value in self.vpn.items():
|
|
|
|
if name == 'service-type':
|
|
|
|
options.update({
|
2022-09-03 12:02:03 +02:00
|
|
|
'vpn.service-type': value,
|
2022-06-06 21:16:27 +02:00
|
|
|
})
|
|
|
|
elif name == 'permissions':
|
|
|
|
options.update({
|
|
|
|
'connection.permissions': value,
|
|
|
|
})
|
|
|
|
else:
|
|
|
|
if vpn_data_values != '':
|
|
|
|
vpn_data_values += ', '
|
|
|
|
|
|
|
|
if isinstance(value, bool):
|
|
|
|
value = self.bool_to_string(value)
|
|
|
|
|
|
|
|
vpn_data_values += '%s=%s' % (name, value)
|
|
|
|
options.update({
|
|
|
|
'vpn.data': vpn_data_values,
|
|
|
|
})
|
2022-10-23 11:30:48 +02:00
|
|
|
elif self.type == 'infiniband':
|
|
|
|
options.update({
|
|
|
|
'infiniband.transport-mode': self.transport_mode,
|
|
|
|
})
|
|
|
|
|
2020-10-23 07:13:39 +02:00
|
|
|
# Convert settings values based on the situation.
|
|
|
|
for setting, value in options.items():
|
|
|
|
setting_type = self.settings_type(setting)
|
|
|
|
convert_func = None
|
|
|
|
if setting_type is bool:
|
|
|
|
# Convert all bool options to yes/no.
|
|
|
|
convert_func = self.bool_to_string
|
|
|
|
if detect_change:
|
|
|
|
if setting in ('vlan.id', 'vxlan.id'):
|
|
|
|
# Convert VLAN/VXLAN IDs to text when detecting changes.
|
|
|
|
convert_func = to_text
|
|
|
|
elif setting == self.mtu_setting:
|
|
|
|
# MTU is 'auto' by default when detecting changes.
|
|
|
|
convert_func = self.mtu_to_string
|
2021-12-04 18:41:14 +01:00
|
|
|
elif setting == 'ipv6.ip6-privacy':
|
|
|
|
convert_func = self.ip6_privacy_to_num
|
2020-10-23 07:13:39 +02:00
|
|
|
elif setting_type is list:
|
|
|
|
# Convert lists to strings for nmcli create/modify commands.
|
|
|
|
convert_func = self.list_to_string
|
|
|
|
|
|
|
|
if callable(convert_func):
|
|
|
|
options[setting] = convert_func(options[setting])
|
|
|
|
|
|
|
|
return options
|
|
|
|
|
|
|
|
@property
|
|
|
|
def ip_conn_type(self):
|
|
|
|
return self.type in (
|
|
|
|
'bond',
|
|
|
|
'bridge',
|
2021-08-05 14:25:42 +02:00
|
|
|
'dummy',
|
2020-10-23 07:13:39 +02:00
|
|
|
'ethernet',
|
2022-03-06 08:56:44 +01:00
|
|
|
'802-3-ethernet',
|
2020-10-23 07:13:39 +02:00
|
|
|
'generic',
|
2021-08-26 08:16:36 +02:00
|
|
|
'gre',
|
2020-12-01 20:39:56 +01:00
|
|
|
'infiniband',
|
2021-08-23 06:24:05 +02:00
|
|
|
'ipip',
|
|
|
|
'sit',
|
2020-10-23 07:13:39 +02:00
|
|
|
'team',
|
|
|
|
'vlan',
|
2021-09-05 18:28:04 +02:00
|
|
|
'wifi',
|
2022-03-06 08:56:44 +01:00
|
|
|
'802-11-wireless',
|
2021-09-05 18:28:04 +02:00
|
|
|
'gsm',
|
2023-04-16 13:22:11 +02:00
|
|
|
'macvlan',
|
2022-01-08 14:13:50 +01:00
|
|
|
'wireguard',
|
2022-09-08 07:44:54 +02:00
|
|
|
'vpn',
|
2023-11-22 09:26:04 +01:00
|
|
|
'loopback',
|
2024-04-09 08:01:00 +02:00
|
|
|
'ovs-interface',
|
2020-10-23 07:13:39 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def mac_setting(self):
|
|
|
|
if self.type == 'bridge':
|
|
|
|
return 'bridge.mac-address'
|
|
|
|
else:
|
|
|
|
return '802-3-ethernet.cloned-mac-address'
|
|
|
|
|
|
|
|
@property
|
|
|
|
def mtu_conn_type(self):
|
|
|
|
return self.type in (
|
2023-11-15 22:13:22 +01:00
|
|
|
'bond',
|
2024-03-24 18:26:34 +01:00
|
|
|
'bond-slave',
|
2021-08-05 14:25:42 +02:00
|
|
|
'dummy',
|
2020-10-23 07:13:39 +02:00
|
|
|
'ethernet',
|
2023-11-15 22:13:22 +01:00
|
|
|
'infiniband',
|
2020-10-23 07:13:39 +02:00
|
|
|
'team-slave',
|
2023-03-04 10:01:52 +01:00
|
|
|
'vlan',
|
2020-10-23 07:13:39 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def mtu_setting(self):
|
2023-11-15 22:13:22 +01:00
|
|
|
if self.type == 'infiniband':
|
|
|
|
return 'infiniband.mtu'
|
|
|
|
else:
|
|
|
|
return '802-3-ethernet.mtu'
|
2020-10-23 07:13:39 +02:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def mtu_to_string(mtu):
|
|
|
|
if not mtu:
|
|
|
|
return 'auto'
|
|
|
|
else:
|
|
|
|
return to_text(mtu)
|
|
|
|
|
2021-12-04 18:41:14 +01:00
|
|
|
@staticmethod
|
|
|
|
def ip6_privacy_to_num(privacy):
|
|
|
|
ip6_privacy_values = {
|
|
|
|
'disabled': '0',
|
|
|
|
'prefer-public-addr': '1 (enabled, prefer public IP)',
|
|
|
|
'prefer-temp-addr': '2 (enabled, prefer temporary IP)',
|
|
|
|
'unknown': '-1',
|
|
|
|
}
|
|
|
|
|
|
|
|
if privacy is None:
|
|
|
|
return None
|
|
|
|
|
|
|
|
if privacy not in ip6_privacy_values:
|
|
|
|
raise AssertionError('{privacy} is invalid ip_privacy6 option'.format(privacy=privacy))
|
|
|
|
|
|
|
|
return ip6_privacy_values[privacy]
|
|
|
|
|
2020-10-23 07:13:39 +02:00
|
|
|
@property
|
|
|
|
def slave_conn_type(self):
|
|
|
|
return self.type in (
|
2023-05-08 19:44:30 +02:00
|
|
|
'ethernet',
|
|
|
|
'bridge',
|
|
|
|
'bond',
|
|
|
|
'vlan',
|
|
|
|
'team',
|
|
|
|
'wifi',
|
2020-10-23 07:13:39 +02:00
|
|
|
'bond-slave',
|
|
|
|
'bridge-slave',
|
|
|
|
'team-slave',
|
2021-04-18 10:59:23 +02:00
|
|
|
'wifi',
|
2023-11-29 13:27:18 +01:00
|
|
|
'infiniband',
|
2024-04-09 08:01:00 +02:00
|
|
|
'ovs-port',
|
|
|
|
'ovs-interface',
|
2020-10-23 07:13:39 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def tunnel_conn_type(self):
|
|
|
|
return self.type in (
|
2021-08-26 08:16:36 +02:00
|
|
|
'gre',
|
2020-10-23 07:13:39 +02:00
|
|
|
'ipip',
|
|
|
|
'sit',
|
|
|
|
)
|
2020-03-09 10:11:07 +01:00
|
|
|
|
2021-11-28 21:09:49 +01:00
|
|
|
@staticmethod
|
|
|
|
def enforce_ipv4_cidr_notation(ip4_addresses):
|
|
|
|
if ip4_addresses is None:
|
|
|
|
return None
|
|
|
|
return [address if '/' in address else address + '/32' for address in ip4_addresses]
|
|
|
|
|
|
|
|
@staticmethod
|
2021-12-09 21:17:32 +01:00
|
|
|
def enforce_ipv6_cidr_notation(ip6_addresses):
|
|
|
|
if ip6_addresses is None:
|
2021-11-28 21:09:49 +01:00
|
|
|
return None
|
2021-12-09 21:17:32 +01:00
|
|
|
return [address if '/' in address else address + '/128' for address in ip6_addresses]
|
2021-11-28 21:09:49 +01:00
|
|
|
|
2022-04-05 06:58:02 +02:00
|
|
|
def enforce_routes_format(self, routes, routes_extended):
|
|
|
|
if routes is not None:
|
|
|
|
return routes
|
|
|
|
elif routes_extended is not None:
|
|
|
|
return [self.route_to_string(route) for route in routes_extended]
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def route_to_string(route):
|
|
|
|
result_str = ''
|
|
|
|
result_str += route['ip']
|
|
|
|
if route.get('next_hop') is not None:
|
|
|
|
result_str += ' ' + route['next_hop']
|
|
|
|
if route.get('metric') is not None:
|
|
|
|
result_str += ' ' + str(route['metric'])
|
|
|
|
|
|
|
|
for attribute, value in sorted(route.items()):
|
|
|
|
if attribute not in ('ip', 'next_hop', 'metric') and value is not None:
|
|
|
|
result_str += ' {0}={1}'.format(attribute, str(value).lower())
|
|
|
|
|
|
|
|
return result_str
|
|
|
|
|
2020-03-09 10:11:07 +01:00
|
|
|
@staticmethod
|
|
|
|
def bool_to_string(boolean):
|
|
|
|
if boolean:
|
|
|
|
return "yes"
|
|
|
|
else:
|
|
|
|
return "no"
|
|
|
|
|
2020-10-23 07:13:39 +02:00
|
|
|
@staticmethod
|
|
|
|
def list_to_string(lst):
|
2022-06-13 11:56:10 +02:00
|
|
|
if lst is None:
|
|
|
|
return None
|
|
|
|
else:
|
|
|
|
return ",".join(lst)
|
2020-10-23 07:13:39 +02:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def settings_type(setting):
|
|
|
|
if setting in ('bridge.stp',
|
|
|
|
'bridge-port.hairpin-mode',
|
2020-12-01 20:39:56 +01:00
|
|
|
'connection.autoconnect',
|
2021-06-01 22:04:09 +02:00
|
|
|
'ipv4.never-default',
|
|
|
|
'ipv4.ignore-auto-dns',
|
|
|
|
'ipv4.ignore-auto-routes',
|
2021-06-19 14:42:05 +02:00
|
|
|
'ipv4.may-fail',
|
2021-06-01 22:04:09 +02:00
|
|
|
'ipv6.ignore-auto-dns',
|
2021-08-04 08:16:11 +02:00
|
|
|
'ipv6.ignore-auto-routes',
|
2023-03-26 09:27:00 +02:00
|
|
|
'802-11-wireless.hidden',
|
|
|
|
'team.runner-fast-rate'):
|
2020-10-23 07:13:39 +02:00
|
|
|
return bool
|
2021-11-19 07:07:35 +01:00
|
|
|
elif setting in ('ipv4.addresses',
|
2021-12-09 21:17:32 +01:00
|
|
|
'ipv6.addresses',
|
2021-11-19 07:07:35 +01:00
|
|
|
'ipv4.dns',
|
2020-10-23 07:13:39 +02:00
|
|
|
'ipv4.dns-search',
|
2023-07-13 22:26:42 +02:00
|
|
|
'ipv4.dns-options',
|
2020-12-01 20:39:56 +01:00
|
|
|
'ipv4.routes',
|
2021-09-29 06:49:49 +02:00
|
|
|
'ipv4.routing-rules',
|
2020-10-23 07:13:39 +02:00
|
|
|
'ipv6.dns',
|
2021-08-20 21:45:30 +02:00
|
|
|
'ipv6.dns-search',
|
2023-07-13 22:26:42 +02:00
|
|
|
'ipv6.dns-options',
|
2022-01-23 13:02:03 +01:00
|
|
|
'ipv6.routes',
|
2021-08-20 21:45:30 +02:00
|
|
|
'802-11-wireless-security.group',
|
|
|
|
'802-11-wireless-security.leap-password-flags',
|
|
|
|
'802-11-wireless-security.pairwise',
|
|
|
|
'802-11-wireless-security.proto',
|
|
|
|
'802-11-wireless-security.psk-flags',
|
|
|
|
'802-11-wireless-security.wep-key-flags',
|
|
|
|
'802-11-wireless.mac-address-blacklist'):
|
2020-10-23 07:13:39 +02:00
|
|
|
return list
|
|
|
|
return str
|
|
|
|
|
2022-04-05 06:58:02 +02:00
|
|
|
def get_route_params(self, raw_values):
|
|
|
|
routes_params = []
|
|
|
|
for raw_value in raw_values:
|
|
|
|
route_params = {}
|
|
|
|
for parameter, value in re.findall(r'([\w-]*)\s?=\s?([^\s,}]*)', raw_value):
|
|
|
|
if parameter == 'nh':
|
|
|
|
route_params['next_hop'] = value
|
|
|
|
elif parameter == 'mt':
|
|
|
|
route_params['metric'] = value
|
|
|
|
else:
|
|
|
|
route_params[parameter] = value
|
|
|
|
routes_params.append(route_params)
|
|
|
|
return [self.route_to_string(route_params) for route_params in routes_params]
|
|
|
|
|
2020-03-09 10:11:07 +01:00
|
|
|
def list_connection_info(self):
|
2020-10-23 07:13:39 +02:00
|
|
|
cmd = [self.nmcli_bin, '--fields', 'name', '--terse', 'con', 'show']
|
|
|
|
(rc, out, err) = self.execute_command(cmd)
|
|
|
|
if rc != 0:
|
|
|
|
raise NmcliModuleError(err)
|
|
|
|
return out.splitlines()
|
2020-03-09 10:11:07 +01:00
|
|
|
|
|
|
|
def connection_exists(self):
|
2020-10-23 07:13:39 +02:00
|
|
|
return self.conn_name in self.list_connection_info()
|
2020-03-09 10:11:07 +01:00
|
|
|
|
|
|
|
def down_connection(self):
|
|
|
|
cmd = [self.nmcli_bin, 'con', 'down', self.conn_name]
|
|
|
|
return self.execute_command(cmd)
|
|
|
|
|
|
|
|
def up_connection(self):
|
|
|
|
cmd = [self.nmcli_bin, 'con', 'up', self.conn_name]
|
|
|
|
return self.execute_command(cmd)
|
|
|
|
|
2020-10-23 07:13:39 +02:00
|
|
|
def connection_update(self, nmcli_command):
|
|
|
|
if nmcli_command == 'create':
|
|
|
|
cmd = [self.nmcli_bin, 'con', 'add', 'type']
|
|
|
|
if self.tunnel_conn_type:
|
|
|
|
cmd.append('ip-tunnel')
|
|
|
|
else:
|
|
|
|
cmd.append(self.type)
|
|
|
|
cmd.append('con-name')
|
|
|
|
elif nmcli_command == 'modify':
|
|
|
|
cmd = [self.nmcli_bin, 'con', 'modify']
|
|
|
|
else:
|
|
|
|
self.module.fail_json(msg="Invalid nmcli command.")
|
|
|
|
cmd.append(self.conn_name)
|
2020-03-09 10:11:07 +01:00
|
|
|
|
2020-10-23 07:13:39 +02:00
|
|
|
# Use connection name as default for interface name on creation.
|
|
|
|
if nmcli_command == 'create' and self.ifname is None:
|
|
|
|
ifname = self.conn_name
|
|
|
|
else:
|
|
|
|
ifname = self.ifname
|
2020-03-09 10:11:07 +01:00
|
|
|
|
|
|
|
options = {
|
2020-10-23 07:13:39 +02:00
|
|
|
'connection.interface-name': ifname,
|
2020-03-09 10:11:07 +01:00
|
|
|
}
|
|
|
|
|
2022-06-06 21:16:27 +02:00
|
|
|
# VPN doesn't need an interface but if sended it must be a valid interface.
|
|
|
|
if self.type == 'vpn' and self.ifname is None:
|
|
|
|
del options['connection.interface-name']
|
|
|
|
|
2020-10-23 07:13:39 +02:00
|
|
|
options.update(self.connection_options())
|
2020-03-09 10:11:07 +01:00
|
|
|
|
2020-10-23 07:13:39 +02:00
|
|
|
# Constructing the command.
|
2020-03-09 10:11:07 +01:00
|
|
|
for key, value in options.items():
|
|
|
|
if value is not None:
|
2021-08-08 18:35:52 +02:00
|
|
|
if key in self.SECRET_OPTIONS:
|
|
|
|
self.edit_commands += ['set %s %s' % (key, value)]
|
|
|
|
continue
|
2023-05-21 17:03:38 +02:00
|
|
|
if key == 'xmit_hash_policy':
|
|
|
|
cmd.extend(['+bond.options', 'xmit_hash_policy=%s' % value])
|
|
|
|
continue
|
2020-03-09 10:11:07 +01:00
|
|
|
cmd.extend([key, value])
|
|
|
|
|
2020-10-23 07:13:39 +02:00
|
|
|
return self.execute_command(cmd)
|
2020-03-09 10:11:07 +01:00
|
|
|
|
|
|
|
def create_connection(self):
|
2020-10-23 07:13:39 +02:00
|
|
|
status = self.connection_update('create')
|
2021-08-08 18:35:52 +02:00
|
|
|
if status[0] == 0 and self.edit_commands:
|
|
|
|
status = self.edit_connection()
|
2020-10-23 07:13:39 +02:00
|
|
|
if self.create_connection_up:
|
|
|
|
status = self.up_connection()
|
|
|
|
return status
|
|
|
|
|
|
|
|
@property
|
|
|
|
def create_connection_up(self):
|
2021-08-05 14:25:42 +02:00
|
|
|
if self.type in ('bond', 'dummy', 'ethernet', 'infiniband', 'wifi'):
|
2020-03-09 10:11:07 +01:00
|
|
|
if (self.mtu is not None) or (self.dns4 is not None) or (self.dns6 is not None):
|
2020-10-23 07:13:39 +02:00
|
|
|
return True
|
|
|
|
elif self.type == 'team':
|
|
|
|
if (self.dns4 is not None) or (self.dns6 is not None):
|
|
|
|
return True
|
|
|
|
return False
|
2020-03-09 10:11:07 +01:00
|
|
|
|
|
|
|
def remove_connection(self):
|
|
|
|
# self.down_connection()
|
|
|
|
cmd = [self.nmcli_bin, 'con', 'del', self.conn_name]
|
|
|
|
return self.execute_command(cmd)
|
|
|
|
|
|
|
|
def modify_connection(self):
|
2021-08-08 18:35:52 +02:00
|
|
|
status = self.connection_update('modify')
|
|
|
|
if status[0] == 0 and self.edit_commands:
|
|
|
|
status = self.edit_connection()
|
|
|
|
return status
|
|
|
|
|
|
|
|
def edit_connection(self):
|
2021-08-20 21:45:30 +02:00
|
|
|
commands = self.edit_commands + ['save', 'quit']
|
|
|
|
return self.execute_edit_commands(commands, arguments=[self.conn_name])
|
2020-03-09 10:11:07 +01:00
|
|
|
|
2020-06-30 05:43:39 +02:00
|
|
|
def show_connection(self):
|
2021-08-07 15:20:44 +02:00
|
|
|
cmd = [self.nmcli_bin, '--show-secrets', 'con', 'show', self.conn_name]
|
2020-06-30 05:43:39 +02:00
|
|
|
|
|
|
|
(rc, out, err) = self.execute_command(cmd)
|
|
|
|
|
|
|
|
if rc != 0:
|
|
|
|
raise NmcliModuleError(err)
|
|
|
|
|
|
|
|
p_enum_value = re.compile(r'^([-]?\d+) \((\w+)\)$')
|
|
|
|
|
|
|
|
conn_info = dict()
|
|
|
|
for line in out.splitlines():
|
|
|
|
pair = line.split(':', 1)
|
|
|
|
key = pair[0].strip()
|
2020-10-23 07:13:39 +02:00
|
|
|
key_type = self.settings_type(key)
|
2020-06-30 05:43:39 +02:00
|
|
|
if key and len(pair) > 1:
|
|
|
|
raw_value = pair[1].lstrip()
|
|
|
|
if raw_value == '--':
|
2023-07-06 21:06:24 +02:00
|
|
|
if key_type == list:
|
|
|
|
conn_info[key] = []
|
|
|
|
else:
|
|
|
|
conn_info[key] = None
|
2020-06-30 05:43:39 +02:00
|
|
|
elif key == 'bond.options':
|
|
|
|
# Aliases such as 'miimon', 'downdelay' are equivalent to the +bond.options 'option=value' syntax.
|
|
|
|
opts = raw_value.split(',')
|
|
|
|
for opt in opts:
|
|
|
|
alias_pair = opt.split('=', 1)
|
|
|
|
if len(alias_pair) > 1:
|
|
|
|
alias_key = alias_pair[0]
|
|
|
|
alias_value = alias_pair[1]
|
|
|
|
conn_info[alias_key] = alias_value
|
2022-01-23 13:02:03 +01:00
|
|
|
elif key in ('ipv4.routes', 'ipv6.routes'):
|
2020-12-01 20:39:56 +01:00
|
|
|
conn_info[key] = [s.strip() for s in raw_value.split(';')]
|
2020-10-23 07:13:39 +02:00
|
|
|
elif key_type == list:
|
|
|
|
conn_info[key] = [s.strip() for s in raw_value.split(',')]
|
2020-06-30 05:43:39 +02:00
|
|
|
else:
|
|
|
|
m_enum = p_enum_value.match(raw_value)
|
|
|
|
if m_enum is not None:
|
|
|
|
value = m_enum.group(1)
|
|
|
|
else:
|
|
|
|
value = raw_value
|
|
|
|
conn_info[key] = value
|
|
|
|
|
|
|
|
return conn_info
|
|
|
|
|
2021-08-20 21:45:30 +02:00
|
|
|
def get_supported_properties(self, setting):
|
|
|
|
properties = []
|
|
|
|
|
|
|
|
if setting == '802-11-wireless-security':
|
|
|
|
set_property = 'psk'
|
|
|
|
set_value = 'FAKEVALUE'
|
|
|
|
commands = ['set %s.%s %s' % (setting, set_property, set_value)]
|
|
|
|
else:
|
|
|
|
commands = []
|
|
|
|
|
|
|
|
commands += ['print %s' % setting, 'quit', 'yes']
|
|
|
|
|
|
|
|
(rc, out, err) = self.execute_edit_commands(commands, arguments=['type', self.type])
|
|
|
|
|
|
|
|
if rc != 0:
|
|
|
|
raise NmcliModuleError(err)
|
|
|
|
|
|
|
|
for line in out.splitlines():
|
|
|
|
prefix = '%s.' % setting
|
|
|
|
if (line.startswith(prefix)):
|
|
|
|
pair = line.split(':', 1)
|
|
|
|
property = pair[0].strip().replace(prefix, '')
|
|
|
|
properties.append(property)
|
|
|
|
|
|
|
|
return properties
|
|
|
|
|
|
|
|
def check_for_unsupported_properties(self, setting):
|
|
|
|
if setting == '802-11-wireless':
|
|
|
|
setting_key = 'wifi'
|
|
|
|
elif setting == '802-11-wireless-security':
|
|
|
|
setting_key = 'wifi_sec'
|
|
|
|
else:
|
|
|
|
setting_key = setting
|
|
|
|
|
|
|
|
supported_properties = self.get_supported_properties(setting)
|
|
|
|
unsupported_properties = []
|
|
|
|
|
|
|
|
for property, value in getattr(self, setting_key).items():
|
|
|
|
if property not in supported_properties:
|
|
|
|
unsupported_properties.append(property)
|
|
|
|
|
|
|
|
if unsupported_properties:
|
|
|
|
msg_options = []
|
|
|
|
for property in unsupported_properties:
|
|
|
|
msg_options.append('%s.%s' % (setting_key, property))
|
|
|
|
|
|
|
|
msg = 'Invalid or unsupported option(s): "%s"' % '", "'.join(msg_options)
|
|
|
|
if self.ignore_unsupported_suboptions:
|
|
|
|
self.module.warn(msg)
|
|
|
|
else:
|
|
|
|
self.module.fail_json(msg=msg)
|
|
|
|
|
|
|
|
return unsupported_properties
|
|
|
|
|
2020-06-30 05:43:39 +02:00
|
|
|
def _compare_conn_params(self, conn_info, options):
|
|
|
|
changed = False
|
|
|
|
diff_before = dict()
|
|
|
|
diff_after = dict()
|
|
|
|
|
|
|
|
for key, value in options.items():
|
nmcli: two fixes needed to make wifi.wake-on-wlan settings work properly (#5431)
* nmcli: Convert current value of wifi.wake-on-wlan before comparing
The new value of wifi.wake-on-wlan is specified as an integer, but in
the nmcli output it's specified as a hex string followed by a textual
description of it. Therefore, to determine properly whether it's being
changed we need to pull the hex string out of the current value,
convert it into an integer, and finally convert the integer back to a
string so that we can compare it to the new specified value. Without
this change, whenever wifi.wake-on-wlan is specified in the module
arguments the module will think the value is being changed even when
it isn't.
* nmcli: Handle wifi options correctly when connection type not specified
When an nmcli task does not specify the connection type and the module
ask nmcli for it, the module needs to convert nmcli's
`802-11-wireless` to `wifi`, the term for this connection type used by
the module.
* nmcli: Correctly detect values changed to the integer 0
If the user specifies a value of 0 (without quotes) in a task, we
should interpret that as an actual value, not empty, when comparing
the new value to the old one. Otherwise we incorrectly conclude that
there was no change.
* Changelog fragment for #5431
2023-02-24 09:10:41 +01:00
|
|
|
# We can't just do `if not value` because then if there's a value
|
|
|
|
# of 0 specified as an integer it'll be interpreted as empty when
|
|
|
|
# it actually isn't.
|
2023-07-06 21:06:24 +02:00
|
|
|
if value not in (0, []) and not value:
|
2020-06-30 05:43:39 +02:00
|
|
|
continue
|
|
|
|
|
|
|
|
if key in conn_info:
|
|
|
|
current_value = conn_info[key]
|
nmcli: two fixes needed to make wifi.wake-on-wlan settings work properly (#5431)
* nmcli: Convert current value of wifi.wake-on-wlan before comparing
The new value of wifi.wake-on-wlan is specified as an integer, but in
the nmcli output it's specified as a hex string followed by a textual
description of it. Therefore, to determine properly whether it's being
changed we need to pull the hex string out of the current value,
convert it into an integer, and finally convert the integer back to a
string so that we can compare it to the new specified value. Without
this change, whenever wifi.wake-on-wlan is specified in the module
arguments the module will think the value is being changed even when
it isn't.
* nmcli: Handle wifi options correctly when connection type not specified
When an nmcli task does not specify the connection type and the module
ask nmcli for it, the module needs to convert nmcli's
`802-11-wireless` to `wifi`, the term for this connection type used by
the module.
* nmcli: Correctly detect values changed to the integer 0
If the user specifies a value of 0 (without quotes) in a task, we
should interpret that as an actual value, not empty, when comparing
the new value to the old one. Otherwise we incorrectly conclude that
there was no change.
* Changelog fragment for #5431
2023-02-24 09:10:41 +01:00
|
|
|
if key == '802-11-wireless.wake-on-wlan' and current_value is not None:
|
|
|
|
match = re.match('0x([0-9A-Fa-f]+)', current_value)
|
|
|
|
if match:
|
|
|
|
current_value = str(int(match.group(1), 16))
|
2022-01-23 13:02:03 +01:00
|
|
|
if key in ('ipv4.routes', 'ipv6.routes') and current_value is not None:
|
2022-04-05 06:58:02 +02:00
|
|
|
current_value = self.get_route_params(current_value)
|
2021-05-03 07:28:53 +02:00
|
|
|
if key == self.mac_setting:
|
|
|
|
# MAC addresses are case insensitive, nmcli always reports them in uppercase
|
|
|
|
value = value.upper()
|
|
|
|
# ensure current_value is also converted to uppercase in case nmcli changes behaviour
|
2022-09-28 22:49:07 +02:00
|
|
|
if current_value:
|
|
|
|
current_value = current_value.upper()
|
2021-09-05 18:28:04 +02:00
|
|
|
if key == 'gsm.apn':
|
|
|
|
# Depending on version nmcli adds double-qoutes to gsm.apn
|
|
|
|
# Need to strip them in order to compare both
|
2022-09-28 22:49:07 +02:00
|
|
|
if current_value:
|
|
|
|
current_value = current_value.strip('"')
|
2021-11-10 07:04:24 +01:00
|
|
|
if key == self.mtu_setting and self.mtu is None:
|
|
|
|
self.mtu = 0
|
2022-06-06 21:16:27 +02:00
|
|
|
if key == 'vpn.data':
|
2022-09-28 22:49:07 +02:00
|
|
|
if current_value:
|
|
|
|
current_value = sorted(re.sub(r'\s*=\s*', '=', part.strip(), count=1) for part in current_value.split(','))
|
2022-09-03 12:02:03 +02:00
|
|
|
value = sorted(part.strip() for part in value.split(','))
|
2020-06-30 05:43:39 +02:00
|
|
|
else:
|
|
|
|
# parameter does not exist
|
|
|
|
current_value = None
|
|
|
|
|
|
|
|
if isinstance(current_value, list) and isinstance(value, list):
|
|
|
|
# compare values between two lists
|
2023-02-25 11:00:43 +01:00
|
|
|
if key in ('ipv4.addresses', 'ipv6.addresses'):
|
|
|
|
# The order of IP addresses matters because the first one
|
|
|
|
# is the default source address for outbound connections.
|
|
|
|
changed |= current_value != value
|
|
|
|
else:
|
|
|
|
changed |= sorted(current_value) != sorted(value)
|
2021-11-10 07:04:24 +01:00
|
|
|
elif all([key == self.mtu_setting, self.type == 'dummy', current_value is None, value == 'auto', self.mtu is None]):
|
|
|
|
value = None
|
2020-06-30 05:43:39 +02:00
|
|
|
else:
|
2022-11-01 21:40:17 +01:00
|
|
|
value = to_text(value)
|
|
|
|
if current_value != value:
|
2020-06-30 05:43:39 +02:00
|
|
|
changed = True
|
|
|
|
|
|
|
|
diff_before[key] = current_value
|
|
|
|
diff_after[key] = value
|
|
|
|
|
|
|
|
diff = {
|
|
|
|
'before': diff_before,
|
|
|
|
'after': diff_after,
|
|
|
|
}
|
|
|
|
return (changed, diff)
|
|
|
|
|
|
|
|
def is_connection_changed(self):
|
2020-10-23 07:13:39 +02:00
|
|
|
options = {
|
|
|
|
'connection.interface-name': self.ifname,
|
|
|
|
}
|
2022-03-06 08:56:44 +01:00
|
|
|
|
2022-06-06 21:16:27 +02:00
|
|
|
# VPN doesn't need an interface but if sended it must be a valid interface.
|
|
|
|
if self.type == 'vpn' and self.ifname is None:
|
|
|
|
del options['connection.interface-name']
|
|
|
|
|
2022-03-06 08:56:44 +01:00
|
|
|
if not self.type:
|
|
|
|
current_con_type = self.show_connection().get('connection.type')
|
|
|
|
if current_con_type:
|
nmcli: two fixes needed to make wifi.wake-on-wlan settings work properly (#5431)
* nmcli: Convert current value of wifi.wake-on-wlan before comparing
The new value of wifi.wake-on-wlan is specified as an integer, but in
the nmcli output it's specified as a hex string followed by a textual
description of it. Therefore, to determine properly whether it's being
changed we need to pull the hex string out of the current value,
convert it into an integer, and finally convert the integer back to a
string so that we can compare it to the new specified value. Without
this change, whenever wifi.wake-on-wlan is specified in the module
arguments the module will think the value is being changed even when
it isn't.
* nmcli: Handle wifi options correctly when connection type not specified
When an nmcli task does not specify the connection type and the module
ask nmcli for it, the module needs to convert nmcli's
`802-11-wireless` to `wifi`, the term for this connection type used by
the module.
* nmcli: Correctly detect values changed to the integer 0
If the user specifies a value of 0 (without quotes) in a task, we
should interpret that as an actual value, not empty, when comparing
the new value to the old one. Otherwise we incorrectly conclude that
there was no change.
* Changelog fragment for #5431
2023-02-24 09:10:41 +01:00
|
|
|
if current_con_type == '802-11-wireless':
|
|
|
|
current_con_type = 'wifi'
|
2022-03-06 08:56:44 +01:00
|
|
|
self.type = current_con_type
|
|
|
|
|
2020-10-23 07:13:39 +02:00
|
|
|
options.update(self.connection_options(detect_change=True))
|
|
|
|
return self._compare_conn_params(self.show_connection(), options)
|
2020-06-30 05:43:39 +02:00
|
|
|
|
2020-03-09 10:11:07 +01:00
|
|
|
|
|
|
|
def main():
|
|
|
|
# Parsing argument file
|
|
|
|
module = AnsibleModule(
|
|
|
|
argument_spec=dict(
|
2021-08-20 21:45:30 +02:00
|
|
|
ignore_unsupported_suboptions=dict(type='bool', default=False),
|
2020-03-09 10:11:07 +01:00
|
|
|
autoconnect=dict(type='bool', default=True),
|
|
|
|
state=dict(type='str', required=True, choices=['absent', 'present']),
|
|
|
|
conn_name=dict(type='str', required=True),
|
|
|
|
master=dict(type='str'),
|
2024-04-09 08:01:00 +02:00
|
|
|
slave_type=dict(type='str', choices=['bond', 'bridge', 'team', 'ovs-port']),
|
2020-03-09 10:11:07 +01:00
|
|
|
ifname=dict(type='str'),
|
|
|
|
type=dict(type='str',
|
2020-12-01 20:39:56 +01:00
|
|
|
choices=[
|
|
|
|
'bond',
|
|
|
|
'bond-slave',
|
|
|
|
'bridge',
|
|
|
|
'bridge-slave',
|
2021-08-05 14:25:42 +02:00
|
|
|
'dummy',
|
2020-12-01 20:39:56 +01:00
|
|
|
'ethernet',
|
|
|
|
'generic',
|
2021-08-26 08:16:36 +02:00
|
|
|
'gre',
|
2020-12-01 20:39:56 +01:00
|
|
|
'infiniband',
|
|
|
|
'ipip',
|
|
|
|
'sit',
|
|
|
|
'team',
|
|
|
|
'team-slave',
|
|
|
|
'vlan',
|
2021-04-18 10:59:23 +02:00
|
|
|
'vxlan',
|
|
|
|
'wifi',
|
2021-09-05 18:28:04 +02:00
|
|
|
'gsm',
|
2023-04-16 13:22:11 +02:00
|
|
|
'macvlan',
|
2022-01-08 14:13:50 +01:00
|
|
|
'wireguard',
|
2022-06-06 21:16:27 +02:00
|
|
|
'vpn',
|
2023-11-22 09:26:04 +01:00
|
|
|
'loopback',
|
2024-04-09 08:01:00 +02:00
|
|
|
'ovs-interface',
|
|
|
|
'ovs-bridge',
|
|
|
|
'ovs-port',
|
2020-12-01 20:39:56 +01:00
|
|
|
]),
|
2021-11-19 07:07:35 +01:00
|
|
|
ip4=dict(type='list', elements='str'),
|
2020-03-09 10:11:07 +01:00
|
|
|
gw4=dict(type='str'),
|
2021-06-01 22:04:09 +02:00
|
|
|
gw4_ignore_auto=dict(type='bool', default=False),
|
2020-12-01 20:39:56 +01:00
|
|
|
routes4=dict(type='list', elements='str'),
|
2022-04-05 06:58:02 +02:00
|
|
|
routes4_extended=dict(type='list',
|
|
|
|
elements='dict',
|
|
|
|
options=dict(
|
|
|
|
ip=dict(type='str', required=True),
|
|
|
|
next_hop=dict(type='str'),
|
|
|
|
metric=dict(type='int'),
|
|
|
|
table=dict(type='int'),
|
|
|
|
tos=dict(type='int'),
|
|
|
|
cwnd=dict(type='int'),
|
|
|
|
mtu=dict(type='int'),
|
|
|
|
onlink=dict(type='bool')
|
|
|
|
)),
|
2020-12-01 20:39:56 +01:00
|
|
|
route_metric4=dict(type='int'),
|
2021-09-29 06:49:49 +02:00
|
|
|
routing_rules4=dict(type='list', elements='str'),
|
2020-12-01 20:39:56 +01:00
|
|
|
never_default4=dict(type='bool', default=False),
|
2020-10-23 07:13:39 +02:00
|
|
|
dns4=dict(type='list', elements='str'),
|
|
|
|
dns4_search=dict(type='list', elements='str'),
|
2023-07-13 22:26:42 +02:00
|
|
|
dns4_options=dict(type='list', elements='str'),
|
2021-06-01 22:04:09 +02:00
|
|
|
dns4_ignore_auto=dict(type='bool', default=False),
|
2021-03-02 12:46:21 +01:00
|
|
|
method4=dict(type='str', choices=['auto', 'link-local', 'manual', 'shared', 'disabled']),
|
2021-06-19 14:42:05 +02:00
|
|
|
may_fail4=dict(type='bool', default=True),
|
2020-03-09 10:11:07 +01:00
|
|
|
dhcp_client_id=dict(type='str'),
|
2021-12-09 21:17:32 +01:00
|
|
|
ip6=dict(type='list', elements='str'),
|
2020-03-09 10:11:07 +01:00
|
|
|
gw6=dict(type='str'),
|
2021-06-01 22:04:09 +02:00
|
|
|
gw6_ignore_auto=dict(type='bool', default=False),
|
2020-10-23 07:13:39 +02:00
|
|
|
dns6=dict(type='list', elements='str'),
|
|
|
|
dns6_search=dict(type='list', elements='str'),
|
2023-07-13 22:26:42 +02:00
|
|
|
dns6_options=dict(type='list', elements='str'),
|
2021-06-01 22:04:09 +02:00
|
|
|
dns6_ignore_auto=dict(type='bool', default=False),
|
2022-01-23 13:02:03 +01:00
|
|
|
routes6=dict(type='list', elements='str'),
|
2022-04-05 06:58:02 +02:00
|
|
|
routes6_extended=dict(type='list',
|
|
|
|
elements='dict',
|
|
|
|
options=dict(
|
|
|
|
ip=dict(type='str', required=True),
|
|
|
|
next_hop=dict(type='str'),
|
|
|
|
metric=dict(type='int'),
|
|
|
|
table=dict(type='int'),
|
|
|
|
cwnd=dict(type='int'),
|
|
|
|
mtu=dict(type='int'),
|
|
|
|
onlink=dict(type='bool')
|
|
|
|
)),
|
2022-01-23 13:02:03 +01:00
|
|
|
route_metric6=dict(type='int'),
|
2021-06-19 14:42:05 +02:00
|
|
|
method6=dict(type='str', choices=['ignore', 'auto', 'dhcp', 'link-local', 'manual', 'shared', 'disabled']),
|
2021-12-04 18:41:14 +01:00
|
|
|
ip_privacy6=dict(type='str', choices=['disabled', 'prefer-public-addr', 'prefer-temp-addr', 'unknown']),
|
2023-03-24 07:55:58 +01:00
|
|
|
addr_gen_mode6=dict(type='str', choices=['default', 'default-or-eui64', 'eui64', 'stable-privacy']),
|
2020-03-09 10:11:07 +01:00
|
|
|
# Bond Specific vars
|
|
|
|
mode=dict(type='str', default='balance-rr',
|
|
|
|
choices=['802.3ad', 'active-backup', 'balance-alb', 'balance-rr', 'balance-tlb', 'balance-xor', 'broadcast']),
|
|
|
|
miimon=dict(type='int'),
|
|
|
|
downdelay=dict(type='int'),
|
|
|
|
updelay=dict(type='int'),
|
2022-09-08 07:45:23 +02:00
|
|
|
xmit_hash_policy=dict(type='str'),
|
2020-03-09 10:11:07 +01:00
|
|
|
arp_interval=dict(type='int'),
|
|
|
|
arp_ip_target=dict(type='str'),
|
|
|
|
primary=dict(type='str'),
|
|
|
|
# general usage
|
|
|
|
mtu=dict(type='int'),
|
|
|
|
mac=dict(type='str'),
|
2020-12-05 16:18:29 +01:00
|
|
|
zone=dict(type='str'),
|
2020-03-09 10:11:07 +01:00
|
|
|
# bridge specific vars
|
|
|
|
stp=dict(type='bool', default=True),
|
|
|
|
priority=dict(type='int', default=128),
|
|
|
|
slavepriority=dict(type='int', default=32),
|
|
|
|
forwarddelay=dict(type='int', default=15),
|
|
|
|
hellotime=dict(type='int', default=2),
|
|
|
|
maxage=dict(type='int', default=20),
|
|
|
|
ageingtime=dict(type='int', default=300),
|
2023-04-26 07:32:00 +02:00
|
|
|
hairpin=dict(type='bool', default=False),
|
2020-03-09 10:11:07 +01:00
|
|
|
path_cost=dict(type='int', default=100),
|
2021-07-14 08:24:27 +02:00
|
|
|
# team specific vars
|
|
|
|
runner=dict(type='str', default='roundrobin',
|
|
|
|
choices=['broadcast', 'roundrobin', 'activebackup', 'loadbalance', 'lacp']),
|
|
|
|
# team active-backup runner specific options
|
|
|
|
runner_hwaddr_policy=dict(type='str', choices=['same_all', 'by_active', 'only_active']),
|
2023-03-26 09:27:00 +02:00
|
|
|
# team lacp runner specific options
|
|
|
|
runner_fast_rate=dict(type='bool'),
|
2020-03-09 10:11:07 +01:00
|
|
|
# vlan specific vars
|
|
|
|
vlanid=dict(type='int'),
|
|
|
|
vlandev=dict(type='str'),
|
|
|
|
flags=dict(type='str'),
|
|
|
|
ingress=dict(type='str'),
|
|
|
|
egress=dict(type='str'),
|
|
|
|
# vxlan specific vars
|
|
|
|
vxlan_id=dict(type='int'),
|
|
|
|
vxlan_local=dict(type='str'),
|
|
|
|
vxlan_remote=dict(type='str'),
|
|
|
|
# ip-tunnel specific vars
|
|
|
|
ip_tunnel_dev=dict(type='str'),
|
|
|
|
ip_tunnel_local=dict(type='str'),
|
|
|
|
ip_tunnel_remote=dict(type='str'),
|
2021-08-26 08:16:36 +02:00
|
|
|
# ip-tunnel type gre specific vars
|
|
|
|
ip_tunnel_input_key=dict(type='str', no_log=True),
|
|
|
|
ip_tunnel_output_key=dict(type='str', no_log=True),
|
2021-08-20 21:45:30 +02:00
|
|
|
# 802-11-wireless* specific vars
|
2021-04-18 10:59:23 +02:00
|
|
|
ssid=dict(type='str'),
|
2021-08-04 08:16:11 +02:00
|
|
|
wifi=dict(type='dict'),
|
2021-04-18 10:59:23 +02:00
|
|
|
wifi_sec=dict(type='dict', no_log=True),
|
2021-09-05 18:28:04 +02:00
|
|
|
gsm=dict(type='dict'),
|
2023-04-16 13:22:11 +02:00
|
|
|
macvlan=dict(type='dict', options=dict(
|
|
|
|
mode=dict(type='int', choices=[1, 2, 3, 4, 5], required=True),
|
|
|
|
parent=dict(type='str', required=True),
|
|
|
|
promiscuous=dict(type='bool'),
|
|
|
|
tap=dict(type='bool'))),
|
2022-01-08 14:13:50 +01:00
|
|
|
wireguard=dict(type='dict'),
|
2022-06-06 21:16:27 +02:00
|
|
|
vpn=dict(type='dict'),
|
2022-10-23 11:30:48 +02:00
|
|
|
transport_mode=dict(type='str', choices=['datagram', 'connected']),
|
2020-03-09 10:11:07 +01:00
|
|
|
),
|
2022-04-05 06:58:02 +02:00
|
|
|
mutually_exclusive=[['never_default4', 'gw4'],
|
|
|
|
['routes4_extended', 'routes4'],
|
|
|
|
['routes6_extended', 'routes6']],
|
2021-04-18 10:59:23 +02:00
|
|
|
required_if=[("type", "wifi", [("ssid")])],
|
2020-03-09 10:11:07 +01:00
|
|
|
supports_check_mode=True,
|
|
|
|
)
|
2020-09-29 22:57:07 +02:00
|
|
|
module.run_command_environ_update = dict(LANG='C', LC_ALL='C', LC_MESSAGES='C', LC_CTYPE='C')
|
2020-03-09 10:11:07 +01:00
|
|
|
|
|
|
|
nmcli = Nmcli(module)
|
|
|
|
|
|
|
|
(rc, out, err) = (None, '', '')
|
|
|
|
result = {'conn_name': nmcli.conn_name, 'state': nmcli.state}
|
|
|
|
|
|
|
|
# check for issues
|
|
|
|
if nmcli.conn_name is None:
|
|
|
|
nmcli.module.fail_json(msg="Please specify a name for the connection")
|
2021-07-14 08:24:27 +02:00
|
|
|
# team checks
|
|
|
|
if nmcli.type == "team":
|
|
|
|
if nmcli.runner_hwaddr_policy and not nmcli.runner == "activebackup":
|
|
|
|
nmcli.module.fail_json(msg="Runner-hwaddr-policy is only allowed for runner activebackup")
|
2023-03-26 09:27:00 +02:00
|
|
|
if nmcli.runner_fast_rate is not None and nmcli.runner != "lacp":
|
|
|
|
nmcli.module.fail_json(msg="runner-fast-rate is only allowed for runner lacp")
|
2020-03-09 10:11:07 +01:00
|
|
|
# team-slave checks
|
2023-05-08 19:44:30 +02:00
|
|
|
if nmcli.type == 'team-slave' or nmcli.slave_type == 'team':
|
2020-06-15 13:32:55 +02:00
|
|
|
if nmcli.master is None:
|
|
|
|
nmcli.module.fail_json(msg="Please specify a name for the master when type is %s" % nmcli.type)
|
|
|
|
if nmcli.ifname is None:
|
|
|
|
nmcli.module.fail_json(msg="Please specify an interface name for the connection when type is %s" % nmcli.type)
|
2021-08-20 21:45:30 +02:00
|
|
|
if nmcli.type == 'wifi':
|
|
|
|
unsupported_properties = {}
|
|
|
|
if nmcli.wifi:
|
|
|
|
if 'ssid' in nmcli.wifi:
|
|
|
|
module.warn("Ignoring option 'wifi.ssid', it must be specified with option 'ssid'")
|
|
|
|
del nmcli.wifi['ssid']
|
|
|
|
unsupported_properties['wifi'] = nmcli.check_for_unsupported_properties('802-11-wireless')
|
|
|
|
if nmcli.wifi_sec:
|
|
|
|
unsupported_properties['wifi_sec'] = nmcli.check_for_unsupported_properties('802-11-wireless-security')
|
|
|
|
if nmcli.ignore_unsupported_suboptions and unsupported_properties:
|
|
|
|
for setting_key, properties in unsupported_properties.items():
|
|
|
|
for property in properties:
|
|
|
|
del getattr(nmcli, setting_key)[property]
|
2020-03-09 10:11:07 +01:00
|
|
|
|
2020-06-30 05:43:39 +02:00
|
|
|
try:
|
|
|
|
if nmcli.state == 'absent':
|
|
|
|
if nmcli.connection_exists():
|
|
|
|
if module.check_mode:
|
|
|
|
module.exit_json(changed=True)
|
|
|
|
(rc, out, err) = nmcli.down_connection()
|
|
|
|
(rc, out, err) = nmcli.remove_connection()
|
|
|
|
if rc != 0:
|
|
|
|
module.fail_json(name=('No Connection named %s exists' % nmcli.conn_name), msg=err, rc=rc)
|
|
|
|
|
|
|
|
elif nmcli.state == 'present':
|
|
|
|
if nmcli.connection_exists():
|
|
|
|
changed, diff = nmcli.is_connection_changed()
|
|
|
|
if module._diff:
|
|
|
|
result['diff'] = diff
|
|
|
|
|
|
|
|
if changed:
|
|
|
|
# modify connection (note: this function is check mode aware)
|
|
|
|
# result['Connection']=('Connection %s of Type %s is not being added' % (nmcli.conn_name, nmcli.type))
|
|
|
|
result['Exists'] = 'Connections do exist so we are modifying them'
|
|
|
|
if module.check_mode:
|
|
|
|
module.exit_json(changed=True, **result)
|
|
|
|
(rc, out, err) = nmcli.modify_connection()
|
|
|
|
else:
|
|
|
|
result['Exists'] = 'Connections already exist and no changes made'
|
|
|
|
if module.check_mode:
|
|
|
|
module.exit_json(changed=False, **result)
|
|
|
|
if not nmcli.connection_exists():
|
|
|
|
result['Connection'] = ('Connection %s of Type %s is being added' % (nmcli.conn_name, nmcli.type))
|
|
|
|
if module.check_mode:
|
|
|
|
module.exit_json(changed=True, **result)
|
|
|
|
(rc, out, err) = nmcli.create_connection()
|
|
|
|
if rc is not None and rc != 0:
|
|
|
|
module.fail_json(name=nmcli.conn_name, msg=err, rc=rc)
|
|
|
|
except NmcliModuleError as e:
|
|
|
|
module.fail_json(name=nmcli.conn_name, msg=str(e))
|
2020-03-09 10:11:07 +01:00
|
|
|
|
|
|
|
if rc is None:
|
|
|
|
result['changed'] = False
|
|
|
|
else:
|
|
|
|
result['changed'] = True
|
|
|
|
if out:
|
|
|
|
result['stdout'] = out
|
|
|
|
if err:
|
|
|
|
result['stderr'] = err
|
|
|
|
|
|
|
|
module.exit_json(**result)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|