Skip to content

Commit 2ac73a7

Browse files
authored
Merge pull request #6 from sscheib/ft-lint_fixes
Lint fixes + fixing undefined users
2 parents 79f2fed + b42f853 commit 2ac73a7

10 files changed

+88
-84
lines changed

.ansible-lint

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
---
2-
enable_list:
3-
- 'args'
4-
- 'empty-string-compare'
5-
- 'no-log-password'
6-
- 'no-same-owner'
7-
- 'name[prefix]'
2+
exclude_paths:
3+
- '.git/'
4+
- 'files/'
85

96
kinds:
7+
- tasks: 'tasks/*.{yml,yaml}'
8+
- vars: 'vars/*.{yml,yaml}'
9+
- vars: 'defaults/*.{yml,yaml}'
10+
- meta: 'meta/main.{yml,yaml}'
1011
- yaml: '.ansible-lint'
1112
- yaml: '.github/workflows/*.{yml,yaml}'
1213
- yaml: '.pre-commit-config.yaml'
1314
- yaml: '.yamllint'
14-
- yaml: '**/*.{yml,yaml}'
15+
- yaml: 'collections/requirements.yml'
1516

1617
loop_var_prefix: '^(__|{role}_)'
1718
max_block_depth: 20

tasks/assert.yml

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
# NOTE: _quiet_assert does not impact this task, as it first needs to be ensured that it actually is
33
# properly defined
4-
- name: 'Ensure mandatory variables, as well as variables, which have a default value, are set (boolean)'
4+
- name: 'assert | Ensure mandatory variables, as well as variables, which have a default value, are set (boolean)'
55
ansible.builtin.assert:
66
that:
77
- "lookup('ansible.builtin.vars', item) is defined"
@@ -21,7 +21,7 @@
2121
loop_control:
2222
label: 'variable: {{ item }}'
2323

24-
- name: 'Ensure mandatory variables, as well as variables, which have a default value, are set (string)'
24+
- name: 'assert | Ensure mandatory variables, as well as variables, which have a default value, are set (string)'
2525
ansible.builtin.assert:
2626
that:
2727
- "lookup('ansible.builtin.vars', item) is defined"
@@ -63,7 +63,7 @@
6363
loop_control:
6464
label: 'variable: {{ item }}'
6565

66-
- name: 'Ensure mandatory variables, as well as variables, which have a default value, are set (integer)'
66+
- name: 'assert | Ensure mandatory variables, as well as variables, which have a default value, are set (integer)'
6767
ansible.builtin.assert:
6868
that:
6969
- "lookup('ansible.builtin.vars', item) is defined"
@@ -80,7 +80,7 @@
8080
loop_control:
8181
label: 'variable: {{ item }}'
8282

83-
- name: 'Ensure kickstart path is set when defined'
83+
- name: 'assert | Ensure kickstart path is set when defined'
8484
ansible.builtin.assert:
8585
that:
8686
- '_kickstart_path is string'
@@ -91,7 +91,7 @@
9191
quiet: '{{ _quiet_assert }}'
9292
when: '_kickstart_path is defined'
9393

94-
- name: 'Ensure kickstart root password is set when defined'
94+
- name: 'assert | Ensure kickstart root password is set when defined'
9595
ansible.builtin.assert:
9696
that:
9797
- '_kickstart_root_password is string'
@@ -103,7 +103,7 @@
103103
no_log: true
104104
when: '_kickstart_root_password is defined'
105105

106-
- name: 'Ensure api_token is defined properly (string)'
106+
- name: 'assert | Ensure api_token is defined properly (string)'
107107
ansible.builtin.assert:
108108
that:
109109
- '_api_token is defined'
@@ -115,7 +115,7 @@
115115
quiet: '{{ _quiet_assert }}'
116116
no_log: true
117117

118-
- name: 'Ensure optional variables, are defined properly, if set (list)'
118+
- name: 'assert | Ensure optional variables, are defined properly, if set (list)'
119119
ansible.builtin.assert:
120120
that:
121121
- "lookup('ansible.builtin.vars', __var) is defined"
@@ -136,7 +136,7 @@
136136
loop_var: '__var'
137137
label: 'variable: {{ __var }}'
138138

139-
- name: 'Ensure post_sections are defined properly'
139+
- name: 'assert | Ensure post_sections are defined properly'
140140
ansible.builtin.assert:
141141
that:
142142
- '_section.name is defined'
@@ -159,7 +159,7 @@
159159
_post_sections is defined
160160
and _post_sections | length > 0
161161
162-
- name: 'Ensure _users is defined properly'
162+
- name: 'assert | Ensure _users is defined properly'
163163
ansible.builtin.assert:
164164
that:
165165
# _user.name
@@ -243,7 +243,7 @@
243243
_users is defined
244244
and _users | length > 0
245245
246-
- name: 'Ensure _users does not specify conflicting options'
246+
- name: 'assert | Ensure _users does not specify conflicting options'
247247
ansible.builtin.assert:
248248
that:
249249
- '_user.home is defined'
@@ -260,13 +260,13 @@
260260
_user.authorized_keys is defined
261261
and _user.authorized_keys | length > 0
262262
263-
- name: 'Skip block if no variables defined beforehand'
263+
- name: 'assert | Skip block if no variables defined beforehand'
264264
when: >
265265
__tmp_list_variables.results is defined and
266266
__tmp_list_variables.results | map(attribute='skipped', default=[]) | select() | length > 0
267267
block:
268268

269-
- name: 'Show variables that have been skipped to check, due to being undefined'
269+
- name: 'assert | Show variables that have been skipped to check, due to being undefined'
270270
ansible.builtin.debug:
271271
msg: 'Variable name: {{ __var }}'
272272
loop:
@@ -275,7 +275,7 @@
275275
loop_var: '__var'
276276
label: '{{ __var }}'
277277

278-
- name: 'Ensure above variables are not important to you, as they are not going to be used!'
278+
- name: 'assert | Ensure above variables are not important to you, as they are not going to be used!'
279279
ansible.builtin.pause:
280280
seconds: 5
281281
...

tasks/authenticate.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
- name: 'Authenticate on the Red Hat Portal'
2+
- name: 'authenticate | Authenticate on the Red Hat Portal'
33
ansible.builtin.uri:
44
url: '{{ _redhat_portal_auth_url }}'
55
return_content: true
@@ -12,7 +12,7 @@
1212
register: '__t_auth'
1313
no_log: true
1414

15-
- name: 'Ensure access token has been returned by the API'
15+
- name: 'authenticate | Ensure access token has been returned by the API'
1616
ansible.builtin.assert:
1717
that:
1818
- '__t_auth.json is defined'
@@ -30,7 +30,7 @@
3030
quiet: '{{ _quiet_assert }}'
3131
no_log: true
3232

33-
- name: 'Set fact: Extract access token'
33+
- name: 'authenticate | Set fact: Extract access token'
3434
ansible.builtin.set_fact:
3535
__access_token: '{{ __t_auth.json.access_token }}'
3636
...

tasks/build_user_statement.yml

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,59 @@
11
---
2-
- name: 'Set fact: Start building the user statement for user {{ _user.name }}'
2+
- name: 'build_user_statement | Set fact: Start building the user statement for user {{ _user.name }}'
33
ansible.builtin.set_fact:
44
_user_statement: "{{ 'user --name=' ~ _user.name }}"
55

6-
- name: 'Set fact: Insert gecos into the user statement for user {{ _user.name }}'
6+
- name: 'build_user_statement | Set fact: Insert gecos into the user statement for user {{ _user.name }}'
77
ansible.builtin.set_fact:
88
_user_statement: "{{ _user_statement ~ ' --gecos=\"' ~ _user.gecos ~ '\"' }}"
99
when: >
1010
_user.gecos is defined
1111
and _user.gecos != ''
1212
and _user.gecos != None
1313
14-
- name: 'Set fact: Insert uid into the user statement for user {{ _user.name }}'
14+
- name: 'build_user_statement | Set fact: Insert uid into the user statement for user {{ _user.name }}'
1515
ansible.builtin.set_fact:
1616
_user_statement: "{{ _user_statement ~ ' --uid=' ~ _user.uid }}"
1717
when: >
1818
_user.uid is defined
1919
and _user.uid | string != ''
2020
21-
- name: 'Set fact: Insert gid into the user statement for user {{ _user.name }}'
21+
- name: 'build_user_statement | Set fact: Insert gid into the user statement for user {{ _user.name }}'
2222
ansible.builtin.set_fact:
2323
_user_statement: "{{ _user_statement ~ ' --gid=' ~ _user.gid }}"
2424
when: >
2525
_user.gid is defined
2626
and _user.gid | string != ''
2727
28-
- name: 'Set fact: Insert groups into the user statement for user {{ _user.name }}'
28+
- name: 'build_user_statement | Set fact: Insert groups into the user statement for user {{ _user.name }}'
2929
ansible.builtin.set_fact:
3030
_user_statement: "{{ _user_statement ~ ' --groups=' ~ _user.groups | join(',') }}"
3131
when: >
3232
_user.groups is defined
3333
and _user.groups | string != ''
3434
35-
- name: 'Set fact: Insert homedir into the user statement for user {{ _user.name }}'
35+
- name: 'build_user_statement | Set fact: Insert homedir into the user statement for user {{ _user.name }}'
3636
ansible.builtin.set_fact:
3737
_user_statement: "{{ _user_statement ~ ' --homedir=' ~ _user.home }}"
3838
when: >
3939
_user.home is defined
4040
and _user.home | string != ''
4141
42-
- name: 'Set fact: Insert shell into the user statement for user {{ _user.name }}'
42+
- name: 'build_user_statement | Set fact: Insert shell into the user statement for user {{ _user.name }}'
4343
ansible.builtin.set_fact:
4444
_user_statement: "{{ _user_statement ~ ' --shell=' ~ _user.shell }}"
4545
when: >
4646
_user.shell is defined
4747
and _user.shell | string != ''
4848
49-
- name: 'Set fact: Insert lock into the user statement for user {{ _user.name }}'
49+
- name: 'build_user_statement | Set fact: Insert lock into the user statement for user {{ _user.name }}'
5050
ansible.builtin.set_fact:
5151
_user_statement: "{{ _user_statement ~ ' --lock' }}"
5252
when: >
5353
_user.lock is defined
5454
and _user.lock
5555
56-
- name: 'Set fact: Insert password into the user statement for user {{ _user.name }}'
56+
- name: 'build_user_statement | Set fact: Insert password into the user statement for user {{ _user.name }}'
5757
ansible.builtin.set_fact:
5858
_user_statement: >
5959
{{
@@ -65,7 +65,7 @@
6565
_user.gid is defined
6666
and _user.gid | string != ''
6767
68-
- name: 'Insert user creation statement into the provided kickstart for user {{ _user.name }}'
68+
- name: 'build_user_statement | Insert user creation statement into the provided kickstart for user {{ _user.name }}'
6969
ansible.builtin.lineinfile:
7070
path: '{{ __work_dir_kickstart_path }}'
7171
regex: '^user\s--name={{ _user.name }}.+$'

tasks/cleanup.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
- name: 'Ensure downloaded ISO is removed: {{ __iso_path }}'
2+
- name: 'cleanup | Ensure downloaded ISO is removed: {{ __iso_path }}'
33
ansible.builtin.file:
44
path: '{{ __iso_path }}'
55
state: 'absent'
@@ -8,7 +8,7 @@
88
_cleanup_iso is defined
99
and _cleanup_iso
1010
11-
- name: 'Ensure temporary work directory is removed: {{ _temporary_work_dir_path }}'
11+
- name: 'cleanup | Ensure temporary work directory is removed: {{ _temporary_work_dir_path }}'
1212
ansible.builtin.file:
1313
path: '{{ _temporary_work_dir_path }}'
1414
state: 'absent'

tasks/create_iso.yml

+12-11
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
---
2-
- name: 'Ensure xorriso is present'
2+
- name: 'create_iso | Ensure xorriso is present'
33
ansible.builtin.package:
44
name: '{{ _xorriso_package_name }},syslinux'
55
state: 'present'
66
become: true
77

8-
- name: 'Set fact: Destination ISO path'
8+
- name: 'create_iso | Set fact: Destination ISO path'
99
ansible.builtin.set_fact:
1010
__dest_iso_path: "{{ _dest_dir_path ~ '/' ~ __iso_filename | splitext | first ~ '-ks.iso' }}"
1111

12-
- name: 'Remove ISO if forced to recreate the ISO is asked for: {{ __dest_iso_path }}'
12+
- name: 'create_iso | Remove ISO if forced to recreate the ISO is asked for: {{ __dest_iso_path }}'
1313
ansible.builtin.file:
1414
path: '{{ __dest_iso_path }}'
1515
state: 'absent'
@@ -18,21 +18,21 @@
1818
_force_recreate_custom_iso is defined
1919
and _force_recreate_custom_iso
2020
21-
- name: 'Retrieve the label of {{ __iso_path }}'
21+
- name: 'create_iso | Retrieve the label of {{ __iso_path }}'
2222
ansible.builtin.command:
2323
cmd: 'blkid --match-tag=LABEL -o value {{ __iso_path }}'
2424
changed_when: false
2525
become: true
2626
register: '__t_label'
2727

28-
- name: 'Set fact: label of {{ __iso_path }}'
28+
- name: 'create_iso | Set fact: label of {{ __iso_path }}'
2929
ansible.builtin.set_fact:
3030
__iso_label: '{{ __t_label.stdout }}'
3131

3232
# Note: Adding '-no-emul-boot' *twice* is necessary to avoid the following issue:
3333
# https://unix.stackexchange.com/questions/491043/boot-grub-efi-img-invalid-image-size
3434
# Command has been built according to https://access.redhat.com/solutions/60959
35-
- name: 'Create the ISO with the included kickstart at: {{ __dest_iso_path }}'
35+
- name: 'create_iso | Create the ISO with the included kickstart at: {{ __dest_iso_path }}'
3636
ansible.builtin.command:
3737
argv:
3838
- 'mkisofs'
@@ -61,32 +61,33 @@
6161
creates: '{{ __dest_iso_path }}'
6262
become: true
6363

64-
- name: 'Ensure ISO is bootable via BIOS and UEFI' # noqa: no-changed-when
64+
- name: 'create_iso | Ensure ISO is bootable via BIOS and UEFI'
6565
ansible.builtin.command:
6666
argv:
6767
- 'isohybrid'
6868
- '--uefi'
6969
- '{{ __dest_iso_path }}'
70+
changed_when: true
7071
become: true
7172

72-
- name: 'Block: Handle implanting of MD5 into ISO'
73+
- name: 'create_iso | Block: Handle implanting of MD5 into ISO'
7374
become: true
7475
when: >
7576
_implant_md5 is defined
7677
and _implant_md5
7778
block:
7879

79-
- name: 'Ensure implantisomd5 is present'
80+
- name: 'create_iso | Ensure implantisomd5 is present'
8081
ansible.builtin.package:
8182
name: '{{ _implantisomd5_package_name }}'
8283
state: 'present'
8384

84-
- name: 'Implant MD5 checksum into the ISO'
85+
- name: 'create_iso | Implant MD5 checksum into the ISO'
8586
ansible.builtin.command:
8687
cmd: 'implantisomd5 {{ __dest_iso_path }}'
8788
changed_when: true
8889

89-
- name: 'Ensure created ISO has the proper permissions'
90+
- name: 'create_iso | Ensure created ISO has the proper permissions'
9091
ansible.builtin.file:
9192
path: '{{ __dest_iso_path }}'
9293
owner: '{{ _custom_iso_owner }}'

tasks/download_iso.yml

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
- name: 'Ensure download directory exists: {{ _download_directory }}'
2+
- name: 'download_iso | Ensure download directory exists: {{ _download_directory }}'
33
ansible.builtin.file:
44
path: '{{ _download_directory }}'
55
state: 'directory'
@@ -8,11 +8,11 @@
88
mode: '{{ _download_directory_mode }}'
99
become: true
1010

11-
- name: 'Set fact: Red Hat Portal API download URL'
11+
- name: 'download_iso | Set fact: Red Hat Portal API download URL'
1212
ansible.builtin.set_fact:
1313
__download_url: '{{ _redhat_portal_download_base_url }}/{{ _checksum }}/download'
1414

15-
- name: 'Gather information about the ISO to download'
15+
- name: 'download_iso | Gather information about the ISO to download'
1616
ansible.builtin.uri:
1717
url: '{{ __download_url }}'
1818
method: 'GET'
@@ -23,7 +23,7 @@
2323
Authorization: 'Bearer {{ __access_token }}'
2424
register: '__t_iso_information'
2525

26-
- name: 'Ensure filename has been returned by the API'
26+
- name: 'download_iso | Ensure filename has been returned by the API'
2727
ansible.builtin.assert:
2828
that:
2929
- '__t_iso_information.json is defined'
@@ -46,15 +46,15 @@
4646
fail_msg: 'The API did not return the filename of the ISO'
4747
quiet: '{{ _quiet_assert }}'
4848

49-
- name: 'Set fact: Extract filename of the ISO to download'
49+
- name: 'download_iso | Set fact: Extract filename of the ISO to download'
5050
ansible.builtin.set_fact:
5151
__iso_filename: '{{ __t_iso_information.json.body.filename }}'
5252

53-
- name: 'Set fact: Destination path for the ISO to download'
53+
- name: 'download_iso | Set fact: Destination path for the ISO to download'
5454
ansible.builtin.set_fact:
5555
__iso_path: '{{ _download_directory }}/{{ __iso_filename }}'
5656

57-
- name: 'Download and verify the checksum of the ISO: {{ __iso_filename }}'
57+
- name: 'download_iso | Download and verify the checksum of the ISO: {{ __iso_filename }}'
5858
ansible.builtin.get_url:
5959
url: '{{ __download_url }}'
6060
dest: '{{ __iso_path }}'

0 commit comments

Comments
 (0)