Skip to content

Commit d701e00

Browse files
committed
Install packages according to package_facts module and ansible_facts.packages
Update the installation task conditionals to check whether the current package is already a subset of rpm packages installed in the hosts machine. This way, we don't need to track a list of packages we've installed on the playbook run thus far.
1 parent 0f974e7 commit d701e00

File tree

5 files changed

+48
-38
lines changed

5 files changed

+48
-38
lines changed

defaults/main.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +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-
storage_packages: []
7-
86
use_partitions: false
97
disklabel_type: gpt
108

tasks/fs-default.yml

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,34 @@
22
- name: Stat the final device file
33
include_tasks: stat_device.yml
44

5-
- block:
6-
- name: Install xfsprogs for xfs file system type
7-
package:
8-
name: xfsprogs
9-
state: present
10-
- set_fact:
11-
storage_packages: "{{ storage_packages + ['xfsprogs'] }}"
12-
when: "'xfsprogs' not in storage_packages and volume.fs_type == 'xfs' and not ansible_check_mode"
5+
- name: Install xfsprogs for xfs file system type
6+
package:
7+
name: xfsprogs
8+
state: present
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.state in 'present' and volume.state in 'present')"
1313

14-
- block:
15-
- name: Install e2fsprogs for ext file system type
16-
package:
17-
name: e2fsprogs
18-
state: present
19-
- set_fact:
20-
storage_packages: "{{ storage_packages + ['e2fsprogs'] }}"
21-
when: "'e2fsprogs' not in storage_packages and volume.fs_type in ['ext2', 'ext3', 'ext4'] and not ansible_check_mode"
14+
- name: Install e2fsprogs for ext file system type
15+
package:
16+
name: e2fsprogs
17+
state: present
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.state in 'present' and volume.state in 'present')"
2223

23-
- block:
24-
- name: Install util-linux as needed
25-
package:
26-
name: util-linux
27-
state: present
28-
- set_fact:
29-
storage_packages: "{{ storage_packages + ['util-linux'] }}"
30-
when: "'util-linux' not in storage_packages and (volume.fs_type == 'swap' or volume.state == 'absent' or (pool.state is defined and pool.state == 'absent')) and not ansible_check_mode"
24+
- name: Install util-linux as needed
25+
package:
26+
name: util-linux
27+
state: present
28+
register: util_linux_installed
29+
when: "(volume.fs_type == 'swap' or volume.state == 'absent' or \
30+
(pool.state is defined and pool.state == 'absent')) and \
31+
['util-linux'] is not subset(ansible_facts.packages.keys()) and \
32+
util_linux_installed is undefined and not ansible_check_mode"
3133

3234
- name: unmount fs if we're going to reformat
3335
mount:

tasks/lv-default.yml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
---
22
- block:
3-
- name: Install LVM2 commands as needed
4-
package:
5-
name: lvm2
6-
state: present
7-
- set_fact:
8-
storage_packages: "{{ storage_packages + ['lvm2'] }}"
9-
when: "'lvm2' not in storage_packages and volume.type == 'lvm' and not ansible_check_mode"
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"
1014

1115
- name: Make sure LV exists
1216
lvol:

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/vg-default.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99
package:
1010
name: lvm2
1111
state: present
12-
- name: Update ansible_facts after installing lvm2
12+
- name: Run the setup module to use ansible_facts.lvm
1313
setup:
14-
- set_fact:
15-
storage_packages: "{{ storage_packages + ['lvm2'] }}"
16-
when: "'lvm2' not in storage_packages and pool.type == 'lvm' and not ansible_check_mode"
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"
1719

1820
- block:
1921
- name: collect list of current pvs
@@ -50,7 +52,8 @@
5052
- name: Set pvs from current vg
5153
set_fact:
5254
pool: "{{ pool|combine({'_orig_members': pvs_cmd.stdout.split()}) }}"
53-
when: pool.type == "lvm" and ansible_facts.lvm is defined and pool.name in ansible_facts.lvm.vgs and not pvs_cmd.failed and not ansible_check_mode
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"
5457

5558
#
5659
# Configure the VG

0 commit comments

Comments
 (0)