Cleaned up tasks

These changes include:
- Cleaning up logic of conditionals for more clarity
- Naming of tasks as some were either missing or incorrect
- Removing unnecessary parens, etc.
- Closes #37
This commit is contained in:
Larry Smith Jr
2020-04-19 12:06:00 -04:00
parent c9a9e1660e
commit 9f37fa3ed1
5 changed files with 137 additions and 155 deletions
+49 -64
View File
@@ -1,22 +1,22 @@
--- ---
- name: manage_lvm | unmounting filesystem(s) - name: create_fs | unmounting filesystem(s)
mount: mount:
path: "{{ lv.mntp }}" path: "{{ lv.mntp }}"
src: "/dev/{{ vg.vgname }}/{{ lv.lvname }}" src: "/dev/{{ vg.vgname }}/{{ lv.lvname }}"
fstype: "{{ lv.filesystem | default(omit) }}" fstype: "{{ lv.filesystem | default(omit) }}"
state: "absent" state: absent
become: true become: true
loop: "{{ vg.lvnames }}" loop: "{{ vg.lvnames }}"
loop_control: loop_control:
loop_var: lv loop_var: lv
when: > when:
(lv is defined and - lv is defined
lv != 'None') and - lv != 'None'
(lv.create is defined and - lv.create is defined
not lv.create and - not lv.create|bool
lv.filesystem != "swap") - lv.filesystem != "swap"
- name: manage_lvm | creating new filesystem on new LVM logical volume(s) - name: create_fs | creating new filesystem on new LVM logical volume(s)
filesystem: filesystem:
fstype: "{{ lv.filesystem }}" fstype: "{{ lv.filesystem }}"
dev: "/dev/{{ vg.vgname }}/{{ lv.lvname }}" dev: "/dev/{{ vg.vgname }}/{{ lv.lvname }}"
@@ -25,23 +25,19 @@
loop_control: loop_control:
loop_var: lv loop_var: lv
become: true become: true
when: > when:
( - vg.create is defined
(vg.create is defined and - vg.create|bool
vg.create) and - lv is defined
(lv is defined and - lv != 'None'
lv != 'None') and - lv.create is defined
(lv.create is defined and - lv.create|bool
lv.create) and - lv.filesystem is defined
( - lv.filesystem != 'None'
lv.filesystem is defined and - lv.filesystem != 'xfs'
lv.filesystem != 'None' and
lv.filesystem != 'xfs'
)
)
# unable to resize xfs: looks like we've to reference the mountpoint instead of the device
- name: lvm | check already converted # unable to resize xfs: looks like we've to reference the mountpoint instead of the device
- name: create_fs | check already converted
# at least xfs is executed twice if the partition has changed in the meantime # at least xfs is executed twice if the partition has changed in the meantime
# then it tries to recreate the fs on the mounted fs which indeed fails... # then it tries to recreate the fs on the mounted fs which indeed fails...
shell: "xfs_info {{ lv.mntp }} | grep -c 'ftype=1'" shell: "xfs_info {{ lv.mntp }} | grep -c 'ftype=1'"
@@ -51,22 +47,15 @@
loop_var: lv loop_var: lv
register: mountedxfs register: mountedxfs
ignore_errors: true ignore_errors: true
changed_when: no changed_when: false
when: > when:
( - lv is defined and lv != 'None'
(lv is defined and lv != 'None') and - lv.filesystem is defined
( - lv.filesystem == "xfs"
lv.filesystem is defined and - lv.create is defined
lv.filesystem == "xfs" - lv.create|bool
)
and
(
lv.create is defined and
lv.create
)
)
- name: manage_lvm | creating new xfs filesystem on new LVM logical volume(s) - name: create_fs | creating new xfs filesystem on new LVM logical volume(s)
filesystem: filesystem:
fstype: "{{ lv.filesystem }}" fstype: "{{ lv.filesystem }}"
dev: "/dev/{{ vg.vgname }}/{{ lv.lvname }}" dev: "/dev/{{ vg.vgname }}/{{ lv.lvname }}"
@@ -74,37 +63,33 @@
loop_control: loop_control:
loop_var: lv loop_var: lv
become: true become: true
when: > when:
( - mountedxfs is failed
mountedxfs is failed and - vg.create is defined
(vg.create is defined and - vg.create|bool
vg.create) and - lv is defined
(lv is defined and - lv != 'None'
lv != 'None') and - lv.create is defined
(lv.create is defined and - lv.create|bool
lv.create) and - lv.filesystem is defined
( - lv.filesystem == 'xfs'
lv.filesystem is defined and
lv.filesystem == 'xfs'
)
)
- name: manage_lvm | mounting new filesystem(s) - name: create_fs | mounting new filesystem(s)
mount: mount:
path: "{{ lv.mntp }}" path: "{{ lv.mntp }}"
src: "/dev/{{ vg.vgname }}/{{ lv.lvname }}" src: "/dev/{{ vg.vgname }}/{{ lv.lvname }}"
fstype: "{{ lv.filesystem }}" fstype: "{{ lv.filesystem }}"
state: "mounted" state: mounted
opts: "{{ lv.mopts | default('defaults') }}" opts: "{{ lv.mopts | default('defaults') }}"
become: true become: true
loop: "{{ vg.lvnames }}" loop: "{{ vg.lvnames }}"
loop_control: loop_control:
loop_var: lv loop_var: lv
when: > when:
((vg.create is defined and - vg.create is defined
vg.create) and - vg.create|bool
lv != 'None' and - lv != 'None'
(lv.create is defined and - lv.create is defined
lv.create) and - lv.create|bool
(lv.mount is defined and - lv.mount is defined
lv.mount)) - lv.mount|bool
+12 -14
View File
@@ -1,10 +1,10 @@
--- ---
- name: "debug vg" - name: create_lv | Display Volume Group
debug: debug:
var: vg var: vg
verbosity: 2 verbosity: 2
- name: "debug lvm" - name: create_lv | debug lvm
loop: "{{ vg.lvnames }}" loop: "{{ vg.lvnames }}"
debug: debug:
var: lv var: lv
@@ -12,24 +12,22 @@
loop_control: loop_control:
loop_var: lv loop_var: lv
- name: manage_lvm | creating new LVM logical volume(s) - name: create_lv | creating new LVM logical volume(s)
lvol: lvol:
vg: "{{ vg.vgname }}" vg: "{{ vg.vgname }}"
lv: "{{ lv.lvname }}" lv: "{{ lv.lvname }}"
size: "{{ lv.size }}" size: "{{ lv.size }}"
shrink: no shrink: false
opts: "{{ lv.opts | default('') }}" opts: "{{ lv.opts | default('') }}"
state: "present" state: present
loop: "{{ vg.lvnames }}" loop: "{{ vg.lvnames }}"
loop_control: loop_control:
loop_var: lv loop_var: lv
become: true become: true
when: > when:
( - vg.create is defined
(vg.create is defined - vg.create|bool
and vg.create) and - lv is defined
(lv is defined and - lv != 'None'
lv != 'None') and - lv.create is defined
(lv.create is defined and - lv.create|bool
lv.create)
)
+5 -6
View File
@@ -1,12 +1,11 @@
--- ---
- name: create_vg | creating new LVM volume group(s)
- name: manage_lvm | creating new LVM volume group(s)
lvg: lvg:
vg: "{{ item.vgname }}" vg: "{{ item.vgname }}"
pvs: "{{ item.disks | join(',') }}" pvs: "{{ item.disks | join(',') }}"
state: "present" state: present
become: true become: true
loop: "{{ lvm_groups }}" loop: "{{ lvm_groups }}"
when: > when:
item.create is defined and - item.create is defined
item.create - item.create|bool
+11 -11
View File
@@ -18,23 +18,23 @@
lvol: lvol:
vg: "{{ item.0.vgname }}" vg: "{{ item.0.vgname }}"
lv: "{{ item.1.lvname }}" lv: "{{ item.1.lvname }}"
state: "absent" state: absent
force: yes force: true
become: true become: true
loop: "{{ lvm_groups|subelements('lvnames') }}" loop: "{{ lvm_groups|subelements('lvnames') }}"
when: > when:
(item.1 is defined and - item.1 is defined
item.1 != 'None') and - item.1 != 'None'
(item.1.create is defined and - item.1.create is defined
not item.1.create) - not item.1.create|bool
- name: manage_lvm | Removing LVM volume group(s) - name: manage_lvm | Removing LVM volume group(s)
lvg: lvg:
vg: "{{ item.vgname }}" vg: "{{ item.vgname }}"
pvs: "{{ item.disks | join(',') }}" pvs: "{{ item.disks | join(',') }}"
state: "absent" state: absent
become: true become: true
loop: "{{ lvm_groups }}" loop: "{{ lvm_groups }}"
when: > when:
item.create is defined and - item.create is defined
not item.create - not item.create|bool