Browse Source

Add path variable for different distros

This change removes the assumption that ip and iptables are always in
the same location on any distro by setting the specific tool path per OS
package manager type.

This adapts the pattern set here:
fc9a2d03dc/tests/roles/bootstrap-host/defaults/main.yml (L106-L118)

Change-Id: If7ddd8f2afb8c990f2b5117947f103626663ad21
Signed-off-by: Kevin Carter <kevin.carter@rackspace.com>
Kevin Carter 2 months ago
parent
commit
ef4aef4802
No account linked to committer's email address
2 changed files with 16 additions and 2 deletions
  1. 2
    2
      tasks/nspawn_networking.yml
  2. 14
    0
      vars/main.yml

+ 2
- 2
tasks/nspawn_networking.yml View File

@@ -213,8 +213,8 @@
213 213
             Wants: network-online.target
214 214
           Service:
215 215
             RemainAfterExit: yes
216
-            ExecStartPre: "-/sbin/iptables -t nat -A POSTROUTING -s {{ dnsmasq_var.value.address }}/{{ (dnsmasq_var.value.address | string + '/' + dnsmasq_var.value.netmask | string) | ipaddr('prefix') }} ! -d {{ dnsmasq_var.value.address }}/{{ (dnsmasq_var.value.address | string + '/' + dnsmasq_var.value.netmask | string) | ipaddr('prefix') }} -j MASQUERADE"
217
-            ExecStopPost: "-/sbin/iptables -t nat -D POSTROUTING -s {{ dnsmasq_var.value.address }}/{{ (dnsmasq_var.value.address | string + '/' + dnsmasq_var.value.netmask | string) | ipaddr('prefix') }} ! -d {{ dnsmasq_var.value.address }}/{{ (dnsmasq_var.value.address | string + '/' + dnsmasq_var.value.netmask | string) | ipaddr('prefix') }} -j MASQUERADE"
216
+            ExecStartPre: "-{{ nspawn_network_utils[ansible_pkg_mgr]['iptables'] }} -t nat -A POSTROUTING -s {{ dnsmasq_var.value.address }}/{{ (dnsmasq_var.value.address | string + '/' + dnsmasq_var.value.netmask | string) | ipaddr('prefix') }} ! -d {{ dnsmasq_var.value.address }}/{{ (dnsmasq_var.value.address | string + '/' + dnsmasq_var.value.netmask | string) | ipaddr('prefix') }} -j MASQUERADE"
217
+            ExecStopPost: "-{{ nspawn_network_utils[ansible_pkg_mgr]['iptables'] }} -t nat -D POSTROUTING -s {{ dnsmasq_var.value.address }}/{{ (dnsmasq_var.value.address | string + '/' + dnsmasq_var.value.netmask | string) | ipaddr('prefix') }} ! -d {{ dnsmasq_var.value.address }}/{{ (dnsmasq_var.value.address | string + '/' + dnsmasq_var.value.netmask | string) | ipaddr('prefix') }} -j MASQUERADE"
218 218
             PIDFile: /run/run/nspawn-{{ dnsmasq_var.value.bridge }}-dnsmasq.pid
219 219
         execstarts:
220 220
           - "/usr/sbin/dnsmasq --keep-in-foreground --conf-file=/etc/dnsmasq.d/dnsmasq-{{ 'mv-' + dnsmasq_var.value.bridge.split('br-')[-1] }}.conf"

+ 14
- 0
vars/main.yml View File

@@ -22,3 +22,17 @@ nspawn_architecture_mapping:
22 22
 
23 23
 # A combined hash of all networks to be used within a deployment.
24 24
 nspawn_combined_networks: "{{ container_networks | combine(container_extra_networks) | combine(nspawn_networks) }}"
25
+
26
+nspawn_network_utils:
27
+  apt:
28
+    iptables: /sbin/iptables
29
+    ip: /sbin/ip
30
+  yum:
31
+    iptables: /usr/sbin/iptables
32
+    ip: /usr/sbin/ip
33
+  zypper:
34
+    iptables: /usr/sbin/iptables
35
+    ip: /sbin/ip
36
+  emerge:
37
+    iptables: /usr/sbin/iptables
38
+    ip: /bin/ip

Loading…
Cancel
Save