Skip to content

Commit

Permalink
Empty commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
aybarsm committed Jun 27, 2024
1 parent af5035f commit 13a3260
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 35 deletions.
34 changes: 19 additions & 15 deletions roles/grub/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
---
linux_manage_grub: false

linux_grub_cfg_dir: /etc/default/grub.d
linux_grub_cfg_file: 50-ansible.cfg
linux_grub_dir: /etc/default/grub.d
linux_grub_file: 50-ansible.cfg
linux_grub_destination: "{{ linux_grub_dir + '/' + linux_grub_file }}"

linux_grub_backup_cfg_file: true
linux_grub_cfg_template: grub.cfg.j2
linux_grub_backup: true
linux_grub_template: grub.cfg.j2

linux_grub_apply_changes: false
linux_grub_update_commands:
- update-grub
# Currently only command strategy is supported
# linux_grub_change_strategy: 'command'
# Leave empty not to apply changes
linux_grub_change_strategy: ''
linux_grub_change:
- cmd: update-grub

linux_grub_config_name_prefix: GRUB_
linux_grub_entry_prefix: GRUB_

linux_grub_inherit_cmdline_default: true
linux_grub_inherit_cmdline: true

linux_grub_config_default: []
linux_grub_config_group: []
linux_grub_config_host: []
linux_grub_config_all: "{{ [linux_grub_config_default, linux_grub_config_group, linux_grub_config_host] |
linux_grub_default: []
linux_grub_group: []
linux_grub_host: []
# The combination strategy below is highly nested hierarchy compliant and recommended (Example provided below)
# linux_grub_host > linux_grub_group > linux_grub_default
linux_grub_all: "{{ [linux_grub_default, linux_grub_group, linux_grub_host] |
community.general.lists_mergeby('name', recursive=true, list_merge='prepend') |
unique_recursive(attribute='name', recurse='value') }}"

__linux_grub_cfg_destination: "{{ linux_grub_cfg_dir + '/' + linux_grub_cfg_file }}"
aybarsm.helper.unique_recursive(attribute='name', recurse='value') }}"
19 changes: 19 additions & 0 deletions roles/grub/handlers/command.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
- name: Apply command(s) for linux_grub changes
become: true
ansible.builtin.command:
argv: "{{ item.argv | default(omit) }}"
chdir: "{{ item.chdir | default(omit) }}"
cmd: "{{ item.cmd }}"
creates: "{{ item.creates | default(omit) }}"
expand_argument_vars: "{{ item.expand_argument_vars | default(omit) }}"
free_form: "{{ item.free_form | default(omit) }}"
removes: "{{ item.removes | default(omit) }}"
stdin: "{{ item.stdin | default(omit) }}"
stdin_add_newline: "{{ item.stdin_add_newline | default(omit) }}"
strip_empty_ends: "{{ item.strip_empty_ends | default(omit) }}"
loop: "{{ linux_grub_change | selectattr('cmd', 'defined') }}"
register: linux_grub_apply_changes_command
when:
- linux_grub_change | type_debug == 'list'
- linux_grub_change | selectattr('cmd', 'defined') | length > 0
16 changes: 5 additions & 11 deletions roles/grub/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
---
- name: Apply grub changes
become: true
ansible.builtin.command:
cmd: "{{ item }}"
loop: "{{ linux_grub_update_commands }}"
changed_when: true
listen: "linux_grub_update_grub"
when:
- linux_grub_apply_changes | bool
- linux_grub_update_commands | type_debug == "list"
- linux_grub_update_commands | length > 0
- name: Apply linux_grub changes
ansible.builtin.import_tasks:
file: "{{ linux_grub_change_strategy }}.yml"
listen: "linux_grub_apply_changes"
when: linux_grub_change_strategy | default('') == 'command'
14 changes: 7 additions & 7 deletions roles/grub/tasks/grub.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
- name: Deploy grub.cfg
become: true
ansible.builtin.template:
src: "{{ linux_grub_cfg_template }}"
dest: "{{ __linux_grub_cfg_destination }}"
backup: "{{ linux_grub_backup_cfg_file | default(omit) | bool }}"
src: "{{ linux_grub_template }}"
dest: "{{ linux_grub_destination }}"
backup: "{{ linux_grub_backup | default(omit) | bool }}"
mode: "0644"
when:
- linux_grub_config_all | type_debug == 'list'
- linux_grub_config_all | length > 0
register: linux_grub_deploy_cfg
notify: linux_grub_update_grub
- linux_grub_all | type_debug == 'list'
- linux_grub_all | length > 0
register: linux_grub_deploy
notify: linux_grub_apply_changes
6 changes: 4 additions & 2 deletions roles/grub/templates/grub.cfg.j2
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
{% set paramName = (linux_grub_config_name_prefix | upper) ~ (param.name | upper) %}
{% if 'value' in param %}
{% if (param.value | type_debug) == 'list' %}
{% if ((param.name | lower) == 'cmdline_linux_default' and (linux_grub_inherit_cmdline_default | bool)) or ((param.name | lower) == 'cmdline_linux' and (linux_grub_inherit_cmdline | bool)) %}
{% set inheritCmdlineDefault = param.name | lower == 'cmdline_linux_default' and linux_grub_inherit_cmdline_default | bool %}
{% set inheritCmdline = param.name | lower == 'cmdline_linux' and linux_grub_inherit_cmdline | bool %}
{% if inheritCmdlineDefault or inheritCmdline %}
{% set paramValPrefix = '$' ~ paramName ~ ' ' %}
{% else %}
{% set paramValPrefix = '' %}
{% endif %}
{{ paramName }}="{{ paramValPrefix }}{{ param.value | flatten_query('name', 'value', '=', ' ') }}"
{{ paramName }}="{{ paramValPrefix }}{{ param.value | aybarsm.helper.flatten_query('name', 'value', '=', ' ') }}"
{% else %}
{{ paramName }}="{{ param.value }}"
{% endif %}
Expand Down
Empty file removed roles/grub/vars/.gitkeep
Empty file.
Empty file.

0 comments on commit 13a3260

Please sign in to comment.