--- # Copyright 2014, Rackspace US, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # NOTE(mhayden): One of three exit codes should be returned. # 0 = service is running # 3 = service is installed, but not running # 4 = service is not installed, and not running - name: Check if NetworkManager is running command: systemctl status NetworkManager changed_when: false failed_when: false register: networkmanager_check tags: - skip_ansible_lint - name: Ensure network services wait on networking (if using NetworkManager) service: name: NetworkManager-wait-online.service enabled: yes when: networkmanager_check.rc == 0 # NOTE(noonedeadpunk): Drop after AA release as this task is needed to cleanup older config - name: Delete previously provisioned lxc-net configuration file: path: "{{ item }}" state: absent with_items: - /etc/network/interfaces.d/lxc-net-bridge.cfg - "/etc/sysconfig/network-scripts/ifcfg-{{ lxc_net_bridge }}" - "/etc/sysconfig/network-scripts/ifdown-post-{{ lxc_net_bridge }}" # NOTE(mhayden): There are systemd services that act like ifup/ifdown hooks # and handle the customized LXC container networking. Starting lxc-net will # trample over these hooks and cause networking issues for containers. - name: Disable and stop lxc-net service: name: lxc-net enabled: no state: stopped masked: true tags: - lxc-net - name: Setup LXC OVS Bridge openvswitch_bridge: bridge: "{{ lxc_net_bridge }}" fail_mode: standalone state: present when: lxc_net_bridge_type == 'openvswitch' - name: Run the systemd-networkd role include_role: name: systemd_networkd vars: _lxc_net_bridge_devices: - NetDev: Name: "{{ lxc_net_bridge }}" Kind: bridge Bridge: ForwardDelaySec: 0 HelloTimeSec: 2 MaxAgeSec: 12 STP: off systemd_networkd_prefix: "lxc-net" systemd_run_networkd: true systemd_netdevs: "{{ (lxc_net_bridge_type == 'openvswitch') | ternary([], _lxc_net_bridge_devices) }}" systemd_networks: - interface: "{{ lxc_net_bridge }}" address: "{{ lxc_net_address }}" netmask: "{{ lxc_net_netmask }}" config_overrides: Network: ConfigureWithoutCarrier: yes Gateway: "{{ lxc_net_gateway is not none | ternary(lxc_net_gateway, {}) }}" - name: Run the systemd-service role include_role: name: systemd_service vars: systemd_service_enabled: true systemd_slice_name: lxc-dnsmasq systemd_services: - service_name: lxc-dnsmasq state: started enabled: yes execstartpres: | {% set pres = ['-/usr/bin/pkill -u {{ lxc_net_dnsmasq_user }} "^dnsmasq"'] %} {% if lxc_net_manage_iptables | bool %} {% set _ = pres.append('/usr/local/bin/lxc-system-manage iptables-create') %} {% endif%} {{ pres }} execstarts: - /usr/local/bin/lxc-system-manage dnsmasq-start execstops: - -/usr/local/bin/lxc-system-manage dnsmasq-stop execstopposts: | {% set posts = [] %} {% if lxc_net_manage_iptables | bool %} {% set _ = posts.append('-/usr/local/bin/lxc-system-manage iptables-remove') %} {% endif %} {{ posts }} config_overrides: Unit: Before: lxc.service Service: PIDFile: /run/lxc/dnsmasq.pid when: lxc_net_nat | bool # Check that the container bridge exists, if not bring it up - name: Check Container Bridge exists stat: path: "/sys/class/net/{{ lxc_net_bridge }}/bridge/bridge_id" register: bridge_check failed_when: false changed_when: not bridge_check.stat.exists notify: - Bring bridge up tags: - lxc-bridge # Ensure lxc networks are running as they're supposed to - meta: flush_handlers