init commit

This commit is contained in:
2025-06-23 09:29:29 -07:00
commit 135847d745
7 changed files with 151 additions and 0 deletions

70
tasks/create_bridge.yaml Normal file
View File

@ -0,0 +1,70 @@
---
# remove cosmos VPN
- name: remove cosmos openvpn profile
shell: |
systemctl stop openvpn-client@cosmos-client.service
systemctl disable openvpn-client@cosmos-client.service
systemctl daemon-reload
- name: Install Packages
apt:
name:
- bridge-utils
state: present
- name: get current interface name
shell: cat /etc/network/interfaces | grep iface | grep -v loopback | awk '{print $2}'
register: current_iface_output
- name: set current_iface
set_fact:
current_iface: '{{ current_iface_output.stdout_lines[0] }}'
- name: display interface name
debug:
msg: "Current interface is {{ current_iface }}"
- name: update interfaces file
block:
- name: backup original interfaces file
shell: "cp /etc/network/interfaces /opt/interfaces-backup"
- name: Comment out allow-hotplug line for main interface
lineinfile:
dest: /etc/network/interfaces
regexp: '^#? *allow-hotplug {{ current_iface }}'
line: '# allow-hotplug {{ current_iface }}'
backrefs: yes
- name: Comment out iface line for main interface
lineinfile:
dest: /etc/network/interfaces
regexp: '^#? *iface {{ current_iface }} inet dhcp'
line: '# iface {{ current_iface }} inet dhcp'
backrefs: yes
- name: Create new bridge interface file
template:
src: bridge.j2
dest: /etc/network/interfaces.d/{{ bridge_name }}
- name: restart networking
shell: |
systemctl daemon-reload
systemctl restart networking
- name: show bridge
shell: |
brctl show
bridge link
register: bridge_status
- name: show bridge status
debug:
msg:
- "{{ bridge_status.stdout_lines }}"
...

42
tasks/main.yaml Normal file
View File

@ -0,0 +1,42 @@
---
# this role installs the bridge and reboots.
# optionally it creates a new inventory file on the jenkins host
# if the appropriate variable is declared
# 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
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'
command: "reboot now"
ignore_errors: yes
...