blob: 116548be3842b8d7a505db9c8493f46142da8044 [file] [log] [blame]
Filip Pytlounb4b80592015-10-06 16:28:32 +02001
Ales Komarek54740682017-05-15 07:16:23 +02002============
3Salt Formula
4============
Filip Pytlounb4b80592015-10-06 16:28:32 +02005
Ales Komarek54740682017-05-15 07:16:23 +02006Salt is a new approach to infrastructure management. Easy enough to get
7running in minutes, scalable enough to manage tens of thousands of servers,
8and fast enough to communicate with them in seconds.
Filip Pytlounb4b80592015-10-06 16:28:32 +02009
Ales Komarek54740682017-05-15 07:16:23 +020010Salt delivers a dynamic communication bus for infrastructures that can be used
11for orchestration, remote execution, configuration management and much more.
Filip Pytlounb4b80592015-10-06 16:28:32 +020012
Ales Komarek54740682017-05-15 07:16:23 +020013
14Sample Metadata
15===============
16
Filip Pytlounb4b80592015-10-06 16:28:32 +020017
Ales Komarekd768f1c2018-01-30 22:37:18 +010018Salt Master
Filip Pytlounb4b80592015-10-06 16:28:32 +020019-----------
20
Ales Komarek54740682017-05-15 07:16:23 +020021Salt master with base formulas and pillar metadata backend
Filip Pytlounb4b80592015-10-06 16:28:32 +020022
Ales Komarek8ba9c0b2016-02-21 14:59:59 +010023.. literalinclude:: tests/pillar/master_single_pillar.sls
24 :language: yaml
Filip Pytlounb4b80592015-10-06 16:28:32 +020025
Ales Komarek54740682017-05-15 07:16:23 +020026Salt master with reclass ENC metadata backend
Filip Pytlounb4b80592015-10-06 16:28:32 +020027
Ales Komarek8ba9c0b2016-02-21 14:59:59 +010028.. literalinclude:: tests/pillar/master_single_reclass.sls
29 :language: yaml
Filip Pytlounb4b80592015-10-06 16:28:32 +020030
Ales Komarek459407b2018-01-18 17:16:31 +010031Salt master with Architect ENC metadata backend
32
33.. code-block:: yaml
34
35 salt:
36 master:
37 enabled: true
38 pillar:
39 engine: architect
40 project: project-name
41 host: architect-api
42 port: 8181
43 username: salt
44 password: password
45
Petr Michalec1f541c42017-08-17 13:30:37 +020046Salt master with multiple ext_pillars
47
48.. literalinclude:: tests/pillar/master_single_extpillars.sls
49 :language: yaml
50
Filip Pytlounb4b80592015-10-06 16:28:32 +020051Salt master with API
52
Ales Komarekb2c8ff62016-08-22 00:20:01 +020053.. literalinclude:: tests/pillar/master_api.sls
54 :language: yaml
Ales Komarekcdb280f2016-07-27 15:37:51 +020055
56Salt master with defined user ACLs
57
Ales Komarekb2c8ff62016-08-22 00:20:01 +020058.. literalinclude:: tests/pillar/master_acl.sls
59 :language: yaml
Filip Pytlounb4b80592015-10-06 16:28:32 +020060
61Salt master with preset minions
62
63.. code-block:: yaml
64
65 salt:
66 master:
67 enabled: true
Filip Pytlounb4b80592015-10-06 16:28:32 +020068 minions:
69 - name: 'node1.system.location.domain.com'
70
Ales Komarek54740682017-05-15 07:16:23 +020071Salt master with pip based installation (optional)
Adam Tenglercaedd972016-05-04 16:44:00 +020072
73.. code-block:: yaml
74
75 salt:
76 master:
77 enabled: true
78 ...
79 source:
80 engine: pip
81 version: 2016.3.0rc2
82
Ales Komarek54740682017-05-15 07:16:23 +020083Install formula through system package management
Adam Tengler3eb85ad2016-05-06 02:52:40 +020084
85.. code-block:: yaml
86
87 salt:
88 master:
89 enabled: true
90 ...
91 environment:
92 prd:
Petr Michalec7a2f1d22017-05-17 22:08:32 +020093 keystone:
Adam Tengler3eb85ad2016-05-06 02:52:40 +020094 source: pkg
95 name: salt-formula-keystone
Petr Michalec7a2f1d22017-05-17 22:08:32 +020096 nova:
97 source: pkg
98 name: salt-formula-keystone
99 version: 0.1+0~20160818133412.24~1.gbp6e1ebb
100 postresql:
101 source: pkg
102 name: salt-formula-postgresql
103 version: purged
104
105Formula keystone is installed latest version and the formulas without version are installed in one call to aptpkg module.
106If the version attribute is present sls iterates over formulas and take action to install specific version or remove it.
107The version attribute may have these values ``[latest|purged|removed|<VERSION>]``.
Adam Tengler3eb85ad2016-05-06 02:52:40 +0200108
109Clone master branch of keystone formula as local feature branch
110
111.. code-block:: yaml
112
113 salt:
114 master:
115 enabled: true
116 ...
117 environment:
118 dev:
119 formula:
120 keystone:
121 source: git
122 address: git@github.com:openstack/salt-formula-keystone.git
123 revision: master
124 branch: feature
125
126Salt master with specified formula refs (for example for Gerrit review)
127
128.. code-block:: yaml
129
130 salt:
131 master:
132 enabled: true
133 ...
134 environment:
135 dev:
136 formula:
137 keystone:
138 source: git
139 address: https://git.openstack.org/openstack/salt-formula-keystone
140 revision: refs/changes/56/123456/1
141
Ales Komarek54740682017-05-15 07:16:23 +0200142Salt master with logging handlers
Filip Pytlounb4b80592015-10-06 16:28:32 +0200143
144.. code-block:: yaml
145
146 salt:
147 master:
148 enabled: true
Ales Komarek8ba9c0b2016-02-21 14:59:59 +0100149 handler:
150 handler01:
151 engine: udp
152 bind:
153 host: 127.0.0.1
154 port: 9999
Filip Pytlounb4b80592015-10-06 16:28:32 +0200155 minion:
Ales Komarek8ba9c0b2016-02-21 14:59:59 +0100156 handler:
157 handler01:
158 engine: udp
159 bind:
160 host: 127.0.0.1
161 port: 9999
162 handler02:
163 engine: zmq
164 bind:
165 host: 127.0.0.1
166 port: 9999
167
Ales Komareka9fc6e72017-09-06 15:02:40 +0200168Salt engine definition for saltgraph metadata collector
169
170.. code-block:: yaml
171
172 salt:
173 master:
174 engine:
175 graph_metadata:
176 engine: saltgraph
177 host: 127.0.0.1
178 port: 5432
179 user: salt
180 password: salt
181 database: salt
182
Ales Komarek459407b2018-01-18 17:16:31 +0100183Salt engine definition for Architect service
184
185.. code-block:: yaml
186
187 salt:
188 master:
189 engine:
190 architect:
191 engine: architect
192 project: project-name
193 host: architect-api
194 port: 8181
195 username: salt
196 password: password
197
Ales Komareka9fc6e72017-09-06 15:02:40 +0200198Salt engine definition for sending events from docker events
199
200.. code-block:: yaml
201
202 salt:
203 master:
204 engine:
205 docker_events:
206 docker_url: unix://var/run/docker.sock
207
Ales Komarek54740682017-05-15 07:16:23 +0200208Salt master peer setup for remote certificate signing
Jakub Pavlikd4859842016-05-23 10:48:04 +0200209
210.. code-block:: yaml
211
212 salt:
213 master:
214 peer:
215 ".*":
216 - x509.sign_remote_certificate
Filip Pytlounb4b80592015-10-06 16:28:32 +0200217
Ales Komarekb2ada522017-12-07 11:31:32 +0100218
219Salt master backup configuration
220
221.. code-block:: yaml
222
223 salt:
224 master:
225 backup: true
226 initial_data:
227 engine: backupninja
Jiri Broulik3e281642018-03-02 18:17:21 +0100228 home_dir: remote-backup-home-dir
Ales Komarekb2ada522017-12-07 11:31:32 +0100229 source: backup-node-host
230 host: original-salt-master-id
231
Tomáš Kukrál8922aef2017-05-10 10:27:04 +0200232Configure verbosity of state output (used for `salt` command)
233
234.. code-block:: yaml
235
236 salt:
237 master:
Tomáš Kukrál044667b2017-05-11 10:12:15 +0200238 state_output: changes
Tomáš Kukrál8922aef2017-05-10 10:27:04 +0200239
Ales Komarekd768f1c2018-01-30 22:37:18 +0100240Pass pillar render error to minion log
241
242.. note:: When set to `False` this option is great for debuging.
243 However it is not recomended for any production environment as it may contain
244 templating data as passwords, etc... , that minion should not expose.
245
246.. code-block:: yaml
247
248 salt:
249 master:
250 pillar_safe_render_error: False
251
252
253Event/Reactor Systems
254~~~~~~~~~~~~~~~~~~~~~
Petr Michalec1f541c42017-08-17 13:30:37 +0200255
Ales Komareke7844d12017-06-08 12:00:01 +0200256Salt synchronise node pillar and modules after start
Ales Komarek54740682017-05-15 07:16:23 +0200257
258.. code-block:: yaml
259
260 salt:
261 master:
262 reactor:
263 salt/minion/*/start:
Ales Komareke7844d12017-06-08 12:00:01 +0200264 - salt://salt/reactor/node_start.sls
Ales Komarek54740682017-05-15 07:16:23 +0200265
Ales Komareke7844d12017-06-08 12:00:01 +0200266Trigger basic node install
267
268.. code-block:: yaml
269
270 salt:
271 master:
272 reactor:
273 salt/minion/install:
274 - salt://salt/reactor/node_install.sls
275
276Sample event to trigger the node installation
277
278.. code-block:: bash
279
280 salt-call event.send 'salt/minion/install'
281
Ales Komarek213fbe02017-08-21 16:39:05 +0200282Run any defined orchestration pipeline
Ales Komarek5c58de32017-06-06 11:49:32 +0200283
284.. code-block:: yaml
285
286 salt:
287 master:
288 reactor:
289 salt/orchestrate/start:
290 - salt://salt/reactor/orchestrate_start.sls
291
Ales Komareke7844d12017-06-08 12:00:01 +0200292Event to trigger the orchestration pipeline
Ales Komarek5c58de32017-06-06 11:49:32 +0200293
294.. code-block:: bash
295
Ales Komareke7844d12017-06-08 12:00:01 +0200296 salt-call event.send 'salt/orchestrate/start' "{'orchestrate': 'salt/orchestrate/infra_install.sls'}"
Ales Komarek5c58de32017-06-06 11:49:32 +0200297
Ales Komarek3ed7c432017-08-24 16:15:49 +0200298Synchronise modules and pillars on minion start.
299
300.. code-block:: yaml
301
302 salt:
303 master:
304 reactor:
305 'salt/minion/*/start':
306 - salt://salt/reactor/minion_start.sls
307
Ales Komarek213fbe02017-08-21 16:39:05 +0200308Add and/or remove the minion key
Ales Komarek5c58de32017-06-06 11:49:32 +0200309
310.. code-block:: yaml
311
312 salt:
313 master:
314 reactor:
Ales Komarek213fbe02017-08-21 16:39:05 +0200315 salt/key/create:
316 - salt://salt/reactor/key_create.sls
317 salt/key/remove:
318 - salt://salt/reactor/key_remove.sls
Ales Komarek5c58de32017-06-06 11:49:32 +0200319
Ales Komarek213fbe02017-08-21 16:39:05 +0200320Event to trigger the key creation
Ales Komarek5c58de32017-06-06 11:49:32 +0200321
322.. code-block:: bash
323
Adam Tengler62188962017-09-04 13:34:44 +0000324 salt-call event.send 'salt/key/create' \
325 > "{'node_id': 'id-of-minion', 'node_host': '172.16.10.100', 'orch_post_create': 'kubernetes.orchestrate.compute_install', 'post_create_pillar': {'node_name': 'id-of-minion'}}"
Ales Komarek5c58de32017-06-06 11:49:32 +0200326
Ales Komarek213fbe02017-08-21 16:39:05 +0200327.. note::
328
329 You can add pass additional `orch_pre_create`, `orch_post_create`,
330 `orch_pre_remove` or `orch_post_remove` parameters to the event to call
331 extra orchestrate files. This can be useful for example for
332 registering/unregistering nodes from the monitoring alarms or dashboards.
333
334 The key creation event needs to be run from other machine than the one
335 being registered.
336
337Event to trigger the key removal
338
339.. code-block:: bash
340
341 salt-call event.send 'salt/key/remove'
Ales Komarek54740682017-05-15 07:16:23 +0200342
Petr Michalec1f541c42017-08-17 13:30:37 +0200343
Ales Komarekd768f1c2018-01-30 22:37:18 +0100344Encrypted Pillars
345~~~~~~~~~~~~~~~~~
Petr Michalec1f541c42017-08-17 13:30:37 +0200346
347Note: NACL + below configuration will be available in Salt > 2017.7.
348
349External resources:
350
351- Tutorial to configure salt + reclass ext_pillar and nacl: http://apealive.net/post/2017-09-salt-nacl-ext-pillar/
352- Saltstack documentation: https://docs.saltstack.com/en/latest/ref/modules/all/salt.modules.nacl.html
353
354Configure salt NACL module:
355
356.. code-block:: shell
357
358 pip install --upgrade libnacl===1.5.2
359 salt-call --local nacl.keygen /etc/salt/pki/master/nacl
360
361 local:
362 saved sk_file:/etc/salt/pki/master/nacl pk_file: /etc/salt/pki/master/nacl.pub
363
364
365.. code-block:: yaml
366
367 salt:
368 master:
369 pillar:
370 reclass: *reclass
371 nacl:
372 index: 99
373 nacl:
374 box_type: sealedbox
375 sk_file: /etc/salt/pki/master/nacl
376 pk_file: /etc/salt/pki/master/nacl.pub
377 #sk: None
378 #pk: None
379
380NACL encrypt secrets:
381
382 salt-call --local nacl.enc 'my_secret_value' pk_file=/etc/salt/pki/master/nacl.pub
383 hXTkJpC1hcKMS7yZVGESutWrkvzusXfETXkacSklIxYjfWDlMJmR37MlmthdIgjXpg4f2AlBKb8tc9Woma7q
384 # or
385 salt-run nacl.enc 'myotherpass'
386 ADDFD0Rav6p6+63sojl7Htfrncp5rrDVyeE4BSPO7ipq8fZuLDIVAzQLf4PCbDqi+Fau5KD3/J/E+Pw=
387
388
389NACL encrypted values on pillar:
390
391Use Boxed syntax `NACL[CryptedValue=]` to encode value on pillar:
392
393.. code-block:: yaml
394
395 my_pillar:
396 my_nacl:
397 key0: unencrypted_value
398 key1: NACL[hXTkJpC1hcKMS7yZVGESutWrkvzusXfETXkacSklIxYjfWDlMJmR37MlmthdIgjXpg4f2AlBKb8tc9Woma7q]
399
400NACL large files:
401
402.. code-block:: shell
403 salt-call nacl.enc_file /tmp/cert.crt out=/srv/salt/env/dev/cert.nacl
404 # or more advanced
405 cert=$(cat /tmp/cert.crt)
406 salt-call --out=newline_values_only nacl.enc_pub data="$cert" > /srv/salt/env/dev/cert.nacl
407
408
409NACL within template/native pillars:
410
411 pillarexample:
412 user: root
413 password1: {{salt.nacl.dec('DRB7Q6/X5gGSRCTpZyxS6hlbWj0llUA+uaVyvou3vJ4=')|json}}
414 cert_key: {{salt.nacl.dec_file('/srv/salt/env/dev/certs/example.com/cert.nacl')|json}}
415 cert_key2: {{salt.nacl.dec_file('salt:///certs/example.com/cert2.nacl')|json}}
416
Ales Komarekd768f1c2018-01-30 22:37:18 +0100417
418Salt Syndic
Ales Komarek54740682017-05-15 07:16:23 +0200419-----------
420
421The master of masters
422
423.. code-block:: yaml
424
425 salt:
426 master:
427 enabled: true
428 order_masters: True
429
430Lower syndicated master
431
432.. code-block:: yaml
433
434 salt:
435 syndic:
436 enabled: true
437 master:
438 host: master-of-master-host
439 timeout: 5
440
441Syndicated master with multiple master of masters
442
443.. code-block:: yaml
444
445 salt:
446 syndic:
447 enabled: true
448 masters:
449 - host: master-of-master-host1
450 - host: master-of-master-host2
451 timeout: 5
452
453
Ales Komarekd768f1c2018-01-30 22:37:18 +0100454Salt Minion
455-----------
456
457Simplest Salt minion setup with central configuration node
458
459.. code-block:: yaml
460
461.. literalinclude:: tests/pillar/minion_master.sls
462 :language: yaml
463
464Multi-master Salt minion setup
465
466.. literalinclude:: tests/pillar/minion_multi_master.sls
467 :language: yaml
468
469Salt minion with salt mine options
470
471.. literalinclude:: tests/pillar/minion_mine.sls
472 :language: yaml
473
474Salt minion with graphing dependencies
475
476.. literalinclude:: tests/pillar/minion_graph.sls
477 :language: yaml
478
479Salt minion behind HTTP proxy
480
481.. code-block:: yaml
482
483 salt:
484 minion:
485 proxy:
486 host: 127.0.0.1
487 port: 3128
488
489Salt minion to specify non-default HTTP backend. The default tornado backend
490does not respect HTTP proxy settings set as environment variables. This is
491useful for cases where you need to set no_proxy lists.
492
493.. code-block:: yaml
494
495 salt:
496 minion:
497 backend: urllib2
498
499
500Salt minion with PKI certificate authority (CA)
501
502.. literalinclude:: tests/pillar/minion_pki_ca.sls
503 :language: yaml
504
505Salt minion using PKI certificate
506
507.. literalinclude:: tests/pillar/minion_pki_cert.sls
508 :language: yaml
509
510Salt minion trust CA certificates issued by salt CA on a specific host (ie: salt-master node)
511
512.. code-block:: yaml
513
514 salt:
515 minion:
516 trusted_ca_minions:
517 - cfg01
518
519
520Salt Minion Proxy
521~~~~~~~~~~~~~~~~~
Jiri Broulika0f46682017-04-20 22:45:01 +0200522
523Salt proxy pillar
524
525.. code-block:: yaml
526
527 salt:
528 minion:
Jiri Broulik88275242017-05-24 17:21:17 +0200529 proxy_minion:
Jiri Broulika0f46682017-04-20 22:45:01 +0200530 master: localhost
531 device:
532 vsrx01.mydomain.local:
533 enabled: true
534 engine: napalm
535 csr1000v.mydomain.local:
536 enabled: true
537 engine: napalm
538
539.. note:: This is pillar of the the real salt-minion
540
541
542Proxy pillar for IOS device
543
544.. code-block:: yaml
545
546 proxy:
547 proxytype: napalm
548 driver: ios
549 host: csr1000v.mydomain.local
550 username: root
551 passwd: r00tme
552
553.. note:: This is pillar of the node thats not able to run salt-minion itself
554
555
556Proxy pillar for JunOS device
557
558.. code-block:: yaml
559
560 proxy:
561 proxytype: napalm
562 driver: junos
563 host: vsrx01.mydomain.local
564 username: root
565 passwd: r00tme
566 optional_args:
567 config_format: set
568
569.. note:: This is pillar of the node thats not able to run salt-minion itself
570
Ales Komarek8fb1da82016-08-21 23:52:03 +0200571
572Salt SSH
Ales Komarekd768f1c2018-01-30 22:37:18 +0100573~~~~~~~~
Ales Komarek8fb1da82016-08-21 23:52:03 +0200574
575Salt SSH with sudoer using key
576
577.. literalinclude:: tests/pillar/master_ssh_minion_key.sls
578 :language: yaml
579
580Salt SSH with sudoer using password
581
582.. literalinclude:: tests/pillar/master_ssh_minion_password.sls
583 :language: yaml
584
585Salt SSH with root using password
586
587.. literalinclude:: tests/pillar/master_ssh_minion_root.sls
588 :language: yaml
589
Ales Komarek8ba9c0b2016-02-21 14:59:59 +0100590Salt control (cloud/kvm/docker)
591-------------------------------
Filip Pytlounb4b80592015-10-06 16:28:32 +0200592
Ales Komarek8ba9c0b2016-02-21 14:59:59 +0100593Salt cloud with local OpenStack provider
Filip Pytlounb4b80592015-10-06 16:28:32 +0200594
Ales Komarek8ba9c0b2016-02-21 14:59:59 +0100595.. literalinclude:: tests/pillar/control_cloud_openstack.sls
596 :language: yaml
Filip Pytlounb4b80592015-10-06 16:28:32 +0200597
598Salt cloud with Digital Ocean provider
599
Ales Komarek8ba9c0b2016-02-21 14:59:59 +0100600.. literalinclude:: tests/pillar/control_cloud_digitalocean.sls
601 :language: yaml
Filip Pytlounb4b80592015-10-06 16:28:32 +0200602
Ales Komarek8fb1da82016-08-21 23:52:03 +0200603Salt virt with KVM cluster
Filip Pytlounb4b80592015-10-06 16:28:32 +0200604
Ales Komarek8ba9c0b2016-02-21 14:59:59 +0100605.. literalinclude:: tests/pillar/control_virt.sls
606 :language: yaml
Filip Pytlounb4b80592015-10-06 16:28:32 +0200607
Mateusz Los4c7cd2d2018-01-09 11:46:07 +0100608salt virt with custom destination for image file
609
610.. literalinclude:: tests/pillar/control_virt_custom.sls
611 :language: yaml
612
Filip Pytlounb4b80592015-10-06 16:28:32 +0200613
614Usage
615=====
616
617Working with salt-cloud
618
619.. code-block:: bash
620
621 salt-cloud -m /path/to/map --assume-yes
622
623Debug LIBCLOUD for salt-cloud connection
624
625.. code-block:: bash
626
627 export LIBCLOUD_DEBUG=/dev/stderr; salt-cloud --list-sizes provider_name --log-level all
628
Ales Komarek8ba9c0b2016-02-21 14:59:59 +0100629
Ales Komarekd768f1c2018-01-30 22:37:18 +0100630References
631==========
Filip Pytlounb4b80592015-10-06 16:28:32 +0200632
633* http://salt.readthedocs.org/en/latest/
634* https://github.com/DanielBryan/salt-state-graph
635* http://karlgrz.com/testing-salt-states-rapidly-with-docker/
636* https://mywushublog.com/2013/03/configuration-management-with-salt-stack/
637* http://russell.ballestrini.net/replace-the-nagios-scheduler-and-nrpe-with-salt-stack/
638* https://github.com/saltstack-formulas/salt-formula
639* http://docs.saltstack.com/en/latest/topics/tutorials/multimaster.html
640
Ales Komarek8ba9c0b2016-02-21 14:59:59 +0100641
Filip Pytlounb4b80592015-10-06 16:28:32 +0200642salt-cloud
643----------
644
645* http://www.blog.sandro-mathys.ch/2013/07/setting-user-password-when-launching.html
646* http://cloudinit.readthedocs.org/en/latest/topics/examples.html
647* http://salt-cloud.readthedocs.org/en/latest/topics/install/index.html
648* http://docs.saltstack.com/topics/cloud/digitalocean.html
649* http://salt-cloud.readthedocs.org/en/latest/topics/rackspace.html
650* http://salt-cloud.readthedocs.org/en/latest/topics/map.html
651* http://docs.saltstack.com/en/latest/topics/tutorials/multimaster.html
Ales Komarek8ba9c0b2016-02-21 14:59:59 +0100652
Filip Pytloun954dbd62017-02-02 13:02:03 +0100653
654Documentation and Bugs
655======================
656
657To learn how to install and update salt-formulas, consult the documentation
658available online at:
659
660 http://salt-formulas.readthedocs.io/
661
662In the unfortunate event that bugs are discovered, they should be reported to
663the appropriate issue tracker. Use Github issue tracker for specific salt
664formula:
665
666 https://github.com/salt-formulas/salt-formula-salt/issues
667
668For feature requests, bug reports or blueprints affecting entire ecosystem,
669use Launchpad salt-formulas project:
670
671 https://launchpad.net/salt-formulas
672
673You can also join salt-formulas-users team and subscribe to mailing list:
674
675 https://launchpad.net/~salt-formulas-users
676
677Developers wishing to work on the salt-formulas projects should always base
678their work on master branch and submit pull request against specific formula.
679
680 https://github.com/salt-formulas/salt-formula-salt
681
682Any questions or feedback is always welcome so feel free to join our IRC
683channel:
684
685 #salt-formulas @ irc.freenode.net