tripleo-ansible/tripleo_ansible/roles/tripleo_multipathd/tasks/configure.yml

92 lines
2.8 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: Install custom multipath.conf if one is specified
copy:
src: "{{ tripleo_multipathd_custom_config_file }}"
dest: /etc/multipath.conf
mode: 0644
when:
- tripleo_multipathd_custom_config_file|length > 0
- name: Ensure /etc/multipath.conf exists
when:
- tripleo_multipathd_custom_config_file|length == 0
block:
- name: Check for existing /etc/multipath.conf
stat:
path: /etc/multipath.conf
register: result
check_mode: false
- name: Create /etc/multipath.conf if file is missing
copy:
src: "{{ role_path }}/files/multipath.conf"
dest: /etc/multipath.conf
mode: 0644
when:
- not result.stat.exists or result.stat.size == 0
- name: Set setype on /etc/multipath.conf
file:
path: /etc/multipath.conf
setype: container_file_t
- name: Ensure a blacklist section is present
lineinfile:
path: /etc/multipath.conf
regexp: '^blacklist'
line: 'blacklist {'
register: blacklist_section
- name: Terminate the blacklist section if one was added
replace:
path: /etc/multipath.conf
regexp: '^(blacklist {)'
replace: '\1\n}'
when:
- blacklist_section.changed
- name: Remove global blacklist if multipathd is enabled
replace:
path: /etc/multipath.conf
regexp: '^blacklist {\n[\s]+devnode \"\.\*\"'
replace: 'blacklist {'
when:
- tripleo_multipathd_enable | bool
- name: Add global blacklist if multipathd is disabled
lineinfile:
path: /etc/multipath.conf
insertafter: '^blacklist'
regexp: '^[\s]+devnode \"\.\*\"'
line: ' devnode ".*"'
when:
- not (tripleo_multipathd_enable|bool)
- name: Configure /etc/multipath.conf variables
lineinfile:
path: /etc/multipath.conf
insertafter: '^defaults'
firstmatch: true
regexp: "^\\s+{{ item.var }}"
line: " {{ item.var }} {{ (item.value|bool) | ternary('yes', 'no') }}"
loop:
- {var: find_multipaths, value: "{{tripleo_multipathd_find_multipaths}}"}
- {var: skip_kpartx, value: "{{tripleo_multipathd_skip_kpartx}}"}
- {var: user_friendly_names, value: "{{tripleo_multipathd_user_friendly_names}}"}
loop_control:
index_var: multipath_var_index