Skip to content

Commit

Permalink
Adding optional dest_iso_filename to allow specifying the filename of…
Browse files Browse the repository at this point in the history
… the custom ISO; Creating the destination directory for the custom ISO
  • Loading branch information
sscheib committed Mar 21, 2024
1 parent a5535ad commit 85b715f
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ Role Variables
| `custom_iso_mode` | `0600` | false | owner of the custom ISO to apply |
| `custom_iso_owner` | `root` | false | chmod of the custom ISO to apply |
| `dest_dir_path` | `{{ playbook_dir }}` | false | destination directory for the custom ISO |
| `dest_dir_owner` | `root` | false | owner of the parent directory for the custom ISO |
| `dest_dir_group` | `root` | false | group of the parent directory for the custom ISO |
| `dest_dir_mode` | `0755` | false | chmod of the parent directory for the custom ISO |
| `dest_iso_filename` | original ISO name + `-ks.iso`| false | filename to use for the custom ISO |
| `download_directory` | `{{ playbook_dir }}` | false | directory to store the downloaded ISO in |
| `download_directory_group` | `root` | false | group of the downloaded ISO to apply |
| `download_directory_mode` | `0600` | false | owner of the downloaded ISO to apply |
Expand Down
3 changes: 3 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ _def_temporary_work_dir_source_files_path_mode: '0755'

# destination directory for the custom ISO
_def_dest_dir_path: '{{ playbook_dir }}'
_def_dest_dir_path_owner: 'root'
_def_dest_dir_path_group: 'root'
_def_dest_dir_path_mode: '0755'

# name of the package that provides xorriso
_def_xorriso_package_name: 'xorriso'
Expand Down
23 changes: 23 additions & 0 deletions tasks/assert.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
- '_temporary_work_dir_source_files_path_group'
- '_temporary_work_dir_source_files_path_mode'
- '_dest_dir_path'
- '_dest_dir_owner'
- '_dest_dir_group'
- '_dest_dir_mode'
- '_xorriso_package_name'
- '_isolinux_bin_path'
- '_boot_cat_path'
Expand Down Expand Up @@ -136,6 +139,26 @@
loop_var: '__var'
label: 'variable: {{ __var }}'

- name: 'assert | Ensure optional string variables are defined properly - if defined'
ansible.builtin.assert:
that:
- "lookup('ansible.builtin.vars', __var) is defined"
- "lookup('ansible.builtin.vars', __var) is string"
- "lookup('ansible.builtin.vars', __var) != None"
- "lookup('ansible.builtin.vars', __var) != ''"
success_msg: "Variable '{{ __var }}' defined properly - value: '{{ lookup('ansible.builtin.vars', __var) }}'"
fail_msg: "Variable '{{ __var }}' failed to validate"
quiet: '{{ _sat_quiet_assert }}'
when: >-
lookup('ansible.builtin.vars', __var, default='') is defined
and lookup('ansible.builtin.vars', __var, default='') != ''
and lookup('ansible.builtin.vars', __var, default='') != None
loop:
- '_dest_iso_filename'
loop_control:
loop_var: '__var'
label: 'variable: {{ __var }}'

- name: 'assert | Ensure post_sections are defined properly'
ansible.builtin.assert:
that:
Expand Down
19 changes: 18 additions & 1 deletion tasks/create_iso.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,26 @@
state: 'present'
become: true

- name: 'create_iso | Ensure the destination directory for the ISO exists: {{ _dest_dir_path }}'
ansible.builtin.file:
path: '{{ _dest_dir_path }}'
state: 'directory'
owner: '{{ _dest_dir_path_owner }}'
group: '{{ _dest_dir_path_group }}'
mode: '{{ _dest_dir_path_mode }}'
become: true

- name: 'create_iso | Set fact: Destination ISO path'
ansible.builtin.set_fact:
__dest_iso_path: "{{ _dest_dir_path ~ '/' ~ __iso_filename | splitext | first ~ '-ks.iso' }}"
__dest_iso_path: >-
{{
_dest_dir_path ~ '/' ~ __iso_filename | splitext | first ~ '-ks.iso'
if _dest_iso_filename is not defined
or _dest_iso_filename == ''
or _dest_iso_filename == None
else
_dest_dir_path ~ '/' ~ _dest_iso_filename
}}
- name: 'create_iso | Remove ISO if forced to recreate the ISO is asked for: {{ __dest_iso_path }}'
ansible.builtin.file:
Expand Down
8 changes: 8 additions & 0 deletions vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ _temporary_work_dir_source_files_path_mode: >-
# destination directory for the custom ISO
_dest_dir_path: '{{ dest_dir_path | default(_def_dest_dir_path) }}'
_dest_dir_path_owner: '{{ dest_dir_path_owner | default(_def_dest_dir_path_owner) }}'
_dest_dir_path_group: '{{ dest_dir_path_group | default(_dest_dir_path_group) }}'
_dest_dir_path_mode: '{{ dest_dir_path_mode | default(_def_dest_dir_path_mode) }}'

# filename to use for the custom ISO
# if not defined, it will default to the original ISO filename (as returned from the API) with a suffixed '-ks'
# e.g.: rhel-8.9-x86_64-dvd.iso -> rhel-8.9-x86_64-dvd-ks.iso
_dest_iso_filename: '{{ dest_iso_filename | default(None) }}'

# name of the package that provides xorriso
_xorriso_package_name: '{{ xorriso_package_name | default(_def_xorriso_package_name) }}'
Expand Down

0 comments on commit 85b715f

Please sign in to comment.