Skip to content

Instantly share code, notes, and snippets.

@kmurudi
Last active March 19, 2018 00:10
Show Gist options
  • Save kmurudi/f2b6f73cbed63d7baaf14587492b169b to your computer and use it in GitHub Desktop.
Save kmurudi/f2b6f73cbed63d7baaf14587492b169b to your computer and use it in GitHub Desktop.
define_networks.yaml
- hosts: localhost
gather_facts: no
become: yes
# as I created 4 ovs bridges in playbook 1, now I will define L2 networks for all of them and then define each separately
tasks:
- name: Define a network
virt_net:
command: define
name: net1
xml: '{{ lookup("template", "net1.xml") }}'
- name: Start the network
command: virsh net-start net1
- name: Start the network
command: virsh net-autostart net1
- name: Define a network
virt_net:
command: define
name: net2
xml: '{{ lookup("template", "net2.xml") }}'
- name: Start the network
command: virsh net-start net2
- name: Start the network
command: virsh net-autostart net2
- name: Define a network
virt_net:
command: define
name: net3
xml: '{{ lookup("template", "net3.xml") }}'
- name: Start the network
command: virsh net-start net3
- name: Start the network
command: virsh net-autostart net3
- name: Define a network
virt_net:
command: define
name: net4
xml: '{{ lookup("template", "net4.xml") }}'
- name: Start the network
command: virsh net-start net4
- name: Start the network
command: virsh net-autostart net4
# making routed networks L3 and other now - named as net3 and net4
- name: Set link up
command: ip link set sw3 up
- name: Set SW3 IPv4 address for routed network
command: ip addr add 10.10.30.30/24 dev sw3
- name: make interface up
command: ip link set sw4 up
- name: Set SW4 IPv4 address for routed network
command: ip addr add 10.10.40.40/24 dev sw4
# defining network L1 - NAT
- name: make interface up
command: ip link set sw1 up
- name: Set SW1 IPv4 address for routed network
command: ip addr add 10.10.10.10/24 dev sw1
- name: flushing all NAT table rules
iptables:
table: nat
flush: yes
- name: enabling nat by changing source address
shell: iptables -t nat -A POSTROUTING -p all -s 10.10.10.10 -j SNAT --to-source 152.46.19.196
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment