fix ansible-lint errors
This commit is contained in:
@@ -28,13 +28,13 @@ roles:
|
||||
virtual_group: "group"
|
||||
logical_volume: "volume"
|
||||
lvm_dev: "/dev/sda"
|
||||
size: 100%FREE
|
||||
fs_type: ext4
|
||||
storage_mountpoint: "/mnt"
|
||||
storage_mountpoint_mode: "0775"
|
||||
mountpoint_owner: root
|
||||
mountpoint_group: root
|
||||
is_container: false # disables udev in LVM if true
|
||||
make_lv_size: 100%FREE
|
||||
make_lv_fs_type: ext4
|
||||
make_lv_storage_mountpoint: "/mnt"
|
||||
make_lv_storage_mountpoint_mode: "0775"
|
||||
make_lv_mountpoint_owner: root
|
||||
make_lv_mountpoint_group: root
|
||||
make_lv_is_container: false # disables udev in LVM if true
|
||||
```
|
||||
|
||||
Minimal variables
|
||||
@@ -48,13 +48,13 @@ roles:
|
||||
|
||||
Defaults
|
||||
```yaml
|
||||
size: 100%FREE
|
||||
fs_type: ext4
|
||||
storage_mountpoint: "/mnt"
|
||||
storage_mountpoint_mode: "0775"
|
||||
mountpoint_owner: root
|
||||
mountpoint_group: root
|
||||
is_container: false # disables udev in LVM if true
|
||||
make_lv_size: 100%FREE
|
||||
make_lv_fs_type: ext4
|
||||
make_lv_storage_mountpoint: "/mnt"
|
||||
make_lv_storage_mountpoint_mode: "0775"
|
||||
make_lv_mountpoint_owner: root
|
||||
make_lv_mountpoint_group: root
|
||||
make_lv_is_container: false # disables udev in LVM if true
|
||||
```
|
||||
|
||||
License
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
---
|
||||
size: 100%FREE
|
||||
fs_type: ext4
|
||||
storage_mountpoint: "/mnt"
|
||||
storage_mountpoint_mode: "0775"
|
||||
mountpoint_owner: root
|
||||
mountpoint_group: root
|
||||
is_container: false
|
||||
make_lv_size: 100%FREE
|
||||
make_lv_fs_type: ext4
|
||||
make_lv_storage_mountpoint: "/mnt"
|
||||
make_lv_storage_mountpoint_mode: "0775"
|
||||
make_lv_mountpoint_owner: root
|
||||
make_lv_mountpoint_group: root
|
||||
make_lv_is_container: false
|
||||
|
||||
@@ -5,33 +5,33 @@
|
||||
- name: Get /root/image.img stats
|
||||
ansible.builtin.stat:
|
||||
path: /root/image.img
|
||||
register: img_stat
|
||||
register: make_lv_img_stat
|
||||
|
||||
- name: Create image file
|
||||
when: not img_stat.stat.exists
|
||||
when: not make_lv_img_stat.stat.exists
|
||||
ansible.builtin.command: dd if=/dev/zero of=/root/image.img bs=1M count=128
|
||||
register: dd_result
|
||||
changed_when: dd_result.rc == 0
|
||||
register: make_lv_dd_result
|
||||
changed_when: make_lv_dd_result.rc == 0
|
||||
|
||||
- name: Get linked loop devices
|
||||
ansible.builtin.command: losetup -a
|
||||
changed_when: false
|
||||
register: loop_devs
|
||||
register: make_lv_loop_devs
|
||||
|
||||
- name: Link image to loop device
|
||||
when: "'/root/image.img' not in loop_devs.stdout"
|
||||
when: "'/root/image.img' not in make_lv_loop_devs.stdout"
|
||||
ansible.builtin.command: losetup --find --show -P /root/image.img
|
||||
register: loop_device
|
||||
changed_when: "'/dev/loop' in loop_device.stdout"
|
||||
register: make_lv_loop_device
|
||||
changed_when: "'/dev/loop' in make_lv_loop_device.stdout"
|
||||
|
||||
- name: Get all loop devices
|
||||
ansible.builtin.command: losetup -a
|
||||
register: losetup_out
|
||||
register: make_lv_losetup_out
|
||||
changed_when: false
|
||||
|
||||
- name: Find line with /root/image.img
|
||||
ansible.builtin.set_fact:
|
||||
matched_line: "{{ losetup_out.stdout_lines
|
||||
make_lv_matched_line: "{{ make_lv_losetup_out.stdout_lines
|
||||
| select('search', '/root/image.img')
|
||||
| list
|
||||
| first
|
||||
@@ -39,22 +39,22 @@
|
||||
|
||||
- name: Extract loop device name (/dev/loopN)
|
||||
ansible.builtin.set_fact:
|
||||
loop_dev: "{{ matched_line | regex_search('(/dev/loop[0-9]+)', '\\1') | default('') }}"
|
||||
make_lv_loop_dev: "{{ make_lv_matched_line | regex_search('(/dev/loop[0-9]+)', '\\1') | default('') }}"
|
||||
|
||||
- name: Debug result
|
||||
ansible.builtin.debug:
|
||||
msg: "/root/image.img is linked to {{ loop_dev[0] }}"
|
||||
when: loop_dev != ''
|
||||
msg: "/root/image.img is linked to {{ make_lv_loop_dev[0] }}"
|
||||
when: make_lv_loop_dev != ''
|
||||
|
||||
roles:
|
||||
- role: genlab.make_lv
|
||||
- role: genlab.common.make_lv
|
||||
virtual_group: "group"
|
||||
logical_volume: "volume"
|
||||
lvm_dev: "{{ loop_dev[0] }}"
|
||||
size: 100%FREE
|
||||
fs_type: ext4
|
||||
storage_mountpoint: "/mnt"
|
||||
storage_mountpoint_mode: "0755"
|
||||
mountpoint_owner: root
|
||||
mountpoint_group: root
|
||||
is_container: true
|
||||
lvm_dev: "{{ make_lv_loop_dev[0] }}"
|
||||
make_lv_size: 100%FREE
|
||||
make_lv_fs_type: ext4
|
||||
make_lv_storage_mountpoint: "/mnt"
|
||||
make_lv_storage_mountpoint_mode: "0755"
|
||||
make_lv_mountpoint_owner: root
|
||||
make_lv_mountpoint_group: root
|
||||
make_lv_is_container: true
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
virtual_group: "group"
|
||||
logical_volume: "volume"
|
||||
lvm_dev: "/dev/loop0"
|
||||
fs_type: ext4
|
||||
storage_mountpoint: "/mnt"
|
||||
make_lv_fs_type: ext4
|
||||
make_lv_storage_mountpoint: "/mnt"
|
||||
|
||||
tasks:
|
||||
- name: Get volume group list
|
||||
@@ -17,11 +17,11 @@
|
||||
executable: /bin/bash
|
||||
changed_when: false
|
||||
failed_when: false
|
||||
register: vg_list
|
||||
register: make_lv_vg_list
|
||||
|
||||
- name: Assert that volume group exists
|
||||
ansible.builtin.assert:
|
||||
that: virtual_group in vg_list.stdout
|
||||
that: virtual_group in make_lv_vg_list.stdout
|
||||
success_msg: "{{ lvm_dev }} has {{ virtual_group }} group"
|
||||
fail_msg: "{{ lvm_dev }} DOES NOT have {{ virtual_group }} group"
|
||||
|
||||
@@ -31,11 +31,11 @@
|
||||
executable: /bin/bash
|
||||
changed_when: false
|
||||
failed_when: false
|
||||
register: lv_list
|
||||
register: make_lv_lv_list
|
||||
|
||||
- name: Assert that logical volume exists
|
||||
ansible.builtin.assert:
|
||||
that: logical_volume in lv_list.stdout
|
||||
that: logical_volume in make_lv_lv_list.stdout
|
||||
success_msg: "{{ virtual_group }} has {{ logical_volume }} volume"
|
||||
fail_msg: "{{ virtual_group }} DOES NOT have {{ logical_volume }} volume"
|
||||
|
||||
@@ -43,23 +43,23 @@
|
||||
ansible.builtin.command: "blkid /dev/mapper/{{ virtual_group }}-{{ logical_volume }} -o value -s TYPE"
|
||||
changed_when: false
|
||||
failed_when: false
|
||||
register: current_fs
|
||||
register: make_lv_current_fs
|
||||
|
||||
- name: Assert that current filesystem is the required one
|
||||
ansible.builtin.assert:
|
||||
that: current_fs.stdout == fs_type
|
||||
success_msg: "{{ virtual_group }} - {{ logical_volume }} has {{ fs_type }} filesystem"
|
||||
fail_msg: "{{ virtual_group }} - {{ logical_volume }} DOES NOT have {{ fs_type }} filesystem"
|
||||
that: make_lv_current_fs.stdout == make_lv_fs_type
|
||||
success_msg: "{{ virtual_group }} - {{ logical_volume }} has {{ make_lv_fs_type }} filesystem"
|
||||
fail_msg: "{{ virtual_group }} - {{ logical_volume }} DOES NOT have {{ make_lv_fs_type }} filesystem"
|
||||
|
||||
- name: Get logical volume mount info # noqa: command-instead-of-module — tells ansible-lint to ignore the error, because you can't actually
|
||||
# do it with ansible.builtin.mount as the linter begs me to do
|
||||
ansible.builtin.shell: "mount | grep -w '{{ virtual_group }}-{{ logical_volume }}'"
|
||||
register: mount_check
|
||||
register: make_lv_mount_check
|
||||
ignore_errors: true
|
||||
changed_when: false
|
||||
|
||||
- name: Assert that volume is mounted
|
||||
ansible.builtin.assert:
|
||||
that: mount_check.rc == 0
|
||||
success_msg: "{{ virtual_group }}-{{ logical_volume }} is mounted at {{ storage_mountpoint }}"
|
||||
fail_msg: "{{ virtual_group }}-{{ logical_volume }} IS NOT mounted at {{ storage_mountpoint }}"
|
||||
that: make_lv_mount_check.rc == 0
|
||||
success_msg: "{{ virtual_group }}-{{ logical_volume }} is mounted at {{ make_lv_storage_mountpoint }}"
|
||||
fail_msg: "{{ virtual_group }}-{{ logical_volume }} IS NOT mounted at {{ make_lv_storage_mountpoint }}"
|
||||
|
||||
@@ -13,11 +13,11 @@
|
||||
executable: /bin/bash
|
||||
changed_when: false
|
||||
failed_when: false
|
||||
register: vg_list
|
||||
register: make_lv_vg_list
|
||||
|
||||
- name: Assert that volume group exists
|
||||
ansible.builtin.assert:
|
||||
that: virtual_group in vg_list.stdout
|
||||
that: virtual_group in make_lv_vg_list.stdout
|
||||
success_msg: "{{ lvm_dev }} has {{ virtual_group }} group"
|
||||
fail_msg: "{{ lvm_dev }} DOES NOT have {{ virtual_group }} group"
|
||||
|
||||
@@ -27,11 +27,11 @@
|
||||
executable: /bin/bash
|
||||
changed_when: false
|
||||
failed_when: false
|
||||
register: lv_list
|
||||
register: make_lv_lv_list
|
||||
|
||||
- name: Assert that logical volume exists
|
||||
ansible.builtin.assert:
|
||||
that: logical_volume in lv_list.stdout
|
||||
that: logical_volume in make_lv_lv_list.stdout
|
||||
success_msg: "{{ virtual_group }} has {{ logical_volume }} volume"
|
||||
fail_msg: "{{ virtual_group }} DOES NOT have {{ logical_volume }} volume"
|
||||
|
||||
@@ -39,25 +39,25 @@
|
||||
ansible.builtin.command: "blkid /dev/mapper/{{ virtual_group }}-{{ logical_volume }} -o value -s TYPE"
|
||||
changed_when: false
|
||||
failed_when: false
|
||||
register: current_fs
|
||||
register: make_lv_current_fs
|
||||
|
||||
- name: Assert that current filesystem is the required one
|
||||
ansible.builtin.assert:
|
||||
that: current_fs.stdout == fs_type
|
||||
success_msg: "{{ virtual_group }} - {{ logical_volume }} has {{ fs_type }} filesystem"
|
||||
fail_msg: "{{ virtual_group }} - {{ logical_volume }} DOES NOT have {{ fs_type }} filesystem"
|
||||
that: make_lv_current_fs.stdout == make_lv_fs_type
|
||||
success_msg: "{{ virtual_group }} - {{ logical_volume }} has {{ make_lv_fs_type }} filesystem"
|
||||
fail_msg: "{{ virtual_group }} - {{ logical_volume }} DOES NOT have {{ make_lv_fs_type }} filesystem"
|
||||
|
||||
rescue:
|
||||
- name: Unmount the main storage
|
||||
ansible.posix.mount:
|
||||
src: "/dev/{{ virtual_group }}/{{ logical_volume }}"
|
||||
path: "{{ storage_mountpoint }}"
|
||||
path: "{{ make_lv_storage_mountpoint }}"
|
||||
state: absent
|
||||
|
||||
- name: Wipe disk signatures
|
||||
ansible.builtin.command: "wipefs -af {{ lvm_dev }}"
|
||||
register: wipefs_result
|
||||
changed_when: wipefs_result.rc == 0
|
||||
register: make_lv_wipefs_result
|
||||
changed_when: make_lv_wipefs_result.rc == 0
|
||||
|
||||
- name: Create a volume group for the storage
|
||||
community.general.lvg:
|
||||
@@ -66,37 +66,37 @@
|
||||
force: true
|
||||
|
||||
- name: Create a logical volume for the storage
|
||||
when: is_container
|
||||
when: make_lv_is_container
|
||||
community.general.lvol:
|
||||
vg: "{{ virtual_group }}"
|
||||
lv: "{{ logical_volume }}"
|
||||
size: "{{ size }}"
|
||||
size: "{{ make_lv_size }}"
|
||||
opts: "--config 'activation/udev_rules=0'"
|
||||
|
||||
- name: Create a logical volume for the storage
|
||||
when: not is_container
|
||||
when: not make_lv_is_container
|
||||
community.general.lvol:
|
||||
vg: "{{ virtual_group }}"
|
||||
lv: "{{ logical_volume }}"
|
||||
size: "{{ size }}"
|
||||
size: "{{ make_lv_size }}"
|
||||
opts: "--config 'activation/udev_rules=1'"
|
||||
|
||||
- name: Create a filesystem for the storage
|
||||
community.general.filesystem:
|
||||
dev: "/dev/{{ virtual_group }}/{{ logical_volume }}"
|
||||
fstype: "{{ fs_type }}"
|
||||
fstype: "{{ make_lv_fs_type }}"
|
||||
|
||||
- name: Create a mountpoint for the storage
|
||||
ansible.builtin.file:
|
||||
path: "{{ storage_mountpoint }}"
|
||||
path: "{{ make_lv_storage_mountpoint }}"
|
||||
state: directory
|
||||
owner: "{{ mountpoint_owner }}"
|
||||
group: "{{ mountpoint_group }}"
|
||||
mode: "{{ storage_mountpoint_mode }}"
|
||||
owner: "{{ make_lv_mountpoint_owner }}"
|
||||
group: "{{ make_lv_mountpoint_group }}"
|
||||
mode: "{{ make_lv_storage_mountpoint_mode }}"
|
||||
|
||||
- name: Mount the main storage
|
||||
ansible.posix.mount:
|
||||
src: "/dev/{{ virtual_group }}/{{ logical_volume }}"
|
||||
path: "{{ storage_mountpoint }}"
|
||||
fstype: "{{ fs_type }}"
|
||||
path: "{{ make_lv_storage_mountpoint }}"
|
||||
fstype: "{{ make_lv_fs_type }}"
|
||||
state: mounted
|
||||
|
||||
Reference in New Issue
Block a user