Skip to content

Instantly share code, notes, and snippets.

@hardcore
Last active August 30, 2022 11:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hardcore/97de020736e6585abcfac74a274fcf61 to your computer and use it in GitHub Desktop.
Save hardcore/97de020736e6585abcfac74a274fcf61 to your computer and use it in GitHub Desktop.
---
- name: Test regex
hosts: localhost
connection: local
become: true
vars:
default_grub_line: balancing=disable
tasks:
- name: Disable balancing
ansible.builtin.lineinfile:
path: /etc/default/grub
backrefs: true
regexp: '^(GRUB_DEFAULT=)"(?!.*\b{{ default_grub_line }}\b)(root=/dev/sda)"$'
line: '\1"{{ default_grub_line }} \2"'
@hardcore
Copy link
Author

hardcore commented Aug 30, 2022

BEFORE:

GRUB_DEFAULT="root=/dev/sda"
AFTER:

GRUB_DEFAULT="balancing=disable root=/dev/sda"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment