Skip to content

Commit c82378d

Browse files
authored
Merge pull request #2 from timflannagan1/install-commands
Update installation tasks to speed up playbook execution
2 parents 634ac74 + 5096bf8 commit c82378d

File tree

8 files changed

+56
-20
lines changed

8 files changed

+56
-20
lines changed

defaults/main.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
storage_backend: "default"
44
pool_layers: ["pool-partitions", "vg"] # md, luks, vdo under vg
55
volume_layers: ["partition", "lv", "fs", "mount"] # luks under fs
6-
76
use_partitions: false
87
disklabel_type: gpt
98

tasks/fs-default.yml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,30 @@
66
package:
77
name: xfsprogs
88
state: present
9-
when: volume.fs_type == "xfs" and not ansible_check_mode
9+
register: xfsprogs_installed
10+
when: "volume.fs_type == 'xfs' and ['xfsprogs'] is not subset(ansible_facts.packages.keys()) \
11+
and xfsprogs_installed is undefined and not ansible_check_mode \
12+
and ((pool is defined and pool.state in 'present') or volume.state in 'present')"
1013

1114
- name: Install e2fsprogs for ext file system type
1215
package:
1316
name: e2fsprogs
1417
state: present
15-
when: volume.fs_type in ["ext2", "ext3", "ext4"]
18+
register: e2fsprogs_installed
19+
when: "volume.fs_type in ['ext2', 'ext3', 'ext4'] and \
20+
['e2fsprogs'] is not subset(ansible_facts.packages.keys()) and \
21+
e2fsprogs_installed is undefined and not ansible_check_mode \
22+
and ((pool is defined and pool.state in 'present') or volume.state in 'present')"
1623

1724
- name: Install util-linux as needed
1825
package:
1926
name: util-linux
2027
state: present
21-
when: volume.fs_type == "swap" or volume.state == "absent" or (pool.state is defined and pool.state == "absent")
28+
register: util_linux_installed
29+
when: "(volume.fs_type == 'swap' or volume.state == 'absent' or
30+
(pool is defined and pool.state is defined and pool.state == 'absent'))
31+
and ['util-linux'] is not subset(ansible_facts.packages.keys()) and
32+
util_linux_installed is undefined and not ansible_check_mode"
2233

2334
- name: unmount fs if we're going to reformat
2435
mount:

tasks/lv-default.yml

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
---
2-
- name: Install LVM2 commands as needed
3-
package:
4-
name: lvm2
5-
state: present
6-
when: volume.type == "lvm"
2+
- block:
3+
- name: Install LVM2 commands as needed
4+
package:
5+
name: lvm2
6+
state: present
7+
- name: Run the setup module to use ansible_facts.lvm
8+
setup:
9+
- name: Ensure the setup module runs above by setting a flag that lvm was installed
10+
set_fact:
11+
lvm_installed: true
12+
when: "volume.type == 'lvm' and (['lvm2'] is not subset(ansible_facts.packages.keys()) and \
13+
lvm_installed is undefined) and not ansible_check_mode"
714

815
- name: Make sure LV exists
916
lvol:
@@ -13,4 +20,4 @@
1320
state: "{{ volume.state if pool.state != 'absent' else pool.state }}"
1421
force: yes
1522
shrink: no
16-
when: volume.type == "lvm" and pool.name
23+
when: volume.type == "lvm" and ansible_facts.lvm is defined and pool.name

tasks/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
---
2+
- name: get a list of rpm packages installed on host machine
3+
package_facts:
4+
manager: "auto"
25

36
- name: manage pools
47
include_tasks: pool-{{ storage_backend }}.yml

tasks/mount-default.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
- name: configure mount state (2/2)
3030
set_fact:
3131
mount_state: "{{ pool.state }}"
32-
when: pool.state is defined and pool.state == "absent"
32+
when: pool is defined and pool.state is defined and pool.state == "absent"
3333

3434
# Set up the mount using a stable device identifier.
3535
- name: Set up the mount

tasks/pool-default.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
- name: see if pool already exists
4040
set_fact:
4141
pool: "{{ pool|combine({'_preexist': pool.name in ansible_facts.lvm.vgs}) }}"
42-
when: pool.type == "lvm"
42+
when: ansible_facts.lvm is defined and pool.type == "lvm"
4343

4444
#
4545
# XXX This is only going to remove fstab entries etc. for volumes explicitly listed.

tasks/pool-partition-default.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
---
2+
- name: Install parted for partition management
3+
package:
4+
name: parted
5+
state: present
6+
register: parted_installed
7+
# update this condition when current use_partitions issue (#5) is fixed.
8+
when: "use_partitions and ['parted'] is not subset(ansible_facts.packages.keys()) \
9+
and parted_installed is undefined and not ansible_check_mode"
210

311
- block:
412
- name: set up partition parameters

tasks/vg-default.yml

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,19 @@
44
#
55
# TODO: Decide on semantics. Playbook PV specs should probably be complete to enable idempotency.
66
#
7-
- name: Install LVM2 commmands as needed
8-
package:
9-
name: lvm2
10-
state: present
11-
when: pool.type == "lvm"
12-
7+
- block:
8+
- name: Install LVM2 commands as needed
9+
package:
10+
name: lvm2
11+
state: present
12+
- name: Run the setup module to use ansible_facts.lvm
13+
setup:
14+
- name: Ensure the setup module runs above by setting a flag that lvm was installed
15+
set_fact:
16+
lvm_installed: true
17+
when: "pool.type == 'lvm' and (['lvm2'] is not subset(ansible_facts.packages.keys()) and \
18+
lvm_installed is undefined) and not ansible_check_mode"
19+
1320
- block:
1421
- name: collect list of current pvs
1522
command: pvs -o name --noheadings --select 'vg_name={{ pool.name }}'
@@ -40,12 +47,13 @@
4047
rescue:
4148
- debug:
4249
msg: "Failed to run pvs"
43-
when: pool.type == "lvm" and pool.name in ansible_facts.lvm.vgs
50+
when: pool.type == "lvm" and ansible_facts.lvm is defined and pool.name in ansible_facts.lvm.vgs
4451

4552
- name: Set pvs from current vg
4653
set_fact:
4754
pool: "{{ pool|combine({'_orig_members': pvs_cmd.stdout.split()}) }}"
48-
when: pool.type == "lvm" and pool.name in ansible_facts.lvm.vgs and not pvs_cmd.failed
55+
when: "pool.type == 'lvm' and ansible_facts.lvm is defined and pool.name in \
56+
ansible_facts.lvm.vgs and not pvs_cmd.failed and not ansible_check_mode"
4957

5058
#
5159
# Configure the VG

0 commit comments

Comments
 (0)