how to tag vlan on bond using nmcli community
---
- name: Configure VLAN on bond using nmcli
hosts: your_hosts_here # Replace with your target hosts
become: yes # This task requires sudo privileges
tasks:
- name: Ensure bond0 is configured
nmcli:
type: bond
conn_name: bond0
ifname: bond0
mode: 802.3ad
options:
miimon: 100
downdelay: 0
updelay: 0
ip4: "{{ '0.0.0.0' }}" # Disables IPv4 on the bond itself
ip6: "{{ '::' }}"
state: present
- name: Add physical interfaces to bond0
nmcli:
type: ethernet
conn_name: "bond0-{{ item }}"
ifname: "{{ item }}"
master: bond0
state: present
loop:
- eno1 # Replace with your actual interface names
- eno2
- name: Configure VLAN on bond0
nmcli:
type: vlan
conn_name: "bond0.{{ vlan_id }}"
ifname: "bond0.{{ vlan_id }}"
dev: bond0
id: "{{ vlan_id }}"
ip4: "{{ vlan_ip }}/{{ vlan_mask }}"
gw4: "{{ vlan_gateway }}"
state: present
vars:
vlan_id: 123 # Change this to your VLAN ID
vlan_ip: 192.168.123.123 # Change to your desired IP
vlan_mask: 24
vlan_gateway: 192.168.123.1 # Change to your network's gateway
- name: Activate all connections
nmcli:
conn_name: "{{ item }}"
state: up
loop:
- bond0
- bond0-eno1
- bond0-eno2
- bond0.123 # Assuming VLAN ID is 123, adjust accordingly
- name: Verify network configuration
shell: |
nmcli connection show
ip addr show
register: network_info
changed_when: false # This task doesn't change system state, just for info
- name: Display network info
debug:
var: network_info.stdout_lines