tripleo-heat-templates/extraconfig/pre_network/boot_param_tasks.yaml

104 lines
4.3 KiB
YAML

- name: Get the command line args of the node
command: cat /proc/cmdline
register: cmdline
- name: Get the active tuned profile
command: tuned-adm active
become: true
register: tuned_active_profile
# Kernel Args Configuration
- block:
- name: Ensure the kernel args ( {{ _KERNEL_ARGS_ }} ) is present as TRIPLEO_HEAT_TEMPLATE_KERNEL_ARGS
lineinfile:
dest: /etc/default/grub
regexp: '^TRIPLEO_HEAT_TEMPLATE_KERNEL_ARGS.*'
insertafter: '^GRUB_CMDLINE_LINUX.*'
line: 'TRIPLEO_HEAT_TEMPLATE_KERNEL_ARGS=" {{ _KERNEL_ARGS_ }} "'
- name: Add TRIPLEO_HEAT_TEMPLATE_KERNEL_ARGS to the GRUB_CMDLINE_LINUX parameter
lineinfile:
dest: /etc/default/grub
line: 'GRUB_CMDLINE_LINUX="${GRUB_CMDLINE_LINUX:+$GRUB_CMDLINE_LINUX }${TRIPLEO_HEAT_TEMPLATE_KERNEL_ARGS}"'
insertafter: '^TRIPLEO_HEAT_TEMPLATE_KERNEL_ARGS.*'
- name: Check grub config paths
stat:
path: "{{ item }}"
register: grub_stat
loop:
- /boot/grub2/grub.cfg
- /boot/efi/EFI/redhat/grub.cfg
- /boot/efi/EFI/centos/grub.cfg
- /boot/efi/EFI/fedora/grub.cfg
- name: Generate grub config
command: "grub2-mkconfig -o {{ item.stat.path }}"
when: item.stat.exists|bool
loop: "{{ grub_stat.results }}"
- name: Set reboot required fact
set_fact:
reboot_required: true
become: true
when:
- _KERNEL_ARGS_|default("") != ""
- _KERNEL_ARGS_|default("") not in cmdline.stdout_lines[0]
# Tune-d Configuration
- block:
- name: Check Tune-d Configuration file exists
stat:
path: /etc/tuned/{{ _TUNED_PROFILE_NAME_ }}-variables.conf
register: tuned_conf_stat_result
- name: Tune-d Configuration
lineinfile:
dest: /etc/tuned/{{ _TUNED_PROFILE_NAME_ }}-variables.conf
regexp: '^isolated_cores=.*'
line: 'isolated_cores={{ _TUNED_CORES_ }}'
when: tuned_conf_stat_result.stat.exists and _TUNED_CORES_|default("") != ""
- name: Tune-d profile activation
shell: tuned-adm profile {{ _TUNED_PROFILE_NAME_ }}
- name: Set reboot required fact
set_fact:
reboot_required: true
become: true
when:
- _TUNED_PROFILE_NAME_|default("") != ""
- _TUNED_PROFILE_NAME_|default("") not in tuned_active_profile.stdout_lines[0]
# Check if os-net-config has run once, if yes, no need for the below workaround
- find:
paths: /etc/sysconfig/network-scripts/
patterns: ifcfg-*
contains: "# This file is autogenerated by os-net-config"
register: os_net_ifcfg_files
# Provisioning Network workaround
# The script will be executed before os-net-config, in which case, only Provisioning network will have IP
# BOOTPROTO of all interface config files (except provisioning), will be set to "none" to avoid reboot failing to acquire IP on other networks
- block:
- find:
paths: /etc/sysconfig/network-scripts/
patterns: ifcfg-*
register: ifcfg_files
- replace:
dest: "{{ item.path }}"
regexp: '^BOOTPROTO=.*'
replace: 'BOOTPROTO=none'
when:
- item.path | regex_replace('(^.*ifcfg-)(.*)', '\\2') != "lo"
# Ensure the interface information is available in the facts
- hostvars[inventory_hostname]['ansible_' + item.path | regex_replace('(^.*ifcfg-)(.*)', '\\2') | replace('-', '_') ] is defined
# This condition will list all the interfaces except the one with valid IP (which is Provisioning network at this stage)
# Simpler Version - hostvars[inventory_hostname]['ansible_' + iface_name ]['ipv4'] is undefined
- hostvars[inventory_hostname]['ansible_' + item.path | regex_replace('(^.*ifcfg-)(.*)', '\\2') | replace('-', '_') ]['ipv4'] is undefined
with_items:
- "{{ ifcfg_files.files }}"
become: true
when: os_net_ifcfg_files.matched == 0
- name: Create a temp file to identify if reboot is required or not
file:
path: "/tmp/kernel_args_reboot_required.ansible"
state: touch
when: reboot_required is defined and reboot_required