Execution
Date 15 Dec 2025 09:38:00 +0000
Duration 00:17:22.68
Controller aio1.openstack.local
User root
Versions
Ansible 2.18.6
ara 1.7.4 / 1.7.4
Python 3.12.3
Summary
18 Hosts
603 Tasks
2798 Results
18 Plays
138 Files
0 Records

File: /home/zuul/src/opendev.org/openstack/openstack-ansible-lxc_hosts/tasks/lxc_net.yml

---
# 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)
  ansible.builtin.service:
    name: NetworkManager-wait-online.service
    enabled: true
  when: networkmanager_check.rc == 0

# 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
  ansible.builtin.systemd:
    name: lxc-net
    enabled: false
    state: stopped
    masked: true
  tags:
    - lxc-net

- name: Setup LXC OVS Bridge
  openvswitch.openvswitch.openvswitch_bridge:
    bridge: "{{ lxc_net_bridge }}"
    fail_mode: standalone
    state: present
  when: lxc_net_bridge_type == 'openvswitch'

- name: Run the systemd-networkd role
  ansible.builtin.include_role:
    name: systemd_networkd
  vars:
    _lxc_net_bridge_devices:
      - NetDev:
          Name: "{{ lxc_net_bridge }}"
          Kind: bridge
          MTUBytes: "{{ lxc_net_mtu }}"
        Bridge:
          ForwardDelaySec: 0
          HelloTimeSec: 2
          MaxAgeSec: 12
          STP: false
    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 }}"
        mtu: "{{ lxc_net_mtu }}"
        config_overrides:
          Network:
            ConfigureWithoutCarrier: true
            Gateway: "{{ lxc_net_gateway is not none | ternary(lxc_net_gateway, {}) }}"

- name: Run the systemd-service role
  ansible.builtin.include_role:
    name: systemd_service
  vars:
    systemd_service_enabled: true
    systemd_slice_name: lxc-dnsmasq
    systemd_services:
      - service_name: lxc-dnsmasq
        state: started
        enabled: true
        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
  ansible.builtin.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
- name: Flush handlers
  ansible.builtin.meta: flush_handlers