Andy Bavier | 30d27c9 | 2016-09-15 15:59:17 -0400 | [diff] [blame] | 1 | --- |
| 2 | - name: Install prerequisites |
| 3 | apt: |
| 4 | name={{ item }} |
| 5 | update_cache=yes |
| 6 | cache_valid_time=3600 |
| 7 | become: yes |
| 8 | register: result |
| 9 | until: result | success |
| 10 | retries: 15 |
| 11 | delay: 60 |
| 12 | with_items: |
| 13 | - bridge-utils |
| 14 | |
| 15 | - name: Create bridges |
| 16 | when: "ansible_{{ item.name }} is not defined" |
| 17 | command: brctl addbr "{{ item.name }}" |
| 18 | with_items: "{{ simfabric_bridges }}" |
| 19 | |
| 20 | # note, not idempotent if failed between prior step and this step |
| 21 | - name: Set IP addresses to bridges |
| 22 | when: "ansible_{{ item.0.name }} is not defined" |
| 23 | command: "ip addr add {{ item.1 }} dev {{ item.0.name }}" |
| 24 | with_subelements: |
| 25 | - "{{ simfabric_bridges }}" |
| 26 | - addresses |
| 27 | |
| 28 | - name: Run setup again to obtain bridge info |
| 29 | setup: |
| 30 | |
| 31 | - name: Start bridges |
| 32 | when: "not ansible_{{ item.name }}.active" |
| 33 | command: "ip link set dev {{ item.name }} up" |
| 34 | with_items: "{{ simfabric_bridges }}" |
| 35 | |
| 36 | - name: Create ip links |
| 37 | when: "ansible_{{ item.dev }} is not defined" |
| 38 | command: "ip link add dev {{ item.dev }} address {{ item.mac }} type {{ item.type }} peer name {{ item.peer }}" |
| 39 | with_items: "{{ simfabric_links }}" |
| 40 | |
| 41 | - name: Run setup again to obtain link info |
| 42 | setup: |
| 43 | |
| 44 | - name: Start interfaces |
| 45 | when: "not ansible_{{ item }}.active" |
| 46 | command: "ip link set dev {{ item }} up" |
| 47 | with_items: |
| 48 | - "{{ simfabric_links | map(attribute='dev') | list }}" |
| 49 | - "{{ simfabric_links | map(attribute='peer') | list }}" |
| 50 | |
| 51 | - name: Add interfaces to bridges |
| 52 | when: "not item.1 in ansible_{{ item.0.name }}.interfaces" |
| 53 | command: "brctl addif {{ item.0.name }} {{ item.1 }}" |
| 54 | with_subelements: |
| 55 | - "{{ simfabric_bridges }}" |
| 56 | - interfaces |
| 57 | |
| 58 | - name: Check for iptables rule |
| 59 | command: "iptables -t nat -C POSTROUTING -s 10.168.0.0/16 ! -d 10.168.0.0/16 -j MASQUERADE" |
| 60 | register: iptables_check |
| 61 | failed_when: "iptables_check|failed and 'No chain/target/match by that name' not in iptables_check.stderr" |
| 62 | tags: |
| 63 | - skip_ansible_lint # FIXME: should use iptables module when it supports inversion of ranges |
| 64 | |
| 65 | - name: Create iptables rule |
| 66 | when: "iptables_check.rc != 0" |
| 67 | command: "iptables -t nat -A POSTROUTING -s 10.168.0.0/16 ! -d 10.168.0.0/16 -j MASQUERADE" |
| 68 | |
| 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 }}" |
| 74 | |
| 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 | |