Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grubcmdline: Support Ubuntu/ cloud-init combination #29

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions roles/grubcmdline/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ kernel_restart_handler: reboot # noqa var-naming[no-role-prefix]
# optionally skip backing up the config file. Can cause issues on some
# filesystems due to filenames containing illegal characters
backup_grub_config_file: true # noqa var-naming[no-role-prefix]

default_grub_conf: "/etc/default/grub" # noqa var-naming[no-role-prefix]
cloudinit_grub_conf: "/etc/default/grub.d/50-cloudimg-settings.cfg" # noqa var-naming[no-role-prefix]
17 changes: 13 additions & 4 deletions roles/grubcmdline/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,18 @@
changed_when: old_cmdline != kernel_cmdline | select() | sort | list
notify: "{{ kernel_restart_handler }}"

- name: Slurp /etc/default/grub
- name: Look for cloud-init grub file
ansible.builtin.stat:
path: "{{ cloudinit_grub_conf }}"
register: cloudinit_result

- name: Set fact with the grub conf file path
ansible.builtin.set_fact:
grub_conf_file: "{{ cloudinit_result.stat.exists | ternary(cloudinit_grub_conf, default_grub_conf) }}"

- name: Slurp grub config file
ansible.builtin.slurp:
path: /etc/default/grub
path: "{{ grub_conf_file }}"
register: grub_result
become: true

Expand Down Expand Up @@ -47,9 +56,9 @@
ansible.builtin.debug:
var: grub_cmdline_linux_new

- name: Set GRUB_CMDLINE_LINUX_DEFAULT in /etc/default/grub
- name: Set GRUB_CMDLINE_LINUX_DEFAULT in the appropriate grub conf
ansible.builtin.lineinfile:
path: /etc/default/grub
path: "{{ grub_conf_file }}"
regexp: ^GRUB_CMDLINE_LINUX_DEFAULT
line: GRUB_CMDLINE_LINUX_DEFAULT="{{ grub_cmdline_linux_new | join(' ') }}"
backup: "{{ backup_grub_config_file }}"
Expand Down