Add EFI support for grub.cfg generation
[ta/infra-ansible.git] / roles / change_kernel_cmdline / tasks / main.yml
1 ---
2
3 # Copyright 2019 Nokia
4
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 #     http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17
18 - name: Get configuration.
19   set_fact:
20     perf_profile: "{{ performance_profiles[hosts[hostname]['performance_profiles'][0]] if 'performance_profiles' in hosts[hostname] else {} }}"
21     cpu_alloc: "{{ ansible_local.cpu_allocation | default([]) }}"
22 - debug:
23     var: perf_profile
24 - debug:
25     var: cpu_alloc
26
27 - name: Get tuning option.
28   set_fact:
29     tuning: "{{ perf_profile['tuning'] | default('standard') }}"
30 - debug:
31     var: tuning
32
33 - name: Make combined CPU lists.
34   set_fact:
35     cpu_alloc: "{{ cpu_alloc | cpulist_combine(item['name'], item['lists']) }}"
36   with_items:
37     - { 'name': 'app', 'lists': ['ovs_dpdk', 'vm'] }
38
39 - name: Make sure configuration directory exists.
40   file:
41     path: /etc/systemd/system.conf.d
42     state: directory
43     mode: 0755
44
45 - name: Set platform CPU affinity.
46   ini_file:
47     dest: /etc/systemd/system.conf.d/00affinity.conf
48     mode: 0644
49     section: Manager
50     option: CPUAffinity
51     value: "{{ cpu_alloc['platform']['set'] | join(' ') }}"
52     no_extra_spaces: True
53   register: platform_affinity
54   when: cpu_alloc | length > 0
55
56 - name: Make CPU list parameters.
57   set_fact:
58     kcmdline_default_list: "{{ kcmdline_default_list + [ item['opt'] + '=' + cpu_alloc[item['list']]['list'] ] }}"
59   with_items:
60     - { 'opt': 'irqaffinity', 'list': 'platform' }
61     - { 'opt': 'kthread', 'list': 'platform' }
62     - { 'opt': 'nohz_full',   'list': 'app' }
63     - { 'opt': 'rcu_nocbs',   'list': 'app' }
64     - { 'opt': 'isolcpus',    'list': 'ovs_dpdk' }
65   when: "item['list'] in cpu_alloc"
66
67 - name: Make low latency kernel cmdline parameters.
68   set_fact:
69     kcmdline_default_list: "{{ kcmdline_default_list + perf_profile['low_latency_options'] | default([]) }}"
70   when:
71     - "tuning == 'low_latency'"
72
73 - name: Make hugepage parameters.
74   set_fact:
75     kcmdline_default_list: "{{ kcmdline_default_list + [ item + '=' + perf_profile[item] | string ] }}"
76   with_items: ['default_hugepagesz', 'hugepagesz', 'hugepages']
77   when: item in perf_profile
78
79 - debug:
80     var: kcmdline_list
81
82 - name: Set common kernel parameters.
83   lineinfile:
84     name: /etc/default/grub
85     regexp: "^GRUB_CMDLINE_LINUX="
86     line: "GRUB_CMDLINE_LINUX='{{ kcmdline_list | list_to_cmdline }}'"
87   register: grub_cmdline
88
89 - debug:
90     var: kcmdline_default_list
91
92 - name: Set default kernel parameters.
93   lineinfile:
94     name: /etc/default/grub
95     regexp: "^GRUB_CMDLINE_LINUX_DEFAULT="
96     line: "GRUB_CMDLINE_LINUX_DEFAULT='{{ kcmdline_default_list | list_to_cmdline }}'"
97   register: grub_cmdline_default
98
99 - name: Check whether grub-efi exists
100   stat:
101     path: /boot/efi/EFI/centos/grub.cfg
102   register: grub_efi_file_stat
103
104 - name: Generate grub configurations
105   command: grub2-mkconfig -o /boot/grub2/grub.cfg
106   when: grub_cmdline.changed or grub_cmdline_default.changed
107
108 - name: Generate grub-efi configurations
109   command: grub2-mkconfig -o /boot/efi/EFI/centos/grub.cfg
110   when:
111     - grub_cmdline.changed or grub_cmdline_default.changed
112     - grub_efi_file_stat.stat.exists == true
113
114 - name: Ensure network.service is enabled
115   systemd:
116     name: network
117     enabled: yes
118
119 - name: Set reboot command
120   set_fact:
121     reboot_cmd: "( sleep 3 && /sbin/reboot & )"
122
123 - name: Reboot node
124   shell: "{{ reboot_cmd }}"
125   async: 0
126   poll: 0
127   ignore_errors: yes
128   register: reboot_node
129   when:
130     - grub_cmdline.changed or grub_cmdline_default.changed or platform_affinity.changed
131     - hostname != installation_controller
132     - installation_phase != "postconfig-ended" or (scaled_out_nodes is defined and hostname in scaled_out_nodes) or (reinitialized_nodes is defined and hostname in reinitialized_nodes)
133
134 - name: Wait for the server to reboot
135   wait_for:
136      host: "{{ansible_host}}"
137      port: 22
138      delay: 15
139      search_regex: OpenSSH
140      sleep: 5
141      timeout: 3600
142   connection: local
143   register: remote_success
144   until: remote_success is succeeded
145   retries: 3
146   when: reboot_node is changed
147
148 - name: Wait for remote node ssh login. Wating for 10mins max.
149   become: "{{ ansible_env.SUDO_USER }}"
150   local_action: shell ssh -oBatchMode=yes -4 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null {{ ansible_host }} "echo success"
151   register: user_enabled
152   until: user_enabled.stdout.find("success") != -1
153   retries: 90
154   delay: 10
155   no_log: True
156   when: reboot_node is changed
157
158 - name: Ensure directory for flag file
159   file:
160     path: /etc/ansible-change_kernel_cmdline/
161     mode: 0555
162     state: directory
163
164 - name: Create a temporary flag file to indicate enabling of performance profile
165   copy:
166     content: ""
167     dest: /etc/ansible-change_kernel_cmdline/enabled
168     force: "no"
169     group: root
170     owner: root
171     mode: 0555
172   when:
173     - grub_cmdline.changed or grub_cmdline_default.changed or platform_affinity.changed
174     - hostname == installation_controller
175
176 - name: Ensure finalize-bootstrap.service is enabled on the installation host
177   systemd:
178     name: finalize-bootstrap
179     enabled: "yes"
180   when:
181     - grub_cmdline.changed or grub_cmdline_default.changed or platform_affinity.changed
182     - hostname == installation_controller
183
184 - name: Set OS tunables in /etc/sysctl.d/os-tuning.conf
185   sysctl:
186     name: "{{ item.name }}"
187     value: "{{ item.value }}"
188     state: present
189     sysctl_file: "{{ os_tuning_conf_file }}"
190     ignoreerrors: no
191   with_items:
192     - {name: 'vm.max_map_count', value: '300000'}
193     - {name: 'fs.inotify.max_user_instances', value: '1024'}