|
27 | 27 | - name: Examine whether device address contains gateway_ip
|
28 | 28 | set_fact:
|
29 | 29 | device_is_gateway_device: "{{ nmcli_devices | map(attribute='ip4_address') | map('ansible.utils.network_in_network', gateway_ip) }}"
|
30 |
| - |
| 30 | + # list of bools - false if gateway_ip == '' |
| 31 | + |
31 | 32 | - name: Get name of connection containing gateway_ip
|
32 | 33 | # might be empty string
|
33 | 34 | set_fact:
|
34 | 35 | gateway_ip_connection: >-
|
35 | 36 | {{ nmcli_devices | map(attribute='connection') |
|
36 | 37 | zip(device_is_gateway_device) | selectattr('1') |
|
37 | 38 | map(attribute=0) | list | first | default ('') }}
|
38 |
| - |
| 39 | +
|
| 40 | + - name: Show debug info |
| 41 | + debug: |
| 42 | + msg: "gateway_ip={{ gateway_ip }} access_ip={{ access_ip }} gateway_ip_connection={{ gateway_ip_connection }}" |
| 43 | + |
39 | 44 | - name: Error if device has a gateway which is not the desired one
|
40 | 45 | # TODO: document
|
41 | 46 | assert:
|
|
48 | 53 | loop: "{{ nmcli_devices }}"
|
49 | 54 |
|
50 | 55 | - name: Remove undesired gateways
|
51 |
| - command: >- |
52 |
| - echo nmcli connection modify '{{ item.connection }}' ipv4.gateway '' |
53 |
| - && |
54 |
| - echo nmcli connection up '{{ item.connection }}' |
| 56 | + shell: | |
| 57 | + nmcli connection modify '{{ item.connection }}' ipv4.gateway '' |
| 58 | + nmcli connection up '{{ item.connection }}' |
55 | 59 | when:
|
56 | 60 | - gateway_ip != ''
|
57 | 61 | - item.ip4_gateway != ''
|
58 | 62 | - item.connection != gateway_ip_connection
|
59 | 63 | loop: "{{ nmcli_devices }}"
|
60 | 64 |
|
61 |
| - - name: Add desired gateways |
62 |
| - command: >- |
63 |
| - echo nmcli connection modify '{{ item.connection }}' |
64 |
| - ipv4.address {{ item.ip4_address }} |
65 |
| - ipv4.gateway {{ gateway_ip }} |
66 |
| - && |
67 |
| - echo nmcli connection up '{{ item.connection }}' |
| 65 | + - name: Add desired gateways # TESTED OK |
| 66 | + shell: | |
| 67 | + nmcli connection modify '{{ item.connection }}' \ |
| 68 | + ipv4.address {{ item.ip4_address }} \ |
| 69 | + ipv4.gateway {{ gateway_ip }} |
| 70 | + nmcli connection up '{{ item.connection }}' |
68 | 71 | when:
|
69 | 72 | - gateway_ip != ''
|
70 | 73 | - item.ip4_gateway != gateway_ip
|
71 | 74 | - item.connection == gateway_ip_connection
|
72 | 75 | loop: "{{ nmcli_devices }}"
|
73 | 76 |
|
74 |
| - - name: Create dummy connection and gateway |
| 77 | + - name: Create dummy connection and gateway # TESTED OK |
75 | 78 | # see https://docs.k3s.io/installation/airgap#default-network-route
|
76 |
| - command: >- |
| 79 | + shell: | |
77 | 80 | nmcli connection add type dummy ifname dummy0 con-name dummy0
|
78 |
| - && |
79 |
| - nmcli connection modify dummy0 |
80 |
| - ipv4.address {{ access_ip }} |
81 |
| - ipv4.gateway {{ access_ip }} |
82 |
| - ipv4.route-metric 1000 |
| 81 | + nmcli connection modify dummy0 \ |
| 82 | + ipv4.address {{ access_ip }} \ |
| 83 | + ipv4.gateway {{ access_ip }} \ |
| 84 | + ipv4.route-metric 1000 \ |
83 | 85 | ipv4.method manual
|
84 |
| - && |
85 | 86 | nmcli connection up dummy0
|
86 | 87 | when:
|
87 | 88 | - gateway_ip == '' # no gateway specified
|
|
0 commit comments