Debian Codegraph @

ansible_collections/community/mongodb/roles/mongodb_linux/tasks/main.yml

raw
1 ---
2 # tasks file for mongodb_linux
3
4 - name: Include OS-specific vars
5 include_vars:
6 file: "{{ lookup('first_found', params) }}"
7 vars:
8 params:
9 paths:
10 - "vars"
11 files:
12 - "{{ ansible_facts.distribution }}-{{ ansible_facts.distribution_version }}.yml"
13 - "{{ ansible_facts.os_family }}-{{ ansible_facts.distribution_major_version }}.yml"
14 - "{{ ansible_facts.distribution }}.yml"
15 - "{{ ansible_facts.os_family }}.yml"
16 - default.yml
17 tags:
18 - "vars"
19
20 - name: "Override variables from OS-specific configuration"
21 set_fact:
22 ntp_package: "{{ mongodb_ntp_package | default(ntp_package, true) }}"
23 ntp_service: "{{ mongodb_ntp_service | default(ntp_service, true) }}"
24 gnu_c_lib: "{{ mongodb_gnu_c_lib | default(gnu_c_lib, true) }}"
25
26 - name: See if we are in docker
27 when:
28 - "ansible_facts.virtualization_role == 'guest'"
29 - not in_docker # defined in vars
30 block:
31 - name: Check if we are in docker (based on /.dockerenv file)
32 stat:
33 path: /.dockerenv
34 register: dockerenv_file
35 tags:
36 - "ci"
37 - name: Update in_docker var
38 set_fact:
39 in_docker: "{{ dockerenv_file.stat.exists }}"
40 tags:
41 - "ci"
42
43
44 # Tasks based on: https://docs.mongodb.com/manual/administration/production-notes/
45
46 - name: Set swappiness
47 ansible.posix.sysctl:
48 name: vm.swappiness
49 value: "{{ swappiness }}"
50 state: present
51 tags:
52 - "linux"
53 - "setup"
54
55 - name: Ensure ntp service is installed
56 package:
57 name: "{{ ntp_package }}"
58 state: present
59 register: _pkg
60 until: _pkg is succeeded
61 retries: 5
62 tags:
63 - "linux"
64 - "setup"
65 - "pkg"
66
67 - name: Update perms on chrony pid dir on RedHat 8+
68 file:
69 path: /run/chrony/
70 owner: root
71 group: root
72 state: directory
73 when:
74 - ansible_facts.os_family == "RedHat"
75 - ansible_facts.distribution_major_version|int >= 8
76 tags:
77 - "linux"
78 - "setup"
79 - "redhat"
80
81 - name: Ensure override directory exists for systemd-timesyncd.service
82 file:
83 path: /lib/systemd/system/systemd-timesyncd.service.d
84 state: directory
85 owner: root
86 group: root
87 mode: '0755'
88 when:
89 - ansible_facts.distribution == "Debian"
90
91 - name: Create override.conf to disable ConditionVirtualization for systemd-timesyncd.service
92 copy:
93 dest: /lib/systemd/system/systemd-timesyncd.service.d/override.conf
94 content: |
95 [Unit]
96 ConditionVirtualization=
97 owner: root
98 group: root
99 mode: '0644'
100 when:
101 - ansible_facts.distribution == "Debian"
102 register: timesync
103
104 - name: Reload systemd manager configuration
105 command: systemctl daemon-reload
106 changed_when: false
107 when: timesync.changed
108
109 - name: Ensure ntp service is configured
110 service:
111 name: "{{ ntp_service }}"
112 state: started
113 enabled: yes
114 tags:
115 - "linux"
116 - "setup"
117 - "service"
118
119 - name: Ensure GNU C Library is the latest
120 package:
121 name: "{{ gnu_c_lib }}"
122 state: latest
123 register: _pkg
124 until: _pkg is succeeded
125 retries: 5
126 tags:
127 - "linux"
128 - "setup"
129 - "pkg"
130
131 - name: Ensure NUMA zone reclaim is disabled
132 ansible.posix.sysctl:
133 name: vm.zone_reclaim_mode
134 value: "0"
135 state: present
136 reload: yes
137 when: not in_docker|bool
138 tags:
139 - "linux"
140 - "setup"
141
142 # https://docs.mongodb.com/manual/tutorial/transparent-huge-pages/
143 - name: Ensure manage-transparent-huge-pages service exists
144 copy:
145 src: "{{ mongodb_enable_thp | ternary('thp-enable.service', 'thp-disable.service') }}"
146 dest: /etc/systemd/system/manage-transparent-huge-pages.service
147 owner: root
148 group: root
149 register: thp
150 tags:
151 - "linux"
152 - "setup"
153
154 - name: Reload systemd
155 systemd:
156 daemon_reexec: yes
157 when: thp is changed
158 tags:
159 - "linux"
160 - "setup"
161 - "service"
162
163 - name: Check if transparent_hugepage is enabled in the kernel
164 stat:
165 path: /sys/kernel/mm/transparent_hugepage
166 register: sys_thp
167
168 - name: Enable manage-transparent-huge-pages service
169 service:
170 name: manage-transparent-huge-pages
171 state: started
172 enabled: yes
173 when: thp.changed
174 tags:
175 - "linux"
176 - "service"
177 - "setup"
178
179 # Tasks based on: https://docs.mongodb.com/manual/reference/ulimit/
180
181 - name: Set pam limits (nproc and nofile)
182 community.general.pam_limits:
183 domain: "{{ item[0] }}"
184 limit_type: "{{ item[1] }}"
185 limit_item: "{{ item[2] }}"
186 value: "{{ item[3] }}"
187 with_nested:
188 - ["root", "mongodb"]
189 - ["hard", "soft"]
190 - ["nproc", "nofile"]
191 - ["{{ nproc_and_nofile_limit }}"]
192 tags:
193 - "linux"
194 - "setup"
195
196 - name: Set pam limits (memlock)
197 community.general.pam_limits:
198 domain: "{{ item[0] }}"
199 limit_type: "{{ item[1] }}"
200 limit_item: "{{ item[2] }}"
201 value: "{{ item[3] }}"
202 with_nested:
203 - ["root", "mongodb"]
204 - ["hard", "soft"]
205 - ["memlock"]
206 - ["{{ memlock_limit }}"]
207 tags:
208 - "linux"
209 - "setup"
210
211 # Other tuning settings
212
213 - name: Set sysctl values
214 ansible.posix.sysctl:
215 name: "{{ item['name'] }}"
216 value: "{{ item['value'] }}"
217 state: present
218 loop:
219 # TODO: These may need to be configurable for different usage patterns.
220 - { "name": "vm.dirty_ratio", "value": "15" }
221 - { "name": "vm.dirty_background_ratio", "value": "5" }
222 - { "name": "vm.max_map_count", "value": "128000" }
223 - { "name": "net.core.somaxconn ", "value": "4096" }
224 - { "name": "net.ipv4.tcp_fin_timeout", "value": "30" }
225 - { "name": "net.ipv4.tcp_keepalive_intvl", "value": "30" }
226 - { "name": "net.ipv4.tcp_keepalive_time", "value": "120" }
227 - { "name": "net.ipv4.tcp_max_syn_backlog ", "value": "4096" }
228 tags:
229 - "linux"
230 - "setup"