6e161bb76a20bc32f1d427db994df5b2b1a39e9d
[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: Generate grub configurations
100   command: grub2-mkconfig -o /boot/grub2/grub.cfg
101   when: grub_cmdline.changed or grub_cmdline_default.changed
102
103 - name: Ensure network.service is enabled
104   systemd:
105     name: network
106     enabled: yes
107
108 - name: Set reboot command
109   set_fact:
110     reboot_cmd: "( sleep 3 && /sbin/reboot & )"
111
112 - name: Reboot node
113   shell: "{{ reboot_cmd }}"
114   async: 0
115   poll: 0
116   ignore_errors: yes
117   register: reboot_node
118   when:
119     - grub_cmdline.changed or grub_cmdline_default.changed or platform_affinity.changed
120     - hostname != installation_controller
121     - 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)
122
123 - name: Wait for the server to reboot
124   wait_for:
125      host: "{{ansible_host}}"
126      port: 22
127      delay: 15
128      search_regex: OpenSSH
129      sleep: 5
130      timeout: 3600
131   connection: local
132   register: remote_success
133   until: remote_success is succeeded
134   retries: 3
135   when: reboot_node is changed
136
137 - name: Wait for remote node ssh login. Wating for 10mins max.
138   become: "{{ ansible_env.SUDO_USER }}"
139   local_action: shell ssh -oBatchMode=yes -4 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null {{ ansible_host }} "echo success"
140   register: user_enabled
141   until: user_enabled.stdout.find("success") != -1
142   retries: 90
143   delay: 10
144   no_log: True
145   when: reboot_node is changed
146
147 - name: Ensure directory for flag file
148   file:
149     path: /etc/ansible-change_kernel_cmdline/
150     mode: 0555
151     state: directory
152
153 - name: Create a temporary flag file to indicate enabling of performance profile
154   copy:
155     content: ""
156     dest: /etc/ansible-change_kernel_cmdline/enabled
157     force: "no"
158     group: root
159     owner: root
160     mode: 0555
161   when:
162     - grub_cmdline.changed or grub_cmdline_default.changed or platform_affinity.changed
163     - hostname == installation_controller
164
165 - name: Ensure finalize-bootstrap.service is enabled on the installation host
166   systemd:
167     name: finalize-bootstrap
168     enabled: "yes"
169   when:
170     - grub_cmdline.changed or grub_cmdline_default.changed or platform_affinity.changed
171     - hostname == installation_controller
172
173 - name: Set OS tunables in /etc/sysctl.d/os-tuning.conf
174   sysctl:
175     name: "{{ item.name }}"
176     value: "{{ item.value }}"
177     state: present
178     sysctl_file: "{{ os_tuning_conf_file }}"
179     ignoreerrors: no
180   with_items:
181     - {name: 'vm.max_map_count', value: '300000'}
182     - {name: 'fs.inotify.max_user_instances', value: '1024'}