3d8e3690ba
We also leverage systemd-networkd for managing lxc-net and replace using of custom service template for lxc-dnsmasq service with our systemd-service role. These changes are quite tighten together, so it's quite hard to split them in different patchsets. Depends-On: https://review.opendev.org/c/openstack/ansible-role-systemd_service/+/861350 Change-Id: I5ac99e2b6c6e6ccd9da18ae68e1f8801f95f4f4e
128 lines
4.0 KiB
YAML
128 lines
4.0 KiB
YAML
---
|
|
|
|
# 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: Run the systemd-networkd role
|
|
include_role:
|
|
name: systemd_networkd
|
|
vars:
|
|
systemd_networkd_prefix: "lxc-net"
|
|
systemd_run_networkd: true
|
|
systemd_netdevs:
|
|
- NetDev:
|
|
Name: "{{ lxc_net_bridge }}"
|
|
Kind: bridge
|
|
Bridge:
|
|
ForwardDelaySec: 0
|
|
HelloTimeSec: 2
|
|
MaxAgeSec: 12
|
|
STP: off
|
|
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
|