blob: 6f24f422e247e41133973d9b5ff1b520e461659a [file] [log] [blame]
Zack Williams0e583122016-04-30 16:57:03 -07001---
2- hosts: nova-compute-1
3 remote_user: ubuntu
4 become: yes
5
6 tasks:
7 - name: Include configuration vars
8 include_vars: simulate-fabric-vars.yml
9
10 - name: Install prerequisites
11 apt:
12 name={{ item }}
13 update_cache=yes
14 cache_valid_time=3600
15 become: yes
16 with_items:
17 - bridge-utils
18
19 - name: Create bridges
Zack Williams5af91912016-05-01 06:34:16 -070020 when: "ansible_{{ item.name }} is not defined"
Zack Williams0e583122016-04-30 16:57:03 -070021 command: brctl addbr "{{ item.name }}"
22 with_items: "{{ simfabric_bridges }}"
23
Zack Williams4a9b1ad2016-05-16 14:24:06 -070024 # note, not idempotent if failed between prior step and this step
Zack Williamsc11aea52016-05-01 21:34:37 -070025 - name: Set IP addresses to bridges
26 when: "ansible_{{ item.0.name }} is not defined"
27 command: "ip addr add {{ item.1 }} dev {{ item.0.name }}"
28 with_subelements:
29 - "{{ simfabric_bridges }}"
30 - addresses
31
Zack Williams4a9b1ad2016-05-16 14:24:06 -070032 - name: Run setup again to obtain bridge info
33 setup:
34
Zack Williamsc11aea52016-05-01 21:34:37 -070035 - name: Start bridges
Zack Williams4a9b1ad2016-05-16 14:24:06 -070036 when: "not ansible_{{ item.name }}.active"
Zack Williamsb994a9e2016-05-01 22:21:06 -070037 command: "ip link set dev {{ item.name }} up"
Zack Williamsc11aea52016-05-01 21:34:37 -070038 with_items: "{{ simfabric_bridges }}"
39
40 - name: Create ip links
41 when: "ansible_{{ item.name }}0 is not defined"
42 command: "ip link add address {{ item.mac }} type {{ item.name }}"
43 with_items: "{{ simfabric_links }}"
44
Zack Williams4a9b1ad2016-05-16 14:24:06 -070045 - name: Run setup again to obtain link info
46 setup:
47
Zack Williamsc11aea52016-05-01 21:34:37 -070048 - name: Start interfaces
Zack Williams4a9b1ad2016-05-16 14:24:06 -070049 when: "not ansible_{{ item }}.active"
Zack Williamsc11aea52016-05-01 21:34:37 -070050 command: "ip link set dev {{ item }} up"
51 with_items: "{{ simfabric_interfaces }}"
52
53 - name: Add interfaces to bridges
Zack Williams4a9b1ad2016-05-16 14:24:06 -070054 when: "not item.1 in ansible_{{ item.0.name }}.interfaces"
Zack Williamsc11aea52016-05-01 21:34:37 -070055 command: "brctl addif {{ item.0.name }} {{ item.1 }}"
56 with_subelements:
57 - "{{ simfabric_bridges }}"
58 - interfaces
59
Zack Williams4a9b1ad2016-05-16 14:24:06 -070060 - name: Check for iptables rule
Zack Williams61e17e52016-05-16 14:40:52 -070061 command: "iptables -t nat -C POSTROUTING -s 10.168.0.0/16 ! -d 10.168.0.0/16 -j MASQUERADE"
Zack Williams4a9b1ad2016-05-16 14:24:06 -070062 register: iptables_check
Zack Williams61e17e52016-05-16 14:40:52 -070063 failed_when: "iptables_check|failed and 'No chain/target/match by that name' not in iptables_check.stderr"
Zack Williams4a9b1ad2016-05-16 14:24:06 -070064
65 - name: Create iptables rule
66 when: "iptables_check.rc != 0"
Zack Williams61e17e52016-05-16 14:40:52 -070067 command: "iptables -t nat -A POSTROUTING -s 10.168.0.0/16 ! -d 10.168.0.0/16 -j MASQUERADE"
Zack Williams4a9b1ad2016-05-16 14:24:06 -070068
69# the below will likely work when this pull makes it into ansible:
70# https://github.com/ansible/ansible-modules-extras/pull/1685
71# - name: Configure iptables
72# iptables: "table={{ item.table }} chain={{ item.chain }} source={{ item.source }} destination={{ item.dest }} jump={{ item.jump }}"
73# with_items: "{{ simfabric_iptables }}"
Zack Williamsc11aea52016-05-01 21:34:37 -070074
75 - name: Set kernel sysctl values
76 sysctl:
77 name="{{ item.name }}"
78 value="{{ item.value }}"
79 sysctl_set=yes
80 state=present
81 reload=yes
82 with_items: "{{ simfabric_sysctl }}"
83