Initial commit
[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.ncir_cpu_allocation | default([]) }}"
22 - debug:
23     var: perf_profile
24 - debug:
25     var: cpu_alloc
26
27 - name: Make combined CPU lists.
28   set_fact:
29     cpu_alloc: "{{ cpu_alloc | cpulist_combine(item['name'], item['lists']) }}"
30   with_items:
31     - { 'name': 'app', 'lists': ['ovs_dpdk', 'vm'] }
32
33 - name: Make sure configuration directory exists.
34   file:
35     path: /etc/systemd/system.conf.d
36     state: directory
37     mode: 0755
38
39 - name: Set platform CPU affinity.
40   ini_file:
41     dest: /etc/systemd/system.conf.d/00affinity.conf
42     mode: 0644
43     section: Manager
44     option: CPUAffinity
45     value: "{{ cpu_alloc['platform']['set'] | join(' ') }}"
46     no_extra_spaces: True
47   register: platform_affinity
48   when: cpu_alloc | length > 0
49
50 - name: Make CPU list parameters.
51   set_fact:
52     kcmdline_default_list: "{{ kcmdline_default_list + [ item['opt'] + '=' + cpu_alloc[item['list']]['list'] ] }}"
53   with_items:
54     - { 'opt': 'irqaffinity', 'list': 'platform' }
55     - { 'opt': 'kthread', 'list': 'platform' }
56     - { 'opt': 'nohz_full',   'list': 'app' }
57     - { 'opt': 'rcu_nocbs',   'list': 'app' }
58     - { 'opt': 'isolcpus',    'list': 'ovs_dpdk' }
59   when: "item['list'] in cpu_alloc"
60
61 - name: Make hugepage parameters.
62   set_fact:
63     kcmdline_default_list: "{{ kcmdline_default_list + [ item + '=' + perf_profile[item] | string ] }}"
64   with_items: ['default_hugepagesz', 'hugepagesz', 'hugepages']
65   when: item in perf_profile
66
67 - debug:
68     var: kcmdline_list
69
70 - name: Set common kernel parameters.
71   lineinfile:
72     name: /etc/default/grub
73     regexp: "^GRUB_CMDLINE_LINUX="
74     line: "GRUB_CMDLINE_LINUX='{{ kcmdline_list | list_to_cmdline }}'"
75   register: grub_cmdline
76
77 - debug:
78     var: kcmdline_default_list
79
80 - name: Set default kernel parameters.
81   lineinfile:
82     name: /etc/default/grub
83     regexp: "^GRUB_CMDLINE_LINUX_DEFAULT="
84     line: "GRUB_CMDLINE_LINUX_DEFAULT='{{ kcmdline_default_list | list_to_cmdline }}'"
85   register: grub_cmdline_default
86
87 - name: Generate grub configurations
88   command: grub2-mkconfig -o /boot/grub2/grub.cfg
89   when: grub_cmdline.changed or grub_cmdline_default.changed
90
91 - name: Ensure network.service is enabled
92   systemd:
93     name: network
94     enabled: yes
95
96 - name: Reboot node
97   shell: ( sleep 3 && /sbin/reboot & )
98   async: 0
99   poll: 0
100   ignore_errors: yes
101   when:
102     - grub_cmdline.changed or grub_cmdline_default.changed or platform_affinity.changed
103     - hostname != installation_controller
104     - 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)
105
106 - name: Wait for the server to reboot
107   local_action: wait_for host="{{ansible_host}}" delay=15 state=started port=22 connect_timeout=10 timeout=720
108   when:
109     - grub_cmdline.changed or grub_cmdline_default.changed or platform_affinity.changed
110     - hostname != installation_controller
111     - 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)
112
113 - name: Wait for remote node ssh login. Wating for 10mins max.
114   become: "{{ ansible_env.SUDO_USER }}"
115   local_action: shell ssh -oBatchMode=yes -4 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null {{ ansible_host }} "echo success"
116   register: user_enabled
117   until: user_enabled.stdout.find("success") != -1
118   retries: 90
119   delay: 10
120   no_log: True
121   when:
122     - grub_cmdline.changed or grub_cmdline_default.changed or platform_affinity.changed
123     - hostname != installation_controller
124     - 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)
125
126 - name: Ensure directory for flag file
127   file:
128     path: /etc/ansible-change_kernel_cmdline/
129     mode: 0555
130     state: directory
131
132 - name: Create a temporary flag file to indicate enabling of performance profile
133   copy:
134     content: ""
135     dest: /etc/ansible-change_kernel_cmdline/enabled
136     force: "no"
137     group: root
138     owner: root
139     mode: 0555
140   when:
141     - grub_cmdline.changed or grub_cmdline_default.changed or platform_affinity.changed
142     - hostname == installation_controller
143
144 - name: Ensure finalize-bootstrap.service is enabled on the installation host
145   systemd:
146     name: finalize-bootstrap
147     enabled: "yes"
148   when:
149     - grub_cmdline.changed or grub_cmdline_default.changed or platform_affinity.changed
150     - hostname == installation_controller
151
152 - name: Set OS tunables in /etc/sysctl.d/os-tuning.conf
153   sysctl:
154     name: "{{ item.name }}"
155     value: "{{ item.value }}"
156     state: present
157     sysctl_file: "{{ os_tuning_conf_file }}"
158     ignoreerrors: no
159   with_items:
160     - {name: 'vm.max_map_count', value: '300000'}
161     - {name: 'fs.inotify.max_user_instances', value: '1024'}