You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
2.4 KiB
67 lines
2.4 KiB
--- |
|
# 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: Check if lvm2 is installed |
|
shell: rpm -q lvm2 |
|
become: true |
|
failed_when: false |
|
register: lvm_pkg_check |
|
- name: gather allowed block devices list |
|
when: |
|
- lvm_pkg_check.rc is defined |
|
- lvm_pkg_check.rc == 0 |
|
- tripleo_tripleo_lvmfilter_enabled or tripleo_tripleo_lvmfilter_dry_run |
|
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: 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: |
|
lvm2_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='[{{ lvm2_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
|
|
|