eee919ad21
For CentOS/Red Hat and SUSE the network post-up/post-down scripts are configured after the bridge has been brought up, and the handlers have been flushed. We need to configure the post-up and post-down scripts before the restart bridge handler is flushed, so that dnsmasq is configured and running before we attempt to install packages into the container. Change-Id: Ifdb52624ed792665c858b3cdd4eec4b6aa365b1e
116 lines
3.1 KiB
YAML
116 lines
3.1 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.
|
|
|
|
- name: Drop lxc net bridge
|
|
template:
|
|
src: "{{ item.src }}"
|
|
dest: "{{ item.dest }}"
|
|
owner: "root"
|
|
group: "root"
|
|
mode: "{{ item.mode | default('0644') }}"
|
|
with_items: "{{ lxc_cached_network_interfaces }}"
|
|
notify:
|
|
- Restart bridge
|
|
tags:
|
|
- lxc-files
|
|
- lxc-net
|
|
- lxc-bridge
|
|
- lxc-interfaces
|
|
|
|
- name: Drop lxc net bridge routes (SUSE)
|
|
template:
|
|
src: "lxc-net-suse-routes.cfg.j2"
|
|
dest: "/etc/sysconfig/network/ifroute-{{ lxc_net_bridge }}"
|
|
owner: "root"
|
|
group: "root"
|
|
mode: "0644"
|
|
when:
|
|
- lxc_net_gateway is not none
|
|
- ansible_pkg_mgr == "zypper"
|
|
notify:
|
|
- Bring bridge up
|
|
tags:
|
|
- lxc-files
|
|
- lxc-net
|
|
- lxc-bridge
|
|
- lxc-interfaces
|
|
|
|
- name: Create networking post-up and post-down data for Red Hat
|
|
lineinfile:
|
|
dest: "{{ item.dest }}"
|
|
line: "{{ item.line }}"
|
|
insertbefore: "^exit\ 0$"
|
|
with_items:
|
|
- dest: "/etc/sysconfig/network-scripts/ifup-post"
|
|
line: ". /etc/sysconfig/network-scripts/ifup-post-{{ lxc_net_bridge }}"
|
|
- dest: "/etc/sysconfig/network-scripts/ifdown-post"
|
|
line: ". /etc/sysconfig/network-scripts/ifdown-post-{{ lxc_net_bridge }}"
|
|
when: ansible_os_family | lower == "redhat"
|
|
notify:
|
|
- Restart bridge
|
|
tags:
|
|
- lxc-post-up
|
|
- lxc-post-down
|
|
- lxc_hosts-config
|
|
|
|
# NOTE(mhayden): There are ifup hooks that 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
|
|
tags:
|
|
- lxc-net
|
|
|
|
- name: Mask lxc-net systemd service
|
|
file:
|
|
src: /dev/null
|
|
path: /etc/systemd/system/lxc-net.service
|
|
state: link
|
|
tags:
|
|
- lxc-files
|
|
- lxc-net
|
|
|
|
# All Debian based systems use the interfaces.d directory for extra network configs
|
|
# this check ensures the needed source line is in the base config file
|
|
- name: Ensure networking includes interfaces.d
|
|
lineinfile:
|
|
dest: "/etc/network/interfaces"
|
|
line: "source /etc/network/interfaces.d/*.cfg"
|
|
backup: "yes"
|
|
when:
|
|
- ansible_os_family == "Debian"
|
|
tags:
|
|
- lxc-net
|
|
- lxc-interfaces
|
|
|
|
# Check that the container bridge exists, if not bring it up
|
|
- name: Check Container Bridge exists
|
|
file:
|
|
state: "file"
|
|
path: "/sys/class/net/{{ lxc_net_bridge }}/bridge/bridge_id"
|
|
register: bridge_check
|
|
failed_when: false
|
|
changed_when: bridge_check.state == 'absent'
|
|
notify:
|
|
- Bring bridge up
|
|
tags:
|
|
- lxc-bridge
|
|
|
|
# Ensure lxc networks are running as they're supposed to
|
|
- meta: flush_handlers
|