tripleo-ansible/tripleo_ansible/roles/tripleo_network_config/tasks/main.yml

123 lines
3.9 KiB
YAML

---
# Copyright 2020 Red Hat, Inc.
# All Rights Reserved.
#
# 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: Gather SELinux fact if needed
when:
- ansible_facts.selinux is undefined
setup:
gather_subset:
- "!all"
- "!min"
- "selinux"
- name: Create fcontext entry for tripleoconfig
become: true
when:
- ansible_facts.selinux.status == "enabled"
sefcontext:
target: "/var/lib/tripleo-config(/.*)?"
setype: container_file_t
selevel: s0
state: present
- name: Ensure /var/lib/tripleo-config directory exists
become: true
file:
path: /var/lib/tripleo-config
state: directory
setype: container_file_t
selevel: s0
- name: Check for previous run of NetworkConfig
become: true
stat:
path: /var/lib/tripleo-config/os-net-config.returncode
register: os_net_config_returncode_stat
- name: Check result of previous run of NetworkConfig
become: true
slurp:
path: /var/lib/tripleo-config/os-net-config.returncode
when: os_net_config_returncode_stat.stat.exists
register: os_net_config_returncode_slurp
- name: NetworkConfig
become: true
block:
- name: Create /etc/os-net-config directory
become: true
file:
path: /etc/os-net-config
state: directory
recurse: true
- name: Create os-net-config mappings from lookup data
tripleo_os_net_config_mappings:
net_config_data_lookup:
"{{ tripleo_network_config_os_net_config_mappings }}"
when: not ansible_check_mode|bool
register: os_net_config_mappings_result
- name: Write os-net-config mappings file /etc/os-net-config/mapping.yaml
copy:
content: "{{ os_net_config_mappings_result.mapping | to_nice_yaml }}"
dest: /etc/os-net-config/mapping.yaml
when: os_net_config_mappings_result.changed|bool
- name: Manage NetworkConfig with tripleo_os_net_config module
block:
- name: Remove /var/lib/tripleo-config/scripts directory
file:
path: /var/lib/tripleo-config/scripts
state: absent
- name: Run NetworkConfig with tripleo_os_net_config
include_tasks: os_net_config.yml
- name: Write rc of NetworkConfig script
copy:
content: "{{ NetworkConfig_result.rc }}"
dest: /var/lib/tripleo-config/os-net-config.returncode
when:
- NetworkConfig_result.rc is defined
# os-net-config currently relies on the legacy network
# so we need to ensure it's enabled on boot. This should
# be removed when we switch to NetworkManager or replaced
# with something that ensures NetworkManager is enabled.
- name: Ensure network service is enabled
systemd:
name: network
enabled: true
when:
- tripleo_network_config_manage_service
- not ansible_check_mode|bool
# The conditions here are when we want to apply the
# NetworkConfig. They are:
# - If tripleo_network_config_update is True
# - Or the previous run of NetworkConfig failed.
# - Or it has never run
# This will match the prior behavior of when a Heat
# SoftwareDeployment was used.
# It also ensures the script does exist as a sine qua non
# condition
when:
- (tripleo_network_config_update) or
(os_net_config_returncode_stat.stat.exists and
((os_net_config_returncode_slurp.content | b64decode | int) != 0)) or
(not os_net_config_returncode_stat.stat.exists)