openstack-ansible/tests/roles/bootstrap-host/tasks/prepare_networking.yml

151 lines
4.9 KiB
YAML

---
# Copyright 2015, 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: Ensure that /etc/network/interfaces.d/ exists (Debian)
file:
path: /etc/network/interfaces.d/
state: directory
tags:
- networking-dir-create
when:
- ansible_pkg_mgr == 'apt'
- name: Copy AIO network configuration (Debian)
template:
src: osa_interfaces.cfg.j2
dest: /etc/network/interfaces.d/osa_interfaces.cfg
register: osa_interfaces
when:
- bootstrap_host_aio_config | bool
- ansible_pkg_mgr == 'apt'
tags:
- networking-interfaces-file
- name: Copy network configuration (RedHat)
template:
src: "redhat_interface_{{ item.type | default('default') }}.cfg.j2"
dest: "/etc/sysconfig/network-scripts/ifcfg-{{ item.name | default('br-mgmt') }}"
with_items: "{{ bridges }}"
register: network_interfaces_rhel
when:
- ansible_pkg_mgr == 'yum'
- name: Create alias file when required (RedHat)
template:
src: "redhat_interface_alias.cfg.j2"
dest: "/etc/sysconfig/network-scripts/ifcfg-{{ item.name | default('br-mgmt')}}:0"
with_items: "{{ bridges }}"
when:
- ansible_pkg_mgr == 'yum'
- item.alias is defined
- name: Put down post-up script for veth-peer interfaces (RedHat)
template:
src: "redhat_interface_{{ item[0] | default('default') }}.cfg.j2"
dest: "/etc/sysconfig/network-scripts/{{ item[0] }}-veth-{{ item[1].name | default('br-mgmt') }}-2-{{ item[1].veth_peer | default('eth1') }}"
mode: "0755"
with_nested:
- [ "ifup-post", "ifdown-post" ]
- "{{ bridges }}"
when:
- item[1].veth_peer is defined
- ansible_pkg_mgr == 'yum'
- name: Ensure the postup/postdown scripts are loaded (RedHat)
lineinfile:
dest: "/etc/sysconfig/network-scripts/{{ item[0] }}"
line: ". /etc/sysconfig/network-scripts/{{ item[0] }}-veth-{{ item[1].name | default('br-mgmt') }}-2-{{ item[1].veth_peer | default('eth1') }}"
insertbefore: "^exit 0"
with_nested:
- [ "ifup-post", "ifdown-post" ]
- "{{ bridges }}"
when:
- item[1].veth_peer is defined
- ansible_pkg_mgr == 'yum'
- name: Copy multinode network configuration (Debian)
template:
src: osa_interfaces_multinode.cfg.j2
dest: /etc/network/interfaces.d/osa_interfaces.cfg
register: osa_multinode_interfaces
when:
- not bootstrap_host_aio_config | bool
- ansible_pkg_mgr == 'apt'
tags:
- networking-interfaces-file
- name: Ensure our interfaces.d configuration files are loaded automatically (Debian)
lineinfile:
dest: /etc/network/interfaces
line: "source /etc/network/interfaces.d/*.cfg"
when:
- ansible_pkg_mgr == 'apt'
tags:
- networking-interfaces-load
- name: Shut down the network interfaces
command: "ifdown {{ item.name }}"
when:
- osa_interfaces | changed or osa_multinode_interfaces | changed or network_interfaces_rhel | changed
- item.enabled | default(True)
with_items:
- { name: br-mgmt }
- { name: br-storage }
- { name: br-vlan }
- { name: br-vxlan }
- { name: br-dbaas, enabled: "{{ (bootstrap_host_scenario == 'translations') | bool }}" }
- { name: br-lbaas, enabled: "{{ (bootstrap_host_scenario in ['translations', 'octavia']) | bool }}" }
tags:
- networking-interfaces-stop
- name: Shut down the encapsulation network interfaces
command: "ifdown {{ item.key }}"
when:
- osa_multinode_interfaces | changed
- bootstrap_host_encapsulation_enabled | bool
with_dict: "{{ bootstrap_host_encapsulation_interfaces }}"
tags:
- networking-interfaces-stop
- name: Start the encapsulation network interfaces
command: "ifup {{ item.key }}"
when:
- osa_multinode_interfaces | changed
- bootstrap_host_encapsulation_enabled | bool
with_dict: "{{ bootstrap_host_encapsulation_interfaces }}"
tags:
- networking-interfaces-start
- name: Start the network interfaces
command: "ifup {{ item.name }}"
when:
- osa_interfaces | changed or network_interfaces_rhel | changed
- item.enabled | default(True)
with_items:
- { name: br-mgmt }
- { name: br-storage }
- { name: br-vlan }
- { name: br-vxlan }
- { name: br-dbaas, enabled: "{{ (bootstrap_host_scenario == 'translations') | bool }}" }
- { name: br-lbaas, enabled: "{{ (bootstrap_host_scenario in ['translations', 'octavia']) | bool }}" }
tags:
- networking-interfaces-start
- name: Updating the facts due to net changes
setup:
filter: "ansible_br*"
tags:
- networking