Files
net_bridge/tasks/main.yaml
2025-11-28 17:25:49 -08:00

49 lines
1.2 KiB
YAML

---
# this role installs the bridge and reboots.
# optionally it creates a new inventory file on the jenkins host
# if the appropriate variable is declared
- name: Install iptables-persistent
apt:
name:
- iptables-persistent
state: present
# check interfaces
- name: check interfaces for vmpbr0
shell: ip -o -4 ad
register: ip_ad_output
- name: install bridge
when: '"vmpbr0" not in ip_ad_output.stdout'
include_tasks: create_bridge.yaml
# Create new inventory file
- name: create inventory file
when: create_inventory | bool
block:
- name: get bridge IP
shell: ip -o -4 ad li | grep {{ bridge_name }} | awk '{print $4}' | cut -d '/' -f 1
register: bridge_ip_output
- name: set bridge_address variable
set_fact:
bridge_address: "{{ bridge_ip_output.stdout_lines[0] }}"
- name: show bridge address
debug:
msg:
- "{{ bridge_address }}"
- name: Network Bridge - Create new inventory file on jenkins server
delegate_to: localhost
template:
src: inventory.j2
dest: "/var/jenkins_home/ansible/.inv/inventory-{{ STAGE_TWO_HASH }}.yml"
- name: Reboot
when: '"vmpbr0" not in ip_ad_output.stdout'
shell: "( sleep 5 ; reboot now ) & "
ignore_errors: yes
...