blob: 04e2a1bb0df21491b7fefba29c59550edc56764a [file] [log] [blame]
Ondrej Smola9af2b082016-08-25 17:37:29 +02001{%- from "maas/map.jinja" import region with context %}
Vasyl Saienko8784db82018-07-06 11:15:52 +03002{%- if region.get('enabled', False) %}
Ondrej Smola9af2b082016-08-25 17:37:29 +02003
Ondrej Smolaa5844e02016-08-25 19:06:56 +02004maas_region_packages:
Ondrej Smola9af2b082016-08-25 17:37:29 +02005 pkg.installed:
6 - names: {{ region.pkgs }}
7
Ondrej Smola61a77772016-08-25 20:05:30 +02008/etc/maas/regiond.conf:
Ondrej Smola9af2b082016-08-25 17:37:29 +02009 file.managed:
Ondrej Smola61a77772016-08-25 20:05:30 +020010 - source: salt://maas/files/regiond.conf
Ondrej Smola9af2b082016-08-25 17:37:29 +020011 - template: jinja
Alexander Noskove24078a2017-06-20 12:24:28 +020012 - group: maas
Ondrej Smola9af2b082016-08-25 17:37:29 +020013 - require:
Ondrej Smolaa5844e02016-08-25 19:06:56 +020014 - pkg: maas_region_packages
Ondrej Smola9af2b082016-08-25 17:37:29 +020015
Jiri Broulik0df14bc2017-08-07 10:01:55 +020016/usr/lib/python3/dist-packages/provisioningserver/templates/proxy/maas-proxy.conf.template:
17 file.managed:
18 - source: salt://maas/files/maas-proxy.conf.template
19 - template: jinja
20 - require:
21 - pkg: maas_region_packages
22
Martin Polreich0764b762017-11-20 14:08:30 +010023{%- if region.database.initial_data is defined %}
24
25/root/maas/scripts/restore_{{ region.database.name }}.sh:
26 file.managed:
27 - source: salt://maas/files/restore.sh
28 - mode: 770
Jiri Broulik47d506b2018-04-13 15:50:53 +020029 - makedirs: true
Martin Polreich0764b762017-11-20 14:08:30 +010030 - template: jinja
31
32restore_maas_database_{{ region.database.name }}:
33 cmd.run:
34 - name: /root/maas/scripts/restore_{{ region.database.name }}.sh
35 - unless: "[ -f /root/maas/flags/{{ region.database.name }}-installed ]"
36 - cwd: /root
37 - require:
38 - file: /root/maas/scripts/restore_{{ region.database.name }}.sh
39
40{%- endif %}
41
Jakub Pavlik2bd298f2016-08-31 13:50:58 +020042{%- if region.get('enable_iframe', False) %}
43
44/etc/apache2/conf-enabled/maas-http.conf:
45 file.managed:
46 - source: salt://maas/files/maas-http.conf
47 - user: root
48 - group: root
49 - mode: 644
50 - require:
51 - pkg: maas_region_packages
52 - require_in:
Pavel Cizinsky5a6e2722016-08-31 15:58:13 +020053 - service: maas_region_services
Jakub Pavlik2bd298f2016-08-31 13:50:58 +020054
Jakub Pavlikbb821802016-08-31 18:14:57 +020055maas_apache_headers:
56 cmd.run:
57 - name: "a2enmod headers"
Jakub Pavlik2bd298f2016-08-31 13:50:58 +020058 - require:
59 - pkg: maas_region_packages
60 - require_in:
Pavel Cizinsky5a6e2722016-08-31 15:58:13 +020061 - service: maas_region_services
Jakub Pavlik2bd298f2016-08-31 13:50:58 +020062
Pavel Cizinsky5a6e2722016-08-31 15:58:13 +020063{%- endif %}
64
65{% if region.theme is defined %}
66
67/usr/share/maas/web/static/css/maas-styles.css:
68 file.managed:
69 - source: salt://maas/files/{{ region.theme }}-styles.css
Pavel Cizinsky5a6e2722016-08-31 15:58:13 +020070 - mode: 644
71 - watch_in:
72 - service: maas_region_services
73
Jakub Pavlik2bd298f2016-08-31 13:50:58 +020074{%- endif %}
75
Ondrej Smola9af2b082016-08-25 17:37:29 +020076/etc/maas/preseeds/curtin_userdata_amd64_generic_trusty:
77 file.managed:
78 - source: salt://maas/files/curtin_userdata_amd64_generic_trusty
79 - template: jinja
80 - user: root
81 - group: root
82 - mode: 644
Damian Szeluga732e0522017-03-29 16:53:06 +020083 - context:
84 salt_master_ip: {{ region.salt_master_ip }}
Ondrej Smola9af2b082016-08-25 17:37:29 +020085 - require:
Ondrej Smolaa5844e02016-08-25 19:06:56 +020086 - pkg: maas_region_packages
Ondrej Smola9af2b082016-08-25 17:37:29 +020087
Damian Szeluga9fe4ce72017-03-29 14:27:10 +020088/etc/maas/preseeds/curtin_userdata_amd64_generic_xenial:
89 file.managed:
90 - source: salt://maas/files/curtin_userdata_amd64_generic_xenial
91 - template: jinja
92 - user: root
93 - group: root
94 - mode: 644
Damian Szeluga732e0522017-03-29 16:53:06 +020095 - context:
96 salt_master_ip: {{ region.salt_master_ip }}
Damian Szeluga9fe4ce72017-03-29 14:27:10 +020097 - require:
98 - pkg: maas_region_packages
99
Alexandru Avadanii7dc29b32017-08-05 02:03:01 +0200100/etc/maas/preseeds/curtin_userdata_arm64_generic_xenial:
101 file.managed:
102 - source: salt://maas/files/curtin_userdata_arm64_generic_xenial
103 - template: jinja
104 - user: root
105 - group: root
106 - mode: 644
107 - context:
108 salt_master_ip: {{ region.salt_master_ip }}
109 - require:
110 - pkg: maas_region_packages
111
Petr Michalec8a0d52e2018-05-30 16:22:56 +0200112Configure /root/.pgpass for MAAS:
Martin Polreich13301192017-11-13 17:51:07 +0100113 file.managed:
Petr Michalec8a0d52e2018-05-30 16:22:56 +0200114 - name: /root/.pgpass
Martin Polreich13301192017-11-13 17:51:07 +0100115 - source: salt://maas/files/pgpass
116 - template: jinja
117 - user: root
118 - group: root
119 - mode: 600
120
Jakub Pavlikd69c6da2016-08-29 22:33:53 +0200121maas_region_services:
122 service.running:
123 - enable: true
124 - names: {{ region.services }}
125 - require:
126 - cmd: maas_region_syncdb
127 - watch:
128 - file: /etc/maas/regiond.conf
Petr Michalec8a0d52e2018-05-30 16:22:56 +0200129 {%- if grains.get('kitchen-test') %}
130 - onlyif: /bin/false
131 {%- endif %}
Jakub Pavlikd69c6da2016-08-29 22:33:53 +0200132
133maas_region_syncdb:
134 cmd.run:
135 - names:
Petr Michalec8a0d52e2018-05-30 16:22:56 +0200136 - maas-region syncdb --noinput
Jakub Pavlikd69c6da2016-08-29 22:33:53 +0200137 - require:
138 - file: /etc/maas/regiond.conf
Petr Michalec8a0d52e2018-05-30 16:22:56 +0200139 {%- if grains['saltversioninfo'][0] >= 2017 and grains['saltversioninfo'][1] >= 7 %}
140 - retry:
141 attempts: 3
142 interval: 5
143 splay: 5
144 {%- endif %}
azvyagintsev3ff2ef12018-06-01 21:30:45 +0300145 {%- if grains.get('kitchen-test') %}
146 - onlyif: /bin/false
147 {%- endif %}
Jakub Pavlikd69c6da2016-08-29 22:33:53 +0200148
azvyagintsev58947072018-06-29 12:09:48 +0300149maas_warmup:
150 module.run:
151 - name: maasng.wait_for_http_code
azvyagintsev58947072018-06-29 12:09:48 +0300152# FIXME
azvyagintsevf3515c82018-06-26 18:59:05 +0300153 - url: "http://localhost:5240/MAAS"
azvyagintsev58947072018-06-29 12:09:48 +0300154# 405 - should be removed ,since twisted will be fixed
155# Currently - api always throw 405=>500 even if request has been made with 'expected 'HEAD
azvyagintsev48381262018-06-29 12:42:20 +0300156 - expected: [200, 405]
azvyagintsev58947072018-06-29 12:09:48 +0300157 - require_in:
158 - module: maas_set_admin_password
159 {%- if grains.get('kitchen-test') %}
160 - onlyif: /bin/false
161 {%- endif %}
162
Krzysztof Szukiełojćc4b33092017-02-15 13:25:38 +0100163maas_set_admin_password:
Pavel Cizinsky2174e7f2016-08-30 18:45:22 +0200164 cmd.run:
165 - name: "maas createadmin --username {{ region.admin.username }} --password {{ region.admin.password }} --email {{ region.admin.email }} && touch /var/lib/maas/.setup_admin"
166 - creates: /var/lib/maas/.setup_admin
167 - require:
168 - service: maas_region_services
Petr Michalec8a0d52e2018-05-30 16:22:56 +0200169 {%- if grains.get('kitchen-test') %}
170 - onlyif: /bin/false
171 {%- endif %}
Ondrej Smolaa5844e02016-08-25 19:06:56 +0200172
Krzysztof Szukiełojćc4b33092017-02-15 13:25:38 +0100173maas_login_admin:
174 cmd.run:
175 - name: "maas-region apikey --username {{ region.admin.username }} > /var/lib/maas/.maas_credentials"
Petr Michalec8a0d52e2018-05-30 16:22:56 +0200176 - require:
177 - cmd: maas_set_admin_password
178 {%- if grains.get('kitchen-test') %}
179 - onlyif: /bin/false
180 {%- endif %}
Krzysztof Szukiełojćc4b33092017-02-15 13:25:38 +0100181
azvyagintsevcb54d142018-06-19 16:18:32 +0300182maas_wait_for_racks_import_done:
183 module.run:
184 - name: maasng.sync_and_wait_bs_to_all_racks
185 - require:
186 - cmd: maas_login_admin
187 - require_in:
188 - module: maas_config
189 {%- if grains.get('kitchen-test') %}
190 - onlyif: /bin/false
191 {%- endif %}
192
193maas_wait_for_region_import_done:
azvyagintsev3ff2ef12018-06-01 21:30:45 +0300194 module.run:
195 - name: maasng.boot_resources_import
196 - action: 'import'
197 - wait: True
198 - require:
199 - cmd: maas_login_admin
200 {% if region.get('boot_sources_delete_all_others', False) %}
201 - module: region_boot_sources_delete_all_others
202 {%- endif %}
203 - require_in:
azvyagintsevcb54d142018-06-19 16:18:32 +0300204 - module: maas_wait_for_racks_import_done
azvyagintsev3ff2ef12018-06-01 21:30:45 +0300205 {%- if grains.get('kitchen-test') %}
206 - onlyif: /bin/false
207 {%- endif %}
208
Krzysztof Szukiełojć43bc7e02017-03-17 10:32:07 +0100209maas_config:
210 module.run:
211 - name: maas.process_maas_config
212 - require:
213 - cmd: maas_login_admin
Petr Michalec8a0d52e2018-05-30 16:22:56 +0200214 {%- if grains.get('kitchen-test') %}
215 - onlyif: /bin/false
216 {%- endif %}
Krzysztof Szukiełojć43bc7e02017-03-17 10:32:07 +0100217
azvyagintsev3ff2ef12018-06-01 21:30:45 +0300218{##}
219{% if region.get('boot_sources_delete_all_others', False) %}
220 {# Collect exclude list, all other - will be removed #}
221 {% set exclude_list=[] %}
222 {%- for _, bs in region.boot_sources.iteritems() %} {% if bs.url is defined %} {% do exclude_list.append(bs.url) %} {% endif %} {%- endfor %}
223region_boot_sources_delete_all_others:
Jiri Broulikccccf0a2018-04-11 16:49:14 +0200224 module.run:
azvyagintsev3ff2ef12018-06-01 21:30:45 +0300225 - name: maasng.boot_sources_delete_all_others
226 - except_urls: {{ exclude_list }}
Jiri Broulikccccf0a2018-04-11 16:49:14 +0200227 - require:
azvyagintsev3ff2ef12018-06-01 21:30:45 +0300228 - cmd: maas_login_admin
Jiri Broulikccccf0a2018-04-11 16:49:14 +0200229{%- endif %}
230
azvyagintsev3ff2ef12018-06-01 21:30:45 +0300231{##}
232{% if region.get('boot_sources', False) %}
233 {%- for b_name, b_source in region.boot_sources.iteritems() %}
234maas_region_boot_source_{{ b_name }}:
235 maasng.boot_source_present:
236 - url: {{ b_source.url }}
237 {%- if b_source.keyring_data is defined %}
238 - keyring_data: {{ b_source.keyring_data }}
239 {%- endif %}
240 {%- if b_source.keyring_file is defined %}
241 - keyring_file: {{ b_source.keyring_file }}
242 {%- endif %}
243 - require:
244 - cmd: maas_login_admin
245 {%- endfor %}
246{%- endif %}
247
248{##}
249 {% if region.get('boot_sources_selections', False) %}
250 {%- for bs_name, bs_source in region.boot_sources_selections.iteritems() %}
251maas_region_boot_sources_selection_{{ bs_name }}:
252 maasng.boot_sources_selections_present:
253 - bs_url: {{ bs_source.url }}
254 - os: {{ bs_source.os }}
255 - release: {{ bs_source.release|string }}
256 - arches: {{ bs_source.arches|string }}
257 - subarches: {{ bs_source.subarches|string }}
258 - labels: {{ bs_source.labels }}
259 - require_in:
260 - module: maas_config
azvyagintsevcb54d142018-06-19 16:18:32 +0300261 - module: maas_wait_for_racks_import_done
azvyagintsev3ff2ef12018-06-01 21:30:45 +0300262 - require:
263 - cmd: maas_login_admin
264 {% if region.get('boot_sources', False) %}
265 {%- for b_name, _ in region.boot_sources.iteritems() %}
266 - maas_region_boot_source_{{ b_name }}
267 {% endfor %}
268 {%- endif %}
269 {%- endfor %}
270 {%- endif %}
271{##}
272
azvyagintsevec61dd62017-11-16 19:12:05 +0200273{%- if region.get('commissioning_scripts', False) %}
274/etc/maas/files/commisioning_scripts/:
275 file.directory:
276 - user: root
277 - group: root
278 - mode: 755
279 - makedirs: true
280 - require:
281 - pkg: maas_region_packages
282
283/etc/maas/files/commisioning_scripts/00-maas-05-simplify-network-interfaces:
284 file.managed:
285 - source: salt://maas/files/commisioning_scripts/00-maas-05-simplify-network-interfaces
286 - mode: 755
287 - user: root
288 - group: root
289 - require:
290 - file: /etc/maas/files/commisioning_scripts/
291
Krzysztof Szukiełojć43bc7e02017-03-17 10:32:07 +0100292maas_commissioning_scripts:
293 module.run:
294 - name: maas.process_commissioning_scripts
295 - require:
azvyagintsev3ff2ef12018-06-01 21:30:45 +0300296 - cmd: maas_login_admin
azvyagintsevec61dd62017-11-16 19:12:05 +0200297{%- endif %}
Krzysztof Szukiełojć43bc7e02017-03-17 10:32:07 +0100298
azvyagintsevec61dd62017-11-16 19:12:05 +0200299{%- if region.get('fabrics', False) %}
azvyagintsevf3515c82018-06-26 18:59:05 +0300300 {%- for _, fabric in region.fabrics.iteritems() %}
301 {% set fabric_name=fabric.get('name', _) %}
302# First, create fabrics
303# Bakward-compat.name:
304
305maas_fabrics_{{ fabric_name }}:
306 maasng.fabric_present:
307 - name: {{ fabric_name }}
308 - description: {{ fabric.get('description', '') }}
Krzysztof Szukiełojćc4b33092017-02-15 13:25:38 +0100309 - require:
azvyagintsev3ff2ef12018-06-01 21:30:45 +0300310 - cmd: maas_login_admin
azvyagintsevf3515c82018-06-26 18:59:05 +0300311
312# Second, add VLAN into fabric's
313 {%- for vlan_n, data in fabric.get('vlans',{}).iteritems() %}
314maas_vlan{{ vlan_n }}_present_for_{{ fabric_name }}:
315 maasng.vlan_present_in_fabric:
316 - vlan: {{ vlan_n }}
Petr Ruzicka80471852018-07-13 14:08:27 +0200317 - mtu: {{ data.get('mtu','') }}
azvyagintsevf3515c82018-06-26 18:59:05 +0300318 - fabric: {{ fabric_name }}
319 - name: {{ data.get('name','') }}
320 - description: {{ data.description }}
321 - primary_rack: {{ data.get('primary_rack', '') }}
322 {%- endfor %}
323 {%- endfor %}
azvyagintsevec61dd62017-11-16 19:12:05 +0200324{%- endif %}
Krzysztof Szukiełojćc4b33092017-02-15 13:25:38 +0100325
azvyagintsevf3515c82018-06-26 18:59:05 +0300326# Create subnets
Pavel Cizinsky8dd85b52018-06-18 21:40:13 +0200327{%- if region.subnets is defined %}
azvyagintsevf3515c82018-06-26 18:59:05 +0300328 {%- for _, subnet in region.subnets.iteritems() %}
329maas_create_subnet_{{ subnet.cidr }}:
Pavel Cizinsky8dd85b52018-06-18 21:40:13 +0200330 maasng.subnet_present:
331 - cidr: {{ subnet.cidr }}
azvyagintsevf3515c82018-06-26 18:59:05 +0300332 - name: {{ subnet.get('name','') }}
Pavel Cizinsky8dd85b52018-06-18 21:40:13 +0200333 - fabric: {{ subnet.fabric }}
azvyagintsevf3515c82018-06-26 18:59:05 +0300334 - vlan: {{ subnet.get('vlan','') }}
Pavel Cizinsky8dd85b52018-06-18 21:40:13 +0200335 - gateway_ip: {{ subnet.gateway_ip }}
Krzysztof Szukiełojćc4b33092017-02-15 13:25:38 +0100336 - require:
azvyagintsev3ff2ef12018-06-01 21:30:45 +0300337 - cmd: maas_login_admin
azvyagintsev0c622322017-11-23 12:46:50 +0200338 {%- if region.get('fabrics', False) %}
azvyagintsevf3515c82018-06-26 18:59:05 +0300339 - maas_fabrics_{{ subnet.fabric }}
azvyagintsev0c622322017-11-23 12:46:50 +0200340 {%- endif %}
azvyagintsevf3515c82018-06-26 18:59:05 +0300341# create ranges
342 {%- for _r, iprange in subnet.get('ipranges',{}).iteritems() %}
343maas_create_iprange_{{ _r }}:
Pavel Cizinsky8dd85b52018-06-18 21:40:13 +0200344 maasng.iprange_present:
azvyagintsevf3515c82018-06-26 18:59:05 +0300345 - name: {{ iprange.get('name', _r) }}
Pavel Cizinsky8dd85b52018-06-18 21:40:13 +0200346 - type_range: {{ iprange.type }}
347 - start_ip: {{ iprange.start }}
348 - end_ip: {{ iprange.end }}
azvyagintsevf0904ac2018-07-05 18:53:26 +0300349 - subnet: {{ iprange.get('subnet', '' ) }}
azvyagintsevf3515c82018-06-26 18:59:05 +0300350 - comment: {{ iprange.get('comment', "") }}
Pavel Cizinsky8dd85b52018-06-18 21:40:13 +0200351 - require:
azvyagintsevf3515c82018-06-26 18:59:05 +0300352 - maas_create_subnet_{{ subnet.cidr }}
353 {%- endfor %}
354 {%- endfor %}
Pavel Cizinsky8dd85b52018-06-18 21:40:13 +0200355{%- endif %}
azvyagintsevf3515c82018-06-26 18:59:05 +0300356
357# Get back to fabrics again and enable DHCP
358{%- if region.get('fabrics', False) %}
359 {%- for _, fabric in region.fabrics.iteritems() %}
360 {%- for vlan_n, data in fabric.get('vlans',{}).iteritems() %}
361 {% set fabric_name=fabric.get('name', _) %}
362maas_vlan{{ vlan_n }}_present_for_{{ fabric_name }}_dhcp:
363 maasng.vlan_present_in_fabric:
364 - vlan: {{ vlan_n }}
Petr Ruzicka80471852018-07-13 14:08:27 +0200365 - mtu: {{ data.get('mtu','') }}
azvyagintsevf3515c82018-06-26 18:59:05 +0300366 - fabric: {{ fabric_name }}
367 - name: {{ data.get('name','') }}
368 - description: {{ data.description }}
369 - primary_rack: {{ data.get('primary_rack', '') }}
370 - dhcp_on: {{ data.get('dhcp','False') }}
371 {%- endfor %}
372 {%- endfor %}
azvyagintsevec61dd62017-11-16 19:12:05 +0200373{%- endif %}
Krzysztof Szukiełojćc4b33092017-02-15 13:25:38 +0100374
azvyagintsevec61dd62017-11-16 19:12:05 +0200375{%- if region.get('devices', False) %}
Krzysztof Szukiełojćc4b33092017-02-15 13:25:38 +0100376maas_devices:
377 module.run:
378 - name: maas.process_devices
379 - require:
azvyagintsev3ff2ef12018-06-01 21:30:45 +0300380 - cmd: maas_login_admin
azvyagintsev0c622322017-11-23 12:46:50 +0200381 {%- if region.get('subnets', False) %}
Krzysztof Szukiełojćc4b33092017-02-15 13:25:38 +0100382 - module: maas_subnets
azvyagintsev0c622322017-11-23 12:46:50 +0200383 {%- endif %}
azvyagintsevec61dd62017-11-16 19:12:05 +0200384{%- endif %}
Krzysztof Szukiełojćc4b33092017-02-15 13:25:38 +0100385
azvyagintsevec61dd62017-11-16 19:12:05 +0200386{%- if region.get('dhcp_snippets', False) %}
Krzysztof Szukiełojćc4b33092017-02-15 13:25:38 +0100387maas_dhcp_snippets:
388 module.run:
389 - name: maas.process_dhcp_snippets
390 - require:
azvyagintsev3ff2ef12018-06-01 21:30:45 +0300391 - cmd: maas_login_admin
azvyagintsevec61dd62017-11-16 19:12:05 +0200392{%- endif %}
Krzysztof Szukiełojćc4b33092017-02-15 13:25:38 +0100393
azvyagintsevec61dd62017-11-16 19:12:05 +0200394{%- if region.get('package_repositories', False) %}
Krzysztof Szukiełojćc4b33092017-02-15 13:25:38 +0100395maas_package_repositories:
396 module.run:
397 - name: maas.process_package_repositories
398 - require:
azvyagintsev3ff2ef12018-06-01 21:30:45 +0300399 - cmd: maas_login_admin
azvyagintsevec61dd62017-11-16 19:12:05 +0200400{%- endif %}
Krzysztof Szukiełojćc4b33092017-02-15 13:25:38 +0100401
azvyagintsev6913e5e2018-07-05 11:42:53 +0300402# FIXME
403# This function usless since broken API logic in module.
404# Should be refactored to be able work with regaiond-domain structure.
405#maas_domain:
406# module.run:
407# - name: maas.process_domain
408# - require:
409# - cmd: maas_login_admin
410# {%- if grains.get('kitchen-test') %}
411# - onlyif: /bin/false
412# {%- endif %}
Krzysztof Szukiełojć8cc32b42017-03-29 15:22:57 +0200413
Pavel Cizinsky0995e8f2018-05-04 17:10:37 +0200414
azvyagintsevec61dd62017-11-16 19:12:05 +0200415{%- if region.get('sshprefs', False) %}
Krzysztof Szukiełojća1bd77e2017-03-30 08:34:22 +0200416maas_sshprefs:
417 module.run:
418 - name: maas.process_sshprefs
419 - require:
azvyagintsev3ff2ef12018-06-01 21:30:45 +0300420 - cmd: maas_login_admin
azvyagintsevec61dd62017-11-16 19:12:05 +0200421{%- endif %}
Krzysztof Szukiełojća1bd77e2017-03-30 08:34:22 +0200422
Jakub Pavlik2bd298f2016-08-31 13:50:58 +0200423{%- endif %}