Skip to content

Commit a49efd8

Browse files
committed
get dummy gateway and adding gateway working
1 parent 366232d commit a49efd8

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

ansible/roles/gateway/files/gateway-init.yml

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,20 @@
2727
- name: Examine whether device address contains gateway_ip
2828
set_fact:
2929
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+
3132
- name: Get name of connection containing gateway_ip
3233
# might be empty string
3334
set_fact:
3435
gateway_ip_connection: >-
3536
{{ nmcli_devices | map(attribute='connection') |
3637
zip(device_is_gateway_device) | selectattr('1') |
3738
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+
3944
- name: Error if device has a gateway which is not the desired one
4045
# TODO: document
4146
assert:
@@ -48,40 +53,36 @@
4853
loop: "{{ nmcli_devices }}"
4954

5055
- 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 }}'
5559
when:
5660
- gateway_ip != ''
5761
- item.ip4_gateway != ''
5862
- item.connection != gateway_ip_connection
5963
loop: "{{ nmcli_devices }}"
6064

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 }}'
6871
when:
6972
- gateway_ip != ''
7073
- item.ip4_gateway != gateway_ip
7174
- item.connection == gateway_ip_connection
7275
loop: "{{ nmcli_devices }}"
7376

74-
- name: Create dummy connection and gateway
77+
- name: Create dummy connection and gateway # TESTED OK
7578
# see https://docs.k3s.io/installation/airgap#default-network-route
76-
command: >-
79+
shell: |
7780
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 \
8385
ipv4.method manual
84-
&&
8586
nmcli connection up dummy0
8687
when:
8788
- gateway_ip == '' # no gateway specified

0 commit comments

Comments
 (0)