diff --git a/README.md b/README.md index dffb3bc..566997b 100644 --- a/README.md +++ b/README.md @@ -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 | diff --git a/defaults/main.yml b/defaults/main.yml index 1297d7d..95e53a0 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -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' diff --git a/tasks/assert.yml b/tasks/assert.yml index 173a529..fea10ce 100644 --- a/tasks/assert.yml +++ b/tasks/assert.yml @@ -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' @@ -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: diff --git a/tasks/create_iso.yml b/tasks/create_iso.yml index e19ffc1..6b519ce 100644 --- a/tasks/create_iso.yml +++ b/tasks/create_iso.yml @@ -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: diff --git a/vars/main.yml b/vars/main.yml index 3b9e8f7..5ccbdfb 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -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) }}'