diff --git a/defaults/main.yml b/defaults/main.yml index 1904f62..6c809cf 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -74,6 +74,14 @@ lxc_container_fs_type: ext4 # using the directory backing. lxc_container_vg_name: lxc +# Scripts allowing the configuration of pre/post-up/down scripts in Ubuntu +# interface files. These are merged with per-interface scripts defined in the +# container_networks dict +lxc_container_default_preup: [] +lxc_container_default_postup: [] +lxc_container_default_predown: [] +lxc_container_default_postdown: [] + lxc_container_default_mtu: "1500" lxc_container_domain: "openstack.local" @@ -110,4 +118,3 @@ lxc_container_network_veth_pair: "{{ inventory_hostname[-8:].replace('-', '').re # Enable fixed mac address generation for an lxc container lxc_container_fixed_mac: false - diff --git a/releasenotes/notes/lxc-interface-scripts-78e9021cf2ed0c97.yaml b/releasenotes/notes/lxc-interface-scripts-78e9021cf2ed0c97.yaml new file mode 100644 index 0000000..5ad710e --- /dev/null +++ b/releasenotes/notes/lxc-interface-scripts-78e9021cf2ed0c97.yaml @@ -0,0 +1,7 @@ +--- +features: + - In the lxc_container_create role, the keys ``preup``, ``postup``, + ``predown``, and ``postdown`` are now supported in the + ``container_networks`` dict for Ubuntu systems. This allows operators to + configure custom scripts to be run by Ubuntu's ifupdown system when network + interface states are changed. diff --git a/templates/debian-interface.cfg.j2 b/templates/debian-interface.cfg.j2 index f958c8b..d650bb5 100644 --- a/templates/debian-interface.cfg.j2 +++ b/templates/debian-interface.cfg.j2 @@ -10,10 +10,6 @@ iface {{ item.value.interface }} inet static gateway {{ item.value.gateway }} {% endif %} mtu {{ item.value.mtu|default(lxc_container_default_mtu) }} - # needed to enable gratuitous arps on interface events - post-up sysctl -w net.ipv4.conf.$IFACE.arp_notify=1 - # needed to force an interface event (setting mac to what it already is) - post-up ip link set $IFACE address $(cat /sys/class/net/$IFACE/address) {% if item.value.static_routes is defined %} {% for route in item.value.static_routes %} post-up ip route add {{ route['cidr'] }} via {{ route['gateway'] }} || true @@ -22,4 +18,16 @@ iface {{ item.value.interface }} inet static {% else %} iface {{ item.value.interface }} inet manual {% endif %} -### end generated network for [ {{ item.value.interface }} ] ### \ No newline at end of file +{% for item in item.value.preup | default([]) | union(lxc_container_default_preup) %} + pre-up {{ item }} +{% endfor %} +{% for item in item.value.postup | default([]) | union(lxc_container_default_postup) %} + post-up {{ item }} +{% endfor %} +{% for item in item.value.predown | default([]) | union(lxc_container_default_predown) %} + pre-down {{ item }} +{% endfor %} +{% for item in item.value.postdown | default([]) | union(lxc_container_default_postdown) %} + post-down {{ item }} +{% endfor %} +### end generated network for [ {{ item.value.interface }} ] ### diff --git a/vars/ubuntu-16.04.yml b/vars/ubuntu-16.04.yml index 15ee41c..5251eee 100644 --- a/vars/ubuntu-16.04.yml +++ b/vars/ubuntu-16.04.yml @@ -29,3 +29,9 @@ lxc_container_map: distro: ubuntu arch: "{{ lxc_architecture_mapping.get( hostvars[physical_host]['ansible_architecture'] | lower ) }}" release: xenial + +lxc_container_default_postup: + # needed to enable gratuitous arps on interface events + - "sysctl -w net.ipv4.conf.$IFACE.arp_notify=1" + # needed to force an interface event (setting mac to what it already is) + - "ip link set $IFACE address $(cat /sys/class/net/$IFACE/address)"