-
-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathspot.1
1653 lines (1618 loc) · 70.6 KB
/
spot.1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
.TH "SPOT" 1 20240427T195838 spot manual
.\" Automatically generated by Pandoc 3.1.13
.\"
.SH Spot
Spot is a powerful and easy\-to\-use tool for effortless deployment and
configuration management.
It allows users to define a playbook with a list of tasks and targets,
where each task consists of a series of commands that can be executed on
remote hosts concurrently.
Spot supports running scripts, copying files, syncing directories, and
deleting files or directories, as well as custom inventory files or
inventory URLs.
.SS Getting Started
.IP \[bu] 2
Install Spot by download the latest release from the \c
.UR https://github.com/umputun/spot/releases
Releases
.UE \c
\ page.
.IP \[bu] 2
Create a configuration file, as shown in the example below, and save it
as \f[CR]spot.yml\f[R].
.IP \[bu] 2
Run Spot using the following command: \f[CR]spot\f[R].
This will execute all the tasks defined in the default
\f[CR]spot.yml\f[R] file for the \f[CR]default\f[R] target with a
concurrency of 1.
.IP \[bu] 2
To execute a specific task, use the \f[CR]\-\-task\f[R] flag:
\f[CR]spot \-\-task=deploy\-things\f[R].
This will execute only the \f[CR]deploy\-things\f[R] task.
.IP \[bu] 2
To execute a specific task for a specific target, use the
\f[CR]\-\-task\f[R] and \f[CR]\-\-target\f[R] flags:
\f[CR]spot \-\-task=deploy\-things \-\-target=prod\f[R].
This will execute only the \f[CR]deploy\-things\f[R] task for the
\f[CR]prod\f[R] target.
.RS 2
.RE
.PP
\f[B]Install from homebrew (macOS)\f[R]
.IP
.EX
brew tap umputun/apps
brew install umputun/apps/spot
.EE
.PP
\f[I]This will install both \f[CI]spot\f[I] and \f[CI]spot\-secrets\f[I]
binaries.\f[R]
.PP
\f[B]Install from deb package (Ubuntu/Debian)\f[R]
.IP "1." 3
Download the latest version of the package by running:
\f[CR]wget https://github.com/umputun/spot/releases/download/<versiom>/spot_<version>_linux_<arch>.deb\f[R]
(replace \f[CR]<version>\f[R] and \f[CR]<arch>\f[R] with the actual
values).
.IP "2." 3
Install the package by running:
\f[CR]sudo dpkg \-i spot_<version>_linux_<arch>.deb\f[R]
.PP
Example for the version 0.14.6 and amd64 architecture:
.IP
.EX
wget https://github.com/umputun/spot/releases/download/v0.14.6/spot_v0.14.6_linux_<arch>.deb
sudo dpkg \-i spot_v0.14.6_linux_<arch>.deb
.EE
.PP
\f[B]Install from rpm package (CentOS/RHEL/Fedora/AWS Linux)\f[R]
.IP
.EX
wget https://github.com/umputun/spot/releases/download/v<version>/spot_v<version>_linux_<arch>.rpm
sudo rpm \-i spot_v<version>_linux_<arch>.rpm
.EE
.PP
\f[B]Install from apk package (Alpine)\f[R]
.IP
.EX
wget https://github.com/umputun/spot/releases/download/<versiom>/spot_<version>_linux_<arch>.apk
sudo apk add spot_<version>_linux_<arch>.apk
.EE
.PP
\f[B]Universal installation for Linux and macOS\f[R]
.PP
Spot provides a universal installation script that can be used to
install the latest version of the tool on Linux and macOS.
.IP "1." 3
Download the installation script:
\f[CR]wget https://raw.githubusercontent.com/umputun/spot/master/install.sh\f[R]
.IP "2." 3
Carefully review the script to make sure it is safe.
.IP "3." 3
Run the script: \f[CR]sudo sh install.sh\f[R]
.PP
The script will detect the OS and architecture and download the correct
binary for the latest version of Spot.
.PP
If you are brave enough, you can run the script directly from the web,
but I\[aq]d recommend downloading it first and reviewing it:
.IP
.EX
curl \-sSfL https://raw.githubusercontent.com/umputun/spot/master/install.sh \f[B]|\f[R] sudo sh
.EE
.PP
\f[B]Install with go install\f[R]
.PP
This method requires \c
.UR https://golang.org/
Go
.UE \c
\ to be installed on your system.
.IP
.EX
go install github.com/umputun/spot/cmd/spot\[at]latest
go install github.com/umputun/spot/cmd/spot\-secrets\[at]latest
.EE
.SS Options
Spot supports the following command\-line options:
.IP \[bu] 2
\f[CR]\-p\f[R], \f[CR]\-\-playbook=\f[R]: Specifies the playbook file
for use.
Defaults to \f[CR]spot.yml\f[R].
You can also set the environment variable \f[CR]$SPOT_PLAYBOOK\f[R] to
define the playbook file path.
.IP \[bu] 2
\f[CR]\-n\f[R], \f[CR]\-\-task=\f[R]: Specifies task names to execute.
The task should be defined in the playbook file.
Several tasks can be executed by providing the \f[CR]\-\-task\f[R] flag
multiple times, e.g., \f[CR]\-n copy_files \-n warmup_cache\f[R].
If not specified all the tasks will be executed.
.IP \[bu] 2
\f[CR]\-t\f[R], \f[CR]\-\-target=\f[R]: Specifies the target name to use
for the task execution.
The target should be defined in the playbook file and can represent
remote hosts, inventory files, or inventory URLs.
If not specified, the \f[CR]default\f[R] target will be used.
User can pass a hostname, group name, tag or IP instead of the target
name for a quick override.
Providing the \f[CR]\-t\f[R], \f[CR]\-\-target\f[R] flag multiple times
with different targets sets multiple destination targets or multiple
hosts, e.g., \f[CR]\-t prod \-t dev\f[R] or
\f[CR]\-t example1.com \-t example2.com\f[R].
.IP \[bu] 2
\f[CR]\-c\f[R], \f[CR]\-\-concurrent=\f[R]: Sets the number of
concurrent hosts to execute tasks.
Defaults to \f[CR]1\f[R], which means hosts will be handled
sequentially.
.IP \[bu] 2
\f[CR]\-\-timeout\f[R]: Sets the SSH timeout.
Defaults to \f[CR]30s\f[R].
User can also set the environment variable \f[CR]$SPOT_TIMEOUT\f[R] to
define the SSH timeout.
.IP \[bu] 2
\f[CR]\-\-ssh\-agent\f[R]: Enables using the SSH agent for
authentication.
Defaults to \f[CR]false\f[R].
Users can also set the environment variable \f[CR]SPOT_SSH_AGENT\f[R] to
define the value.
.IP \[bu] 2
\f[CR]\-\-forward\-ssh\-agent\f[R]: Enables forwarding of connections
from an authentication agent.
Defaults to \f[CR]false\f[R].
Users can also set the environment variable
\f[CR]SPOT_FORWARD_SSH_AGENT\f[R] to define the value.
.IP \[bu] 2
\f[CR]\-\-shell\f[R] \- shell for remote ssh execution, default is
\f[CR]/bin/sh\f[R].
Users can also set the environment variable \f[CR]SPOT_SHELL\f[R] to
define the value.
.IP \[bu] 2
\f[CR]\-i\f[R], \f[CR]\-\-inventory=\f[R]: Specifies the inventory file
or URL to use for the task execution.
Overrides the inventory file defined in the playbook file.
Users can also set the environment variable \f[CR]$SPOT_INVENTORY\f[R]
to define the default inventory file path or url.
.IP \[bu] 2
\f[CR]\-u\f[R], \f[CR]\-\-user=\f[R]: Specifies the SSH user to use when
connecting to remote hosts.
Overrides the user defined in the playbook file .
.IP \[bu] 2
\f[CR]\-k\f[R], \f[CR]\-\-key=\f[R]: Specifies the SSH key for
connecting to remote hosts.
Overrides the key defined in the playbook file.
.IP \[bu] 2
\f[CR]\-s\f[R], \f[CR]\-\-skip=\f[R]: Skips the specified commands
during the task execution.
Providing the \f[CR]\-s\f[R] flag multiple times with different command
names skips multiple commands.
.IP \[bu] 2
\f[CR]\-o\f[R], \f[CR]\-\-only=\f[R]: Runs only the specified commands
during the task execution.
Providing the \f[CR]\-o\f[R] flag multiple times with different command
names runs only multiple commands.
.IP \[bu] 2
\f[CR]\-e\f[R], \f[CR]\-\-env=\f[R]: Sets the environment variables to
be used during the task execution.
Providing the \f[CR]\-e\f[R] flag multiple times with different
environment variables sets multiple environment variables, e.g.,
\f[CR]\-e VAR1:VALUE1 \-e VAR2:VALUE2\f[R].
Values could be taken from the OS environment variables as well, e.g.,
\f[CR]\-e VAR1:$ENV_VAR1\f[R] or \f[CR]\-e VAR1:${ENV_VAR1}\f[R].
.IP \[bu] 2
\f[CR]\-E\f[R], \f[CR]\-\-env\-file=\f[R]: Sets the environment
variables from the file to be used during the task execution.
The file can have values from the OS environment variables as well.
The default is env.yml.
Can also be set with the environment variable \f[CR]SPOT_ENV_FILE\f[R].
.IP \[bu] 2
\f[CR]\-\-no\-color\f[R]: disable the colorized output.
It can also be set with the environment variable
\f[CR]SPOT_NO_COLOR\f[R].
.IP \[bu] 2
\f[CR]\-\-dry\f[R]: Enables dry\-run mode, which prints out the commands
to be executed without actually executing them.
.IP \[bu] 2
\f[CR]\-v\f[R], \f[CR]\-\-verbose\f[R]: Enables verbose mode, providing
more detailed output and error messages during the task execution.
Setting this flag multiple times increases the verbosity level, i.e.,
\f[CR]\-vv\f[R].
.IP \[bu] 2
\f[CR]\-\-dbg\f[R]: Enables debug mode, providing even more detailed
output and error messages during the task execution and diagnostic
messages.
.IP \[bu] 2
\f[CR]\-h\f[R] \f[CR]\-\-help\f[R]: Displays the help message, listing
all available command\-line options.
.SS Basic Concepts
.IP \[bu] 2
\f[B]Playbook\f[R] is a YAML or TOML file that defines a list of tasks
to be executed on one or more target hosts.
Each task consists of a series of commands that can be executed on the
target hosts.
Playbooks can be used to automate deployment and configuration
management tasks.
.IP \[bu] 2
\f[B]Task\f[R] is a named set of commands that can be executed on one or
more target hosts.
Tasks can be defined in a playbook and executed concurrently on multiple
hosts.
.IP \[bu] 2
\f[B]Command\f[R] is an action that can be executed on a target host.
Spot supports several built\-in commands, including copy, sync, delete,
script, echo, and wait.
.IP \[bu] 2
\f[B]Target\f[R] is a host or group of hosts on which a task can be
executed.
Targets can be specified directly in a playbook or defined in an
inventory file.
Spot supports several inventory file formats.
.IP \[bu] 2
\f[B]Inventory\f[R] is a list of targets that can be used to define the
hosts and groups of hosts on which a task can be executed.
.SS Playbooks
.SS Full playbook example
.IP
.EX
user\f[B]:\f[R] umputun\f[I] # default ssh user. Can be overridden by \-u flag or by inventory or host definition\f[R]
ssh_key\f[B]:\f[R] keys/id_rsa\f[I] # ssh key\f[R]
ssh_shell\f[B]:\f[R] /bin/bash\f[I] # shell to use for remote ssh execution, default is /bin/sh\f[R]
local_shell\f[B]:\f[R] /bin/bash\f[I] # shell to use for local execution, default is os shell\f[R]
inventory\f[B]:\f[R] /etc/spot/inventory.yml\f[I] # default inventory file. Can be overridden by \-\-inventory flag\f[R]
\f[I]# list of targets, i.e. hosts, inventory files or inventory URLs\f[R]
targets\f[B]:\f[R]
prod\f[B]:\f[R]
hosts\f[B]:\f[R]\f[I] # list of hosts, user, name and port optional. \f[R]
\f[B]\-\f[R] \f[B]{\f[R]host\f[B]:\f[R] \[dq]h1.example.com\[dq]\f[B],\f[R] user\f[B]:\f[R] \[dq]user2\[dq]\f[B],\f[R] name\f[B]:\f[R] \[dq]h1\[dq]\f[B]}\f[R]
\f[B]\-\f[R] \f[B]{\f[R]host\f[B]:\f[R] \[dq]h2.example.com\[dq]\f[B],\f[R] port\f[B]:\f[R] 2222\f[B]}\f[R]
staging\f[B]:\f[R]
groups\f[B]:\f[R] \f[B][\f[R]\[dq]dev\[dq]\f[B],\f[R] \[dq]staging\[dq]\f[B]]\f[R]\f[I] # list of groups from inventory file\f[R]
dev\f[B]:\f[R]
names\f[B]:\f[R] \f[B][\f[R]\[dq]devbox1\[dq]\f[B],\f[R] \[dq]devbox2\[dq]\f[B]]\f[R]\f[I] # list of server names from inventory file\f[R]
all\-boxes\f[B]:\f[R]
groups\f[B]:\f[R] \f[B][\f[R]\[dq]all\[dq]\f[B]]\f[R]\f[I] # all hosts from all groups from inventory file\f[R]
\f[I]# list of tasks, i.e. commands to execute\f[R]
tasks\f[B]:\f[R]
\f[B]\-\f[R] name\f[B]:\f[R] deploy\-things
on_error\f[B]:\f[R] \[dq]curl \-s localhost:8080/error?msg={SPOT_ERROR}\[dq]\f[I] # call hook on error\f[R]
commands\f[B]:\f[R]
\f[B]\-\f[R] name\f[B]:\f[R] wait
script\f[B]:\f[R] sleep 5s
\f[B]\-\f[R] name\f[B]:\f[R] copy configuration
copy\f[B]:\f[R] \f[B]{\f[R]\[dq]src\[dq]\f[B]:\f[R] \[dq]testdata/conf.yml\[dq]\f[B],\f[R] \[dq]dst\[dq]\f[B]:\f[R] \[dq]/tmp/conf.yml\[dq]\f[B],\f[R] \[dq]mkdir\[dq]\f[B]:\f[R] true\f[B]}\f[R]
\f[B]\-\f[R] name\f[B]:\f[R] copy other files
copy\f[B]:\f[R]
\f[B]\-\f[R] \f[B]{\f[R]\[dq]src\[dq]\f[B]:\f[R] \[dq]testdata/f1.csv\[dq]\f[B],\f[R] \[dq]dst\[dq]\f[B]:\f[R] \[dq]/tmp/things/f1.csv\[dq]\f[B],\f[R] \[dq]recur\[dq]\f[B]:\f[R] true\f[B]}\f[R]
\f[B]\-\f[R] \f[B]{\f[R]\[dq]src\[dq]\f[B]:\f[R] \[dq]testdata/f2.csv\[dq]\f[B],\f[R] \[dq]dst\[dq]\f[B]:\f[R] \[dq]/tmp/things/f2.csv\[dq]\f[B],\f[R] \[dq]recur\[dq]\f[B]:\f[R] true\f[B]}\f[R]
\f[B]\-\f[R] name\f[B]:\f[R] sync things
sync\f[B]:\f[R] \f[B]{\f[R]\[dq]src\[dq]\f[B]:\f[R] \[dq]testdata\[dq]\f[B],\f[R] \[dq]dst\[dq]\f[B]:\f[R] \[dq]/tmp/things\[dq]\f[B]}\f[R]
\f[B]\-\f[R] name\f[B]:\f[R] some command
script\f[B]: \f[R]|
ls \-laR /tmp
du \-hcs /srv
cat /tmp/conf.yml
echo all good, 123
\f[B]\-\f[R] name\f[B]:\f[R] delete things
delete\f[B]:\f[R] \f[B]{\f[R]\[dq]path\[dq]\f[B]:\f[R] \[dq]/tmp/things\[dq]\f[B],\f[R] \[dq]recur\[dq]\f[B]:\f[R] true\f[B]}\f[R]
\f[B]\-\f[R] name\f[B]:\f[R] show content
script\f[B]:\f[R] ls \-laR /tmp
\f[B]\-\f[R] name\f[B]:\f[R] docker
commands\f[B]:\f[R]
\f[B]\-\f[R] name\f[B]:\f[R] docker pull and start
script\f[B]: \f[R]|
docker pull umputun/remark42:latest
docker stop remark42 || true
docker rm remark42 || true
docker run \-d \-\-name remark42 \-p 8080:8080 umputun/remark42:latest
env\f[B]:\f[R] \f[B]{\f[R]FOO\f[B]:\f[R] bar\f[B],\f[R] BAR\f[B]:\f[R] qux\f[B]}\f[R]\f[I] # set environment variables for the command\f[R]
\f[B]\-\f[R] wait\f[B]:\f[R] \f[B]{\f[R]cmd\f[B]:\f[R] \[dq]curl \-s localhost:8080/health\[dq]\f[B],\f[R] timeout\f[B]:\f[R] \[dq]10s\[dq]\f[B],\f[R] interval\f[B]:\f[R] \[dq]1s\[dq]\f[B]}\f[R]\f[I] # wait for health check to pass\f[R]
.EE
.PP
\f[I]Alternatively, the playbook can be represented using the TOML
format.\f[R]
.SS Simplified playbook example
In some cases, the rich syntax of the full playbook is not needed and
can feel over\-engineered and even overwhelming.
For those situations, Spot supports a simplified playbook format, which
is easier to read and write, but also more limited in its capabilities.
.IP
.EX
user\f[B]:\f[R] umputun\f[I] # default ssh user. Can be overridden by \-u flag or by inventory or host definition\f[R]
ssh_key\f[B]:\f[R] keys/id_rsa\f[I] # ssh key\f[R]
ssh_shell\f[B]:\f[R] /bin/bash\f[I] # shell to use for remote ssh execution, default is /bin/sh\f[R]
local_shell\f[B]:\f[R] /bin/bash\f[I] # shell to use for local execution, default is os shell\f[R]
inventory\f[B]:\f[R] /etc/spot/inventory.yml\f[I] # default inventory file. Can be overridden by \-\-inventory flag\f[R]
targets\f[B]:\f[R] \f[B][\f[R]\[dq]devbox1\[dq]\f[B],\f[R] \[dq]devbox2\[dq]\f[B],\f[R] \[dq]h1.example.com:2222\[dq]\f[B],\f[R] \[dq]h2.example.com\[dq]\f[B]]\f[R]\f[I] # list of host names from inventory and direct host ips\f[R]
\f[I]# the actual list of commands to execute\f[R]
task\f[B]:\f[R]
\f[B]\-\f[R] name\f[B]:\f[R] wait
script\f[B]:\f[R] sleep 5s
\f[B]\-\f[R] name\f[B]:\f[R] copy configuration
copy\f[B]:\f[R] \f[B]{\f[R]\[dq]src\[dq]\f[B]:\f[R] \[dq]testdata/conf.yml\[dq]\f[B],\f[R] \[dq]dst\[dq]\f[B]:\f[R] \[dq]/tmp/conf.yml\[dq]\f[B],\f[R] \[dq]mkdir\[dq]\f[B]:\f[R] true\f[B]}\f[R]
\f[B]\-\f[R] name\f[B]:\f[R] copy other files
copy\f[B]:\f[R]
\f[B]\-\f[R] \f[B]{\f[R]\[dq]src\[dq]\f[B]:\f[R] \[dq]testdata/f1.csv\[dq]\f[B],\f[R] \[dq]dst\[dq]\f[B]:\f[R] \[dq]/tmp/things/f1.csv\[dq]\f[B],\f[R] \[dq]recur\[dq]\f[B]:\f[R] true\f[B]}\f[R]
\f[B]\-\f[R] \f[B]{\f[R]\[dq]src\[dq]\f[B]:\f[R] \[dq]testdata/f2.csv\[dq]\f[B],\f[R] \[dq]dst\[dq]\f[B]:\f[R] \[dq]/tmp/things/f2.csv\[dq]\f[B],\f[R] \[dq]recur\[dq]\f[B]:\f[R] true\f[B]}\f[R]
\f[B]\-\f[R] name\f[B]:\f[R] sync things
sync\f[B]:\f[R] \f[B]{\f[R]\[dq]src\[dq]\f[B]:\f[R] \[dq]testdata\[dq]\f[B],\f[R] \[dq]dst\[dq]\f[B]:\f[R] \[dq]/tmp/things\[dq]\f[B]}\f[R]
\f[B]\-\f[R] name\f[B]:\f[R] some command
script\f[B]: \f[R]|
ls \-laR /tmp
du \-hcs /srv
cat /tmp/conf.yml
echo all good, 123
\f[B]\-\f[R] name\f[B]:\f[R] delete things
delete\f[B]:\f[R] \f[B]{\f[R]\[dq]path\[dq]\f[B]:\f[R] \[dq]/tmp/things\[dq]\f[B],\f[R] \[dq]recur\[dq]\f[B]:\f[R] true\f[B]}\f[R]
\f[B]\-\f[R] name\f[B]:\f[R] show content
script\f[B]:\f[R] ls \-laR /tmp
\f[B]\-\f[R] name\f[B]:\f[R] docker pull and start
script\f[B]: \f[R]|
docker pull umputun/remark42:latest
docker stop remark42 || true
docker rm remark42 || true
docker run \-d \-\-name remark42 \-p 8080:8080 umputun/remark42:latest
env\f[B]:\f[R] \f[B]{\f[R]FOO\f[B]:\f[R] bar\f[B],\f[R] BAR\f[B]:\f[R] qux\f[B]}\f[R]\f[I] # set environment variables for the command\f[R]
\f[B]\-\f[R] wait\f[B]:\f[R] \f[B]{\f[R]cmd\f[B]:\f[R] \[dq]curl \-s localhost:8080/health\[dq]\f[B],\f[R] timeout\f[B]:\f[R] \[dq]10s\[dq]\f[B],\f[R] interval\f[B]:\f[R] \[dq]1s\[dq]\f[B]}\f[R]\f[I] # wait for health check to pass\f[R]
.EE
.PP
\f[B]For more examples see \c
.UR https://github.com/umputun/spot/tree/master/.examples
\&.examples
.UE \c
\ directory.\f[R]
.SS Playbook Types
Spot supports two types of playbooks: full and simplified.
Both can be represented in either YAML or TOML format.
The full playbook is more powerful and flexible but also more verbose
and complex.
The simplified playbook, on the other hand, is easier to read and write
but has more limited capabilities.
.PP
Here are the main differences between the two types of playbooks:
.IP \[bu] 2
The full playbook supports multiple target sets, while the simplified
playbook only supports a single target set.
In other words, the full playbook can execute the same set of commands
on multiple environments, with each environment defined as a separate
target set.
The simplified playbook can execute the same set of commands in just one
environment.
.IP \[bu] 2
The full playbook supports multiple tasks, while the simplified playbook
only supports a single task.
This means that the full playbook can execute multiple sets of commands,
whereas the simplified playbook can only execute one set of commands.
.IP \[bu] 2
The full playbook supports various target types, such as
\f[CR]hosts\f[R], \f[CR]groups\f[R], and \f[CR]names\f[R], while the
simplified playbook only supports a single type, which is a list of
names or host addresses.
See the Targets section for more details.
.IP \[bu] 2
The simplified playbook does not support task\-level \f[CR]on_error\f[R]
field, while the full playbook does.
See the Task details section for more information.
.IP \[bu] 2
The full playbook also supports task\-level \f[CR]user\f[R] field, which
allows setting the SSH user to use when connecting to remote hosts for
the particular task.
.IP \[bu] 2
The simplified playbook also has \f[CR]target\f[R] field (in addition to
\f[CR]targets\f[R]) that allows setting a single host/name only.
This is useful when users want to run the playbook on a single host
only.
The full playbook does not have this field.
.PP
Both types of playbooks support the remaining fields and options.
.SS Tasks and Commands
Each task consists of a list of commands that will be executed on the
remote host(s).
The task can also define the following optional fields:
.IP \[bu] 2
\f[CR]on_error\f[R]: specifies the command to execute on the local host
(the one running the \f[CR]spot\f[R] command) in case of an error.
The command can use the \f[CR]{SPOT_ERROR}\f[R] variable to access the
last error message.
Example:
\f[CR]on_error: \[dq]curl \-s localhost:8080/error?msg={SPOT_ERROR}\[dq]\f[R]
.IP \[bu] 2
\f[CR]user\f[R]: specifies the SSH user to use when connecting to remote
hosts.
Overrides the user defined in the top section of the playbook file for
the specified task.
.IP \[bu] 2
\f[CR]targets\f[R] \- list of target names, groups, tags, or host
addresses to execute the task on.
Command line \f[CR]\-t\f[R] flag can be used to override this field.
The \f[CR]targets\f[R] field may include variables.
For more details see Dynamic targets section.
.PP
\f[I]Note: these fields are supported in the full playbook type
only\f[R]
.PP
All tasks are executed sequentially on a given host, one after another.
If a task fails, the execution of the playbook will stop and the
\f[CR]on_error\f[R] command will be executed on the local host, if
defined.
Every task has to have \f[CR]name\f[R] field defined, which is used to
identify the task everywhere.
Playbook with a missing \f[CR]name\f[R] field will fail to execute
immediately.
Duplicate task names are not allowed either.
.SS Relative paths resolution
Relative path resolution is a frequent issue in systems that involve
file references or inclusion.
Different systems handle this in various ways.
Spot uses a widely\-adopted method of resolving relative paths based on
the current working directory of the process.
This means that if you run Spot from different directories, the way
relative paths are resolved will change.
In simpler terms, Spot doesn\[aq]t resolve relative paths according to
the location of the playbook file itself.
.PP
This approach is intentional to prevent confusion and make it easier to
comprehend relative path resolution.
Generally, it\[aq]s a good practice to run Spot from the same directory
where the playbook file is located when using relative paths.
Alternatively, you can use absolute paths for even better results.
.SS Command Types
Spot supports the following command types:
.SS \f[CR]script\f[R]
Can be any valid shell script.
The script will be executed on the remote host(s) using SSH, inside a
shell.
.IP
.EX
script\f[B]: \f[R]|
ls \-laR /tmp
du \-hcs /srv
cat /tmp/conf.yml
echo all good, 123
.EE
.PP
Read more about YAML multiline string formatting on \c
.UR https://yaml-multiline.info/
yaml\-multiline.info
.UE \c
\ and this \c
.UR https://stackoverflow.com/questions/3790454/how-do-i-break-a-string-in-yaml-over-multiple-lines
stackoverflow post
.UE \c
\&.
.SS \f[CR]copy\f[R]
Copies a file from the local machine to the remote host(s).
If \f[CR]mkdir\f[R] is set to \f[CR]true\f[R] the command will create
the destination directory if it doesn\[aq]t exist, the same as
\f[CR]mkdir \-p\f[R] in bash.
The command also supports glob patterns in \f[CR]src\f[R] field.
.PP
Copy command performs a quick check to see if the file already exists on
the remote host(s) with the same size and modification time, and skips
the copy if it does.
This option can be disabled by setting \f[CR]force: true\f[R] flag.
Another option is \f[CR]exclude\f[R] which allows to specify a list of
files to exclude to be copied.
.IP
.EX
\f[B]\-\f[R] name\f[B]:\f[R] copy file with mkdir
copy\f[B]:\f[R] \f[B]{\f[R]\[dq]src\[dq]\f[B]:\f[R] \[dq]testdata/conf.yml\[dq]\f[B],\f[R] \[dq]dst\[dq]\f[B]:\f[R] \[dq]/tmp/conf.yml\[dq]\f[B],\f[R] \[dq]mkdir\[dq]\f[B]:\f[R] true\f[B]}\f[R]
\f[B]\-\f[R] name\f[B]:\f[R] copy files with glob
copy\f[B]:\f[R] \f[B]{\f[R]\[dq]src\[dq]\f[B]:\f[R] \[dq]testdata/*.csv\[dq]\f[B],\f[R] \[dq]dst\[dq]\f[B]:\f[R] \[dq]/tmp/things\[dq]\f[B]}\f[R]
\f[B]\-\f[R] name\f[B]:\f[R] copy files with glob and exclude
copy\f[B]:\f[R] \f[B]{\f[R]\[dq]src\[dq]\f[B]:\f[R] \[dq]testdata/*.yml\[dq]\f[B],\f[R] \[dq]dst\[dq]\f[B]:\f[R] \[dq]/tmp/things\[dq]\f[B],\f[R] \[dq]exclude\[dq]\f[B]:\f[R] \f[B][\f[R]\[dq]conf.dist.yml\[dq]\f[B]]}\f[R]
\f[B]\-\f[R] name\f[B]:\f[R] copy files with force flag
copy\f[B]:\f[R] \f[B]{\f[R]\[dq]src\[dq]\f[B]:\f[R] \[dq]testdata/*.csv\[dq]\f[B],\f[R] \[dq]dst\[dq]\f[B]:\f[R] \[dq]/tmp/things\[dq]\f[B],\f[R] \[dq]force\[dq]\f[B]:\f[R] true\f[B]}\f[R]
.EE
.PP
Copy also supports list format to copy multiple files at once:
.IP
.EX
\f[B]\-\f[R] name\f[B]:\f[R] copy files with glob
copy\f[B]:\f[R]
\f[B]\-\f[R] \f[B]{\f[R]\[dq]src\[dq]\f[B]:\f[R] \[dq]testdata/*.csv\[dq]\f[B],\f[R] \[dq]dst\[dq]\f[B]:\f[R] \[dq]/tmp/things\[dq]\f[B]}\f[R]
\f[B]\-\f[R] \f[B]{\f[R]\[dq]src\[dq]\f[B]:\f[R] \[dq]testdata/*.yml\[dq]\f[B],\f[R] \[dq]dst\[dq]\f[B]:\f[R] \[dq]/tmp/things\[dq]\f[B]}\f[R]
.EE
.PP
Copy file and making it executable is also supported:
.IP
.EX
\f[B]\-\f[R] name\f[B]:\f[R] copy file and make it executable
copy\f[B]:\f[R]
\f[B]\-\f[R] \f[B]{\f[R]\[dq]src\[dq]\f[B]:\f[R] \[dq]testdata/script.sh\[dq]\f[B],\f[R] \[dq]dst\[dq]\f[B]:\f[R] \[dq]/tmp/script.sh\[dq]\f[B],\f[R] \[dq]chmod+x\[dq]\f[B]:\f[R] true\f[B]}\f[R]
.EE
.SS \f[CR]sync\f[R]
Synchronises directory from the local machine to the remote host(s).
Optionally supports deleting files on the remote host(s) that don\[aq]t
exist locally with \f[CR]\[dq]delete\[dq]: true\f[R] flag.
Another option is \f[CR]exclude\f[R] which allows to specify a list of
files to exclude from the sync.
.IP
.EX
\f[B]\-\f[R] name\f[B]:\f[R] sync directory
sync\f[B]:\f[R] \f[B]{\f[R]\[dq]src\[dq]\f[B]:\f[R] \[dq]testdata\[dq]\f[B],\f[R] \[dq]dst\[dq]\f[B]:\f[R] \[dq]/tmp/things\[dq]\f[B]}\f[R]
\f[B]\-\f[R] name\f[B]:\f[R] sync directory with delete
sync\f[B]:\f[R] \f[B]{\f[R]\[dq]src\[dq]\f[B]:\f[R] \[dq]testdata\[dq]\f[B],\f[R] \[dq]dst\[dq]\f[B]:\f[R] \[dq]/tmp/things\[dq]\f[B],\f[R] \[dq]delete\[dq]\f[B]:\f[R] true\f[B]}\f[R]
\f[B]\-\f[R] name\f[B]:\f[R] sync directory with exclude
sync\f[B]:\f[R] \f[B]{\f[R]\[dq]src\[dq]\f[B]:\f[R] \[dq]testdata\[dq]\f[B],\f[R] \[dq]dst\[dq]\f[B]:\f[R] \[dq]/tmp/things\[dq]\f[B],\f[R] \[dq]exclude\[dq]\f[B]:\f[R] \f[B][\f[R]\[dq]*.txt\[dq]\f[B],\f[R] \[dq]*.yml\[dq]\f[B]]}\f[R]
.EE
.PP
Sync also supports list format to sync multiple paths at once.
.SS \f[CR]delete\f[R]
Deletes a file or directory on the remote host(s), optionally can remove
recursively.
.IP
.EX
\f[B]\-\f[R] name\f[B]:\f[R] delete file
delete\f[B]:\f[R] \f[B]{\f[R]\[dq]path\[dq]\f[B]:\f[R] \[dq]/tmp/things.csv\[dq]\f[B]}\f[R]
\f[B]\-\f[R] name\f[B]:\f[R] delete directory recursively
delete\f[B]:\f[R] \f[B]{\f[R]\[dq]path\[dq]\f[B]:\f[R] \[dq]/tmp/things\[dq]\f[B],\f[R] \[dq]recur\[dq]\f[B]:\f[R] true\f[B]}\f[R]
\f[B]\-\f[R] name\f[B]:\f[R] delete directory recursively with exclude
delete\f[B]:\f[R] \f[B]{\f[R]\[dq]path\[dq]\f[B]:\f[R] \[dq]/tmp/things\[dq]\f[B],\f[R] \[dq]recur\[dq]\f[B]:\f[R] true\f[B],\f[R] \[dq]exclude\[dq]\f[B]:\f[R] \f[B][\f[R]\[dq]*.txt\[dq]\f[B],\f[R] \[dq]*.yml\[dq]\f[B]]}\f[R]
.EE
.PP
Delete also supports a list format to remove multiple paths at once.
.SS \f[CR]wait\f[R]
Waits for the specified command to finish on the remote host(s) with 0
error code.
This command is useful when a user needs to wait for a service to start
before executing the next command.
Allows to specify the timeout as well as check interval.
.IP
.EX
\f[B]\-\f[R] name\f[B]:\f[R] wait for service to start
wait\f[B]:\f[R] \f[B]{\f[R]\[dq]cmd\[dq]\f[B]:\f[R] \[dq]curl \-s \-\-fail localhost:8080\[dq]\f[B],\f[R] \[dq]timeout\[dq]\f[B]:\f[R] \[dq]30s\[dq]\f[B],\f[R] \[dq]interval\[dq]\f[B]:\f[R] \[dq]1s\[dq]\f[B]}\f[R]
.EE
.SS \f[CR]echo\f[R]
Prints the specified message to the console.
This command is useful for debugging purposes and also to print the
value of variables to the console.
.IP
.EX
\f[B]\-\f[R] name\f[B]:\f[R] print message
echo\f[B]:\f[R] \[dq]hello world\[dq]
\f[B]\-\f[R] name\f[B]:\f[R] print variable
echo\f[B]:\f[R] $some_var
.EE
.SS Command options
Each command type supports the following options:
.IP \[bu] 2
\f[CR]ignore_errors\f[R]: if set to \f[CR]true\f[R] the command will not
fail the task in case of an error.
.IP \[bu] 2
\f[CR]no_auto\f[R]: if set to \f[CR]true\f[R] the command will not be
executed automatically, but can be executed manually using the
\f[CR]\-\-only\f[R] flag.
.IP \[bu] 2
\f[CR]local\f[R]: if set to \f[CR]true\f[R] the command will be executed
on the local host (the one running the \f[CR]spot\f[R] command) instead
of the remote host(s).
.IP \[bu] 2
\f[CR]sudo\f[R]: if set to \f[CR]true\f[R] the command will be executed
with \f[CR]sudo\f[R] privileges.
This option is not supported for \f[CR]sync\f[R] command type but can be
used with any other command type.
.IP \[bu] 2
\f[CR]only_on\f[R]: allows to set a list of host names or addresses
where the command will be executed.
For example, \f[CR]only_on: [host1, host2]\f[R] will execute a command
on \f[CR]host1\f[R] and \f[CR]host2\f[R] only.
This option also supports reversed conditions, so if a user wants to
execute a command on all hosts except some, \f[CR]!\f[R] prefix can be
used.
For example, \f[CR]only_on: [!host1, !host2]\f[R] will execute a command
on all hosts except \f[CR]host1\f[R] and \f[CR]host2\f[R].
.PP
example setting \f[CR]ignore_errors\f[R], \f[CR]no_auto\f[R] and
\f[CR]only_on\f[R] options:
.IP
.EX
commands\f[B]:\f[R]
\f[B]\-\f[R] name\f[B]:\f[R] wait
script\f[B]:\f[R] sleep 5s
options\f[B]:\f[R] \f[B]{\f[R]ignore_errors\f[B]:\f[R] true\f[B],\f[R] no_auto\f[B]:\f[R] true\f[B],\f[R] only_on\f[B]:\f[R] \f[B][\f[R]host1\f[B],\f[R] host2\f[B]]}\f[R]
.EE
.PP
The same options can be set for the whole task as well.
In this case, the options will be applied to all commands in the task
but can be overridden for a specific command.
Pls note: the command option cannot reset the boolean options that were
set for the task.
This limitation is due to the way the default values are set.
.IP
.EX
\f[B]\-\f[R] name\f[B]:\f[R] deploy\-things
on_error\f[B]:\f[R] \[dq]curl \-s localhost:8080/error?msg={SPOT_ERROR}\[dq]\f[I] # call hook on error\f[R]
options\f[B]:\f[R] \f[B]{\f[R]ignore_errors\f[B]:\f[R] true\f[B],\f[R] no_auto\f[B]:\f[R] true\f[B],\f[R] only_on\f[B]:\f[R] \f[B][\f[R]host1\f[B],\f[R] host2\f[B]]}\f[R]
commands\f[B]:\f[R]
\f[B]\-\f[R] name\f[B]:\f[R] wait
script\f[B]:\f[R] sleep 5s
.EE
.SS Command conditionals
\f[CR]cond\f[R]: defines a condition for the command to be executed.
The condition is a valid shell command that will be executed on the
remote host(s) and if it returns 0, the primary command will be
executed.
For example, \f[CR]cond: \[dq]test \-f /tmp/foo\[dq]\f[R] will execute
the primary script command only if the file \f[CR]/tmp/foo\f[R] exists.
The condition can be reversed by adding \f[CR]!\f[R] prefix, i.e.
\f[CR]! test \-f /tmp/foo\f[R] will pass only if the file
\f[CR]/tmp/foo\f[R] doesn\[aq]t exist.
.PP
example installing curl package if not installed already:
.IP
.EX
\f[B]\-\f[R] name\f[B]:\f[R] \[dq]install curl\[dq]
script\f[B]:\f[R] \[dq]yum install curl \-y\[dq]
options\f[B]:\f[R] \f[B]{\f[R]sudo\f[B]:\f[R] true\f[B]}\f[R]
cond\f[B]:\f[R] \[dq]! command \-v curl\[dq]
.EE
.SS Deferred actions (\f[CR]on_exit\f[R])
Each command may have \f[CR]on_exit\f[R] parameter defined.
It allows executing a command on the remote host after the task with all
commands is completed.
The command is called regardless of the task\[aq]s exit code.
.PP
This is useful in several scenarios:
.IP \[bu] 2
a temporary script copied to the remote host and executed and should be
removed after execution with
\f[CR]on_exit: \[dq]rm \-fv /tmp/script.sh\[dq]\f[R]
.IP \[bu] 2
a service should be restarted after the new version is deployed with
\f[CR]on_exit: \[dq]systemctl restart myservice\[dq]\f[R]
.IP
.EX
\f[B]\-\f[R] name\f[B]:\f[R] \[dq]copy script\[dq]
copy\f[B]:\f[R] \f[B]{\f[R]src\f[B]:\f[R] \[dq]testdata/script.sh\[dq]\f[B],\f[R] \[dq]dst\[dq]\f[B]:\f[R] \[dq]/tmp/script.sh\[dq]\f[B],\f[R] \[dq]chmod+x\[dq]\f[B]:\f[R] true\f[B]}\f[R]
on_exit\f[B]:\f[R] \[dq]rm \-fv /tmp/script.sh\[dq]\f[I] # register deferred action to remove script.sh after execution\f[R]
\f[B]\-\f[R] name\f[B]:\f[R] \[dq]run script\[dq]
script\f[B]:\f[R] \[dq]/tmp/script.sh\[dq]
.EE
.PP
In the example above, the \f[CR]script.sh\f[R] is copied to the remote
host, executed, and removed after completion of the task.
.SS Script Execution
Spot allows executing scripts on remote hosts, or locally if
\f[CR]options.local\f[R] is set to true.
Scripts can be executed in two different ways, depending on whether they
are single\-line or multi\-line scripts.
.PP
\f[B]Single\-line Script Execution\f[R]
.PP
For single\-line scripts, they are executed directly inside the shell
with the optional parameters set to the command line.
For example:
.IP
.EX
commands\f[B]:\f[R]
\f[B]\-\f[R] name\f[B]:\f[R] some command
script\f[B]:\f[R] ls \-laR /tmp
env\f[B]:\f[R] \f[B]{\f[R]FOO\f[B]:\f[R] bar\f[B],\f[R] BAR\f[B]:\f[R] qux\f[B]}\f[R]
.EE
.PP
this will be executed as:
\f[CR]FOO=\[aq]bar\[aq] BAR=\[aq]qux\[aq]ls \-laR /tmp FOO=bar BAR=qux\f[R]
inside the shell on the remote host(s), i.e.
\f[CR]sh \-c \[dq]FOO=\[aq]bar\[aq] BAR=\[aq]qux\[aq]ls \-laR /tmp FOO=bar BAR=qux\[dq]\f[R].
.PP
\f[B]Multi\-line Script Execution\f[R]
.PP
For multi\-line scripts, Spot creates a temporary script containing all
the commands, uploads it to the remote host (or keeps it locally if
\f[CR]options.local\f[R] is set to true), and executes the script.
Environment variables are set inside the script, allowing the user to
create complex scripts that include setting variables, conditionals,
loops, and other advanced functionality.
Scripts run with \[dq]set \-e\[dq] to fail on error.
For example:
.IP
.EX
commands\f[B]:\f[R]
\f[B]\-\f[R] name\f[B]:\f[R] multi_line_script
script\f[B]: \f[R]|
touch /tmp/file1
echo \[dq]Hello World\[dq] > /tmp/file2
echo \[dq]Executing loop...\[dq]
for i in {1..5}; do
echo \[dq]Iteration $i\[dq]
done
echo \[dq]All done! $FOO $BAR
env\f[B]:\f[R] \f[B]{\f[R]FOO\f[B]:\f[R] bar\f[B],\f[R] BAR\f[B]:\f[R] qux\f[B]}\f[R]
.EE
.PP
this will create a temporary script on the remote host(s) with the
following content and execute it:
.IP
.EX
\f[I]#!/bin/sh\f[R]
set \-e
export FOO=\[aq]bar\[aq]
export BAR=\[aq]qux\[aq]
touch /tmp/file1
echo \[dq]Hello World\[dq] > /tmp/file2
echo \[dq]Executing loop...\[dq]
\f[B]for\f[R] i \f[B]in\f[R] {1..5}\f[B];\f[R] \f[B]do\f[R]
echo \[dq]Iteration $i\[dq]
\f[B]done\f[R]
echo \[dq]All done! $FOO $BAR\[dq]
.EE
.PP
By using this approach, Spot enables users to write and execute more
complex scripts, providing greater flexibility and power in managing
remote hosts or local environments.
.PP
Users can also set any custom shebang for the script by adding
\f[CR]#!\f[R] at the beginning of the script.
For example:
.IP
.EX
commands\f[B]:\f[R]
\f[B]\-\f[R] name\f[B]:\f[R] multi_line_script
script\f[B]: \f[R]|
#!/bin/bash
touch /tmp/file1
echo \[dq]Hello World\[dq] > /tmp/file2
.EE
.SS Passing variables from one script command to another
The spot allows passing variables from one command to another.
This feature is especially useful when a command, often a script, sets a
variable, and the subsequent command requires this variable.
For instance, if one command creates a file and the file name is needed
in another command.
To pass these variables, a user must use the conventional shell\[aq]s
export directive in the initial script command.
Subsequently, all variables exported in this initial command will be
accessible in the following commands.
.PP
For example:
.IP
.EX
commands\f[B]:\f[R]
\f[B]\-\f[R] name\f[B]:\f[R] first command
script\f[B]: \f[R]|
export FILE_NAME=/tmp/file1
touch $FILE_NAME
\f[B]\-\f[R] name\f[B]:\f[R] second command
script\f[B]: \f[R]|
echo \[dq]File name is $FILE_NAME\[dq]
\f[B]\-\f[R] name\f[B]:\f[R] third command
copy\f[B]:\f[R] \f[B]{\f[R]src\f[B]:\f[R] $FILE_NAME\f[B],\f[R] dest\f[B]:\f[R] /tmp/file2\f[B]}\f[R]
.EE
.PP
Sometimes, exporting variables is not possible or not desired.
For such cases, Spot allows to register variables explicitly using the
\f[CR]register\f[R] option.
.PP
For example:
.IP
.EX
commands\f[B]:\f[R]
\f[B]\-\f[R] name\f[B]:\f[R] first command
script\f[B]: \f[R]|
FILE_NAME=/tmp/file1
touch $FILE_NAME
ANOTHER_VAR=foo
register\f[B]:\f[R] \f[B][\f[R]FILE_NAME\f[B],\f[R] ANOTHER_VAR\f[B]]\f[R]
\f[B]\-\f[R] name\f[B]:\f[R] second command
script\f[B]: \f[R]|
echo \[dq]File name is $FILE_NAME, var is $ANOTHER_VAR\[dq]
\f[B]\-\f[R] name\f[B]:\f[R] third command
copy\f[B]:\f[R] \f[B]{\f[R]src\f[B]:\f[R] $FILE_NAME\f[B],\f[R] dest\f[B]:\f[R] /tmp/file2\f[B]}\f[R]
.EE
.PP
Another unique feature of the registered variables is that they can be
used not only in the subsequent commands for the current task but also
in the subsequent tasks.
This allows users to pass variables between tasks.
In other words, the registered variables are populated to the
environment of all the tasks in the playbook, automatically.
.PP
example:
.IP
.EX
tasks\f[B]:\f[R]
\f[B]\-\f[R] name\f[B]:\f[R] set_register_var
commands\f[B]:\f[R]
\f[B]\-\f[R] name\f[B]:\f[R] some command
script\f[B]: \f[R]|
echo good command 1
len=$(echo \[dq]file content\[dq] | wc \-c)
register\f[B]:\f[R] \f[B][\f[R]len\f[B]]\f[R]
\f[B]\-\f[R] name\f[B]:\f[R] use_register_var
commands\f[B]:\f[R]
\f[B]\-\f[R] name\f[B]:\f[R] some command
script\f[B]: \f[R]|
echo \[dq]len: $len\[dq]
.EE
.SS Setting environment variables
Environment variables can be set with \f[CR]\-\-env\f[R] /
\f[CR]\-e\f[R] cli option.
For example: \f[CR]\-e VAR1:VALUE1 \-e VAR2:VALUE2\f[R].
Environment variables can also be set in the environment file (default
\f[CR]env.yml\f[R] can be changed with \f[CR]\-\-env\-file\f[R] /
\f[CR]\-E\f[R] cli flag).
For example:
.IP
.EX
vars\f[B]:\f[R]
VAR1\f[B]:\f[R] VALUE1
VAR2\f[B]:\f[R] VALUE2
.EE
.PP
Environment variables can be used in the playbook file with the expected
syntax: \f[CR]$VAR_NAME\f[R] or \f[CR]${VAR_NAME}\f[R].
For example:
.IP
.EX
commands\f[B]:\f[R]
\f[B]\-\f[R] name\f[B]:\f[R] some command
script\f[B]:\f[R] echo $VAR1
\f[B]\-\f[R] name\f[B]:\f[R] another command
copy\f[B]:\f[R] \f[B]{\f[R]\[dq]src\[dq]\f[B]:\f[R] \[dq]testdata/*.csv\[dq]\f[B],\f[R] \[dq]dst\[dq]\f[B]:\f[R] \[dq]$VAR2\[dq]\f[B]}\f[R]
.EE
.PP
In case of a conflict between environment variables set in the
environment file and the cli, the cli variables will take precedence.
.SS Targets
Targets are used to define the remote hosts to execute the tasks on.
Targets can be defined in the playbook file or passed as a command\-line
argument.
The following target types are supported:
.IP \[bu] 2
\f[CR]hosts\f[R]: a list of destination host names or IP addresses, with
optional port and username, to execute the tasks on.
Example:
\f[CR]hosts: [{host: \[dq]h1.example.com\[dq], user: \[dq]test\[dq], name: \[dq]h1}, {host: \[dq]h2.example.com\[dq], \[dq]port\[dq]: 2222}]\f[R].
If no user is specified, the user defined in the top section of the
playbook file (or override) will be used.
If no port is specified, port 22 will be used.
.IP \[bu] 2
\f[CR]groups\f[R]: a list of groups from inventory to use.
Example: \f[CR]groups: [\[dq]dev\[dq], \[dq]staging\[dq]}\f[R].
A special group \f[CR]all\f[R] combines all the groups.
.IP \[bu] 2
\f[CR]tags\f[R]: a list of tags from inventory to use.
Example: \f[CR]tags: [\[dq]tag1\[dq], \[dq]tag2\[dq]}\f[R].
.IP \[bu] 2
\f[CR]names\f[R]: a list of host names from inventory to use.
Example: \f[CR]names: [\[dq]host1\[dq], \[dq]host2\[dq]}\f[R].
.PP
All the target types can be combined, i.e.
\f[CR]hosts\f[R], \f[CR]groups\f[R], \f[CR]tags\f[R], \f[CR]hosts\f[R]
and \f[CR]names\f[R] all can be used together in the same target.
To avoid possible duplicates, the final list of hosts is deduplicated by
the host+ip+user.
.PP
example of targets set in the playbook file:
.IP
.EX
targets\f[B]:\f[R]
prod\f[B]:\f[R]
hosts\f[B]:\f[R] \f[B][{\f[R]host\f[B]:\f[R] \[dq]h1.example.com\[dq]\f[B],\f[R] user\f[B]:\f[R] \[dq]test\[dq]\f[B]},\f[R] \f[B]{\f[R]\[dq]h2.example.com\[dq]\f[B],\f[R] \[dq]port\[dq]\f[B]:\f[R] 2222\f[B],\f[R] name\f[B]:\f[R] \[dq]h2\[dq]\f[B]}]\f[R]
staging\f[B]:\f[R]
groups\f[B]:\f[R] \f[B][\f[R]\[dq]staging\[dq]\f[B]]\f[R]
dev\f[B]:\f[R]
groups\f[B]:\f[R] \f[B][\f[R]\[dq]dev\[dq]\f[B],\f[R] \[dq]staging\[dq]\f[B]]\f[R]
names\f[B]:\f[R] \f[B][\f[R]\[dq]host1\[dq]\f[B],\f[R] \[dq]host2\[dq]\f[B]]\f[R]
all\-servers\f[B]:\f[R]
groups\f[B]:\f[R] \f[B][\f[R]\[dq]all\[dq]\f[B]]\f[R]
tasks\f[B]:\f[R]
\f[B]\-\f[R] name\f[B]:\f[R] task1
targets\f[B]:\f[R] \f[B][\f[R]\[dq]dev\[dq]\f[B],\f[R] \[dq]host3.example.com:2222\[dq]\f[B]]\f[R]
commands\f[B]:\f[R]
\f[B]\-\f[R] name\f[B]:\f[R] command1
script\f[B]:\f[R] echo \[dq]Hello World\[dq]
.EE
.PP
\f[I]Note: All the target types are available in the full playbook file
only.
The simplified playbook file only supports a single, anonymous target
type combining \f[CI]hosts\f[I] and \f[CI]names\f[I] together.\f[R]
.IP
.EX
targets\f[B]:\f[R] \f[B][\f[R]\[dq]host1\[dq]\f[B],\f[R] \[dq]host2\[dq]\f[B],\f[R] \[dq]host3.example.com\[dq]\f[B],\f[R] \[dq]host4.example.com:2222\[dq]\f[B]]\f[R]
.EE
.PP
in this example, the playbook will be executed on hosts named
\f[CR]host1\f[R] and \f[CR]host2\f[R] from the inventory and on hosts
\f[CR]host3.example.com\f[R] with port \f[CR]22\f[R] and
\f[CR]host4.example.com\f[R] with port \f[CR]2222\f[R].
.SS Target overrides
There are several ways to override or alter the target defined in the
playbook file via command\-line arguments:
.IP \[bu] 2
\f[CR]\-\-inventory\f[R] set hosts from the provided inventory file or
url.
Example: \f[CR]\-\-inventory=inventory.yml\f[R] or
\f[CR]\-\-inventory=http://localhost:8080/inventory\f[R].
.IP \[bu] 2
\f[CR]\-\-target\f[R] set groups, names, tags from inventory or direct
hosts to run the playbook on.
Example: \f[CR]\-\-target=prod\f[R] (will run on all hosts in group
\f[CR]prod\f[R]) or \f[CR]\-\-target=example.com:2222\f[R] (will run on
host \f[CR]example.com\f[R] with port \f[CR]2222\f[R]).
User name can be provided as a part of the direct target address as
well, i.e.
\f[CR]\-\-target=user2\[at]example.com:2222\f[R]
.IP \[bu] 2
\f[CR]\-\-user\f[R] set the ssh user to run the playbook on remote
hosts.
Example: \f[CR]\-\-user=test\f[R].
.IP \[bu] 2
\f[CR]\-\-key\f[R] set the ssh key to run the playbook on remote hosts.
Example: \f[CR]\-\-key=/path/to/key\f[R].
.SS Target selection
The target selection is done in the following order:
.IP \[bu] 2
if \f[CR]\-\-target\f[R] is set, it will be used.
.RS 2
.IP \[bu] 2
first Spot will try to match on target name in the playbook file.
.IP \[bu] 2
if no match is found, Spot will try to match on the group name in the
inventory file.
.IP \[bu] 2
if no match is found, Spot will try to match on tags in the inventory
file.
.IP \[bu] 2
if no match is found, Spot will try to match on hostname in the
inventory file.
.IP \[bu] 2
if no match is found, Spot will try to match on host address in the
playbook file.
.IP \[bu] 2
if no match is found, Spot will use it as a host address.
.RE
.IP \[bu] 2
if \f[CR]\-\-target\f[R] is not set, Spot will try to check it
\f[CR]targets\f[R] list for the task.
If set, it will use it following the same logic as above.
.IP \[bu] 2