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

68 lines
2.5 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 package facts
package_facts:
manager: auto
- name: gather allowed block devices list
when: "'lvm2' in ansible_facts.packages"
block:
- name: collect in-use lvm2 devices list
become: true
lvm2_physical_devices_facts:
- name: set allowed_devices
set_fact:
allowed_devices: "{{ (ansible_facts['lvm2_active_pvs'] | default([]) | list)
| intersect(ansible_devices.keys())
+ (tripleo_tripleo_lvmfilter_devices_allowlist | default([]))
| unique }}"
- name: create lvm.conf with global_filter
when:
- allowed_devices is defined
- (allowed_devices | length) > 0
block:
- name: build lvm2 allow list
set_fact:
lvm2_allow_list: "\"{{ allowed_devices | map('regex_replace', '(.+)', 'a|\\1|')
| join('\",\"') }}\""
- name: build lvm2 deny list
set_fact:
lvm2_deny_list: "\"{{ tripleo_tripleo_lvmfilter_devices_denylist | default([])
| map('regex_replace', '(.+)', 'r|\\1|') | join('\",\"') }}\""
- name: build lvm2 filter
set_fact:
filter: "{{ lvm2_allow_list + ',' + lvm2_deny_list }}"
- name: regenerate lvm config
become: true
command: >
lvmconfig -f /tmp/tripleo_lvmfilter.conf
--mergedconfig --withgeneralpreamble --withspaces --withsummary --withcomments --ignorelocal --showdeprecated
--config devices/global_filter='[{{ filter }}]'
- name: copy new lvm.conf in place
become: true
copy:
remote_src: true
src: /tmp/tripleo_lvmfilter.conf
dest: /etc/lvm/lvm.conf
owner: root
group: root
mode: '0644'
backup: true
when: tripleo_tripleo_lvmfilter_enabled
notify:
- Refresh LVM caches