init commit
This commit is contained in:
5
README.md
Normal file
5
README.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
This is a playbook to set up a network bridge.
|
||||||
|
|
||||||
|
I wrote it for the VM party.
|
||||||
|
|
||||||
|
It will set up a bridge.
|
||||||
10
defaults/main.yaml
Normal file
10
defaults/main.yaml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
|
||||||
|
create_inventory: false
|
||||||
|
|
||||||
|
run_stage_two: false
|
||||||
|
|
||||||
|
public_deploy: true
|
||||||
|
|
||||||
|
...
|
||||||
9
files/interfaces
Normal file
9
files/interfaces
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
# This file describes the network interfaces available on your system
|
||||||
|
# and how to activate them. For more information, see interfaces(5).
|
||||||
|
|
||||||
|
source /etc/network/interfaces.d/*
|
||||||
|
|
||||||
|
# The loopback network interface
|
||||||
|
auto lo
|
||||||
|
iface lo inet loopback
|
||||||
|
|
||||||
70
tasks/create_bridge.yaml
Normal file
70
tasks/create_bridge.yaml
Normal 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
42
tasks/main.yaml
Normal 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
|
||||||
|
|
||||||
|
...
|
||||||
6
templates/bridge.j2
Normal file
6
templates/bridge.j2
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
## DHCP ip config file for {{ bridge_name }} ##
|
||||||
|
auto {{ bridge_name }}
|
||||||
|
|
||||||
|
# Bridge setup
|
||||||
|
iface {{ bridge_name }} inet dhcp
|
||||||
|
bridge_ports {{ current_iface }}
|
||||||
9
templates/inventory.j2
Normal file
9
templates/inventory.j2
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
all:
|
||||||
|
hosts:
|
||||||
|
{{ bridge_address }}:
|
||||||
|
ansible_user: root
|
||||||
|
vars:
|
||||||
|
ansible_connection: ssh
|
||||||
|
ansible_ssh_private_key_file: /var/jenkins_home/jenkins_key
|
||||||
|
|
||||||
|
# host_ip;{{ bridge_address }}
|
||||||
Reference in New Issue
Block a user