automagix 4.0.0.dev1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. automagix-4.0.0.dev1/LICENSE +22 -0
  2. automagix-4.0.0.dev1/PKG-INFO +640 -0
  3. automagix-4.0.0.dev1/README.md +604 -0
  4. automagix-4.0.0.dev1/automagix/__init__.py +95 -0
  5. automagix-4.0.0.dev1/automagix/automagix.py +185 -0
  6. automagix-4.0.0.dev1/automagix/automagix_test.py +34 -0
  7. automagix-4.0.0.dev1/automagix/bash_completion.py +65 -0
  8. automagix-4.0.0.dev1/automagix/batch_runner.py +70 -0
  9. automagix-4.0.0.dev1/automagix/bundlewrap.py +75 -0
  10. automagix-4.0.0.dev1/automagix/colors.py +42 -0
  11. automagix-4.0.0.dev1/automagix/command.py +576 -0
  12. automagix-4.0.0.dev1/automagix/command_test.py +164 -0
  13. automagix-4.0.0.dev1/automagix/config.py +412 -0
  14. automagix-4.0.0.dev1/automagix/config_test.py +95 -0
  15. automagix-4.0.0.dev1/automagix/environment.py +85 -0
  16. automagix-4.0.0.dev1/automagix/environment_test.py +34 -0
  17. automagix-4.0.0.dev1/automagix/helpers.py +83 -0
  18. automagix-4.0.0.dev1/automagix/logger.py +95 -0
  19. automagix-4.0.0.dev1/automagix/parallel.py +197 -0
  20. automagix-4.0.0.dev1/automagix/parallel_runner.py +124 -0
  21. automagix-4.0.0.dev1/automagix/parallel_ui.py +222 -0
  22. automagix-4.0.0.dev1/automagix/progress_bar.py +206 -0
  23. automagix-4.0.0.dev1/automagix.egg-info/PKG-INFO +640 -0
  24. automagix-4.0.0.dev1/automagix.egg-info/SOURCES.txt +29 -0
  25. automagix-4.0.0.dev1/automagix.egg-info/dependency_links.txt +1 -0
  26. automagix-4.0.0.dev1/automagix.egg-info/entry_points.txt +4 -0
  27. automagix-4.0.0.dev1/automagix.egg-info/requires.txt +10 -0
  28. automagix-4.0.0.dev1/automagix.egg-info/top_level.txt +1 -0
  29. automagix-4.0.0.dev1/setup.cfg +4 -0
  30. automagix-4.0.0.dev1/setup.py +37 -0
  31. automagix-4.0.0.dev1/tests/test_environment.py +71 -0
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019-2026 //SEIBERT/MEDIA GmbH
4
+ Copyright (c) 2019-2026 Johannes Paul
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
@@ -0,0 +1,640 @@
1
+ Metadata-Version: 2.4
2
+ Name: automagix
3
+ Version: 4.0.0.dev1
4
+ Summary: Automation wrapper for bash and python commands
5
+ Home-page: https://codeberg.org/vanadinit/automagix
6
+ Author: Johannes Paul
7
+ Author-email: vanadinit@quantentunnel.de
8
+ License: MIT
9
+ Keywords: bash,shell,command,automation,process,wrapper,devops,system administration
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Requires-Python: >=3.10
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Requires-Dist: pyyaml>=5.1
16
+ Provides-Extra: tests
17
+ Requires-Dist: cython<3.0.0; extra == "tests"
18
+ Requires-Dist: pytest; extra == "tests"
19
+ Requires-Dist: pytest-docker; extra == "tests"
20
+ Requires-Dist: flake8; extra == "tests"
21
+ Provides-Extra: bash-completion
22
+ Requires-Dist: argcomplete; extra == "bash-completion"
23
+ Dynamic: author
24
+ Dynamic: author-email
25
+ Dynamic: classifier
26
+ Dynamic: description
27
+ Dynamic: description-content-type
28
+ Dynamic: home-page
29
+ Dynamic: keywords
30
+ Dynamic: license
31
+ Dynamic: license-file
32
+ Dynamic: provides-extra
33
+ Dynamic: requires-dist
34
+ Dynamic: requires-python
35
+ Dynamic: summary
36
+
37
+ ### This project is under construction ###
38
+
39
+ # automagix
40
+ Automation wrapper for bash and python commands. Extended Features version.
41
+ Fork of Automatix (https://github.com/seibert-media/automatix)
42
+
43
+ # DESCRIPTION
44
+
45
+ **automagix** is a wrapper for scripted sysadmin tasks. It offers
46
+ some useful functionality for easier scripting and having full
47
+ control over the automated process.
48
+
49
+ The idea of **automagix** is to write down all the commands you would
50
+ normally type to your commandline or python console into a YAML file.
51
+ Then use **automagix** to execute these commands.
52
+
53
+ There are different modes for **automagix** to work. Without any
54
+ parameters automagix will try to execute the specified command
55
+ pipeline from the script file until an error occurs or the pipeline
56
+ is done. The interactive mode (**-i**) asks for every single
57
+ commandline step whether to execute, skip or abort.
58
+ Forced mode (**-f**) will also proceed if errors occur.
59
+
60
+ **automagix** was originally designed for internal Seibert Group use.
61
+ It comes therefore with bundlewrap and teamvault support as well as
62
+ the possibility to use your own logging library.
63
+
64
+ ## Warning:
65
+
66
+ Beware that this tool cannot substitute the system administrators
67
+ brain and it needs a responsible handling, since you can do
68
+ (and destroy) almost everything with it.
69
+
70
+ **Automagix** evaluates YAML files and executes defined commands as
71
+ shell or python commands. There is no check for harmful commands.
72
+ Be aware that this can cause critical damage to your system.
73
+
74
+ Please use the interactive mode and doublecheck commands before
75
+ executing. Usage of automagix is at your own risk!
76
+
77
+
78
+ # INSTALLATION
79
+
80
+ Automagix requires Python &ge; 3.10.
81
+
82
+ ```
83
+ pip install automagix
84
+ ```
85
+
86
+ NOTICE: original `automagix` and `automagix_cmd` share the
87
+ same main entrypoint. To avoid overwriting and confusion,
88
+ you should have only installed **ONE** of them!
89
+
90
+ # CONFIGURATION
91
+
92
+ You can specify a path to a configuration YAML file via the
93
+ environment variable **AUTOMAGIX_CONFIG**.
94
+ Default location is "~/.automagix.cfg.yaml".
95
+ All (string) configuration values can be overwritten by the
96
+ corresponding upper case environment variables preceeded
97
+ by 'AUTOMAGIX_', e.g. _AUTOMAGIX_ENCODING_.
98
+
99
+ ### Example: .automagix.cfg.yaml
100
+
101
+ # Path to scripts directory
102
+ script_dir: '~/automagix_script_files'
103
+
104
+ # Global constants for use in pipeline scripts
105
+ constants:
106
+ apt_update: 'apt-get -qy update'
107
+ apt_upgrade: 'DEBIAN_FRONTEND=noninteractive apt-get -qy -o Dpkg::Options::=--force-confold --no-install-recommends upgrade'
108
+ apt_full_upgrade: 'DEBIAN_FRONTEND=noninteractive apt-get -qy -o Dpkg::Options::=--force-confold --no-install-recommends full-upgrade'
109
+
110
+ # Encoding
111
+ encoding: 'utf-8'
112
+
113
+ # Path to local bash (default: /bin/bash)
114
+ bash_path: '/bin/bash'
115
+
116
+ # SSH Command used for remote connections
117
+ # You propably want -t for pseudo-terminal allocation here.
118
+ ssh_cmd: 'ssh -t {hostname} sudo '
119
+
120
+ # Logger
121
+ logger: 'mylogger'
122
+
123
+ # Logging library (has to implement the init_logger method)
124
+ logging_lib: 'mylib.logging'
125
+
126
+ # Logfile directory for parallel processing (ONLY for parallel processing!)
127
+ logfile_dir: 'automagix_logs'
128
+
129
+ # Bundlewrap support, bundlewrap has to be installed (default: false)
130
+ bundlewrap: true
131
+
132
+ # Teamvault / Secret support, bundlewrap-teamvault has to be installed (default: false)
133
+ teamvault: true
134
+
135
+ # Activate progress bar, python_progress_bar has to be installed (default: false)
136
+ progress_bar: true
137
+
138
+ # Startup script, which is triggered on every start of Automagix.
139
+ # The whole Automagix call with all arguments is passed through as arguments.
140
+ startup_script: '/some/path/bin/automagix_startup.sh'
141
+
142
+ # SYNOPSIS
143
+
144
+ **automagix**
145
+ \[**--help**|**-h**\]
146
+ \[**--systems** \[_SYSTEM1=ADDRESS_OR_NODENAME_ ...\]\]
147
+ \[**--vars** \[_VAR1=VALUE1_ ...\]\]
148
+ \[**--secrets** \[_SECRET1=SECRETID_ ...\]\]
149
+ \[**--vars-file** _VARS_FILE_PATH_ \]
150
+ \[**--print-overview**|**-p**\]
151
+ \[**--jump-to**|**-j** _JUMP_TO_\]
152
+ \[**--steps**|**-s** _STEPS_\]
153
+ \[**--interactive**|**-i**\]
154
+ \[**--force**|**-f**\]
155
+ \[**--debug**|**-d**\]
156
+ \[**--**\] **scriptfile**
157
+
158
+
159
+ ## OPTIONS
160
+
161
+ **scriptfile**
162
+ : The only required parameter for this tool to work. Use " -- " if
163
+ needed to delimit this from argument fields. See **SCRIPTFILE**
164
+ section for more information.
165
+
166
+ **-h**, **--help**
167
+ : View help message and exit.
168
+
169
+ **--systems** _SYSTEM1=ADDRESS_OR_NODENAME_
170
+ : Use this to set systems without adding them to the
171
+ scriptfile or to overwrite them. You can specify multiple
172
+ systems like: --systems v1=string1 v2=string2 v3=string3
173
+
174
+ **--vars** _VAR1=VALUE1_
175
+ : Use this to set vars without adding them to the scriptfile
176
+ or to overwrite them. You can specify multiple vars
177
+ like: --vars v1=string1 v2=string2 v3=string3
178
+
179
+ **--secrets** _SECRET1=SECRETID_
180
+ : Use this to set secrets without adding them to the
181
+ scriptfile or to overwrite them. You can specify multiple
182
+ secrets like: --secrets v1=string1 v2=string2 v3=string3 *(only if
183
+ teamvault is enabled)*
184
+
185
+ **--vars-file** _VARS_FILE_PATH_
186
+ : Use this to specify a CSV file from where **automagix** reads
187
+ systems, variables and secrets. First row must contain the field
188
+ types and names. You may also specify an `label` and `group` field.
189
+
190
+ The `label` field can be to achieve a better overview and which row
191
+ is currently executed. It is used, when printing error messages or
192
+ as status line in screens for parallel processing. Without label
193
+ the row number is displayed.
194
+
195
+ The `group` field is only relevant for parallel processing. Row of
196
+ the same group are grouped together in a single screen and processed
197
+ sequentially there. Different groups are processed parallel.
198
+ Rows without specified group are run each in a parallel screen.
199
+ These rows are processed after the groups.
200
+
201
+ Example header: `label,group,systems:mysystem,vars:myvar`.
202
+
203
+ **--parallel**
204
+ : Run CSV file entries parallel in screen sessions; only valid with --vars-file.
205
+ GNU screen has to be installed. See EXTRAS section below.
206
+
207
+ **--print-overview**, **-p**
208
+ : Just print command pipeline overview with indices then exit without
209
+ executing the commandline. Note that the *always pipeline* will be
210
+ executed anyway.
211
+
212
+ **--jump-to** _JUMP_TO_, **-j** _JUMP_TO_
213
+ : Jump to step with index _JUMP_TO_ instead of starting at the
214
+ beginning. Use this option without argument to get an interactive selection.
215
+ You can also use negative numbers to start counting from the end.
216
+
217
+ **--steps** _STEPS_, **-s** _STEPS_
218
+ : Only execute these steps (comma-separated indices) or exclude steps
219
+ by prepending the comma-separated list with "e".
220
+ Examples: `-s 1,3,7`, `-s e2`, `-s e0,5,7,2`
221
+
222
+ **--interactive**, **-i**
223
+ : Confirm actions before executing.
224
+
225
+ **--force**, **-f**
226
+ : Try always to proceed (except manual steps), even if errors occur
227
+ (no retries).
228
+
229
+ **--debug**, **-d**
230
+ : Activate debug log level.
231
+
232
+
233
+ ### EXAMPLE: Usage
234
+
235
+ automagix -i --systems source=sourcesystem.com target=targetsystem.org -- scriptfile.yaml
236
+
237
+
238
+ ## SCRIPTFILE
239
+
240
+ The **scriptfile** describes your automated process. Therefore it
241
+ contains information about systems, variables, secrets and the
242
+ command pipeline.
243
+
244
+ You can provide a path to your **scriptfile** or place your
245
+ scriptfile in the predefined directory (see **CONFIGURATION**
246
+ section, _script_dir_). The path has precedence over the predefined
247
+ directory, if the file exists at both locations.
248
+
249
+ The **scriptfile** has to contain valid YAML.
250
+
251
+ ### EXAMPLE: scriptfile
252
+
253
+ name: Migration Server XY
254
+ # Systems you like to refer to in pipeline (accessible via 'SYSTEMS.source')
255
+ # If Bundlewrap support is activated use node names instead of hostnames or add preceeding 'hostname!'.
256
+ require_version: '1.5.0'
257
+ systems:
258
+ source: sourcesystem.com
259
+ target: targetsystem.org
260
+ # Custom vars to use in pipeline
261
+ vars:
262
+ version: 1.2.3
263
+ domain: 'bla.mein-test-system'
264
+ # Teamvault Secrets, if activated (left: like vars, right: SECRETID_FIELD, FIELD=username|password|file)
265
+ secrets:
266
+ web_user: v6GQag_username
267
+ web_pw: v6GQag_password
268
+ # Precommands, which are executed before each shell command in the main pipeline
269
+ precommands:
270
+ local: '. myfunctions'
271
+ remote: '. /tmp/myfunctions'
272
+ # like command pipeline but will be exectuted always beforehand
273
+ always:
274
+ - python: |
275
+ import mylib as nc
276
+ PERSISTENT_VARS.update(locals())
277
+ pipeline:
278
+ - remote@target: systemctl stop server
279
+ - remote@source: zfs snapshot -r tank@before-migration
280
+ - manual: Please trigger preparing tasks via webinterface
281
+ - myvar=local: curl -L -vvv -k https://{domain}/
282
+ - local: echo "1.1.1.1 {domain}" >> /etc/hosts
283
+ - sla=python: NODES.source.metadata.get('sla')
284
+ - python: |
285
+ sla = '{sla}'
286
+ if sla == 'gold':
287
+ print('Wow that\'s pretty cool. You have SLA Gold.')
288
+ else:
289
+ print('Oh. Running out of money? SLA Gold is worth it. You should check your wallet.')
290
+ PERSISTENT_VARS['sla'] = sla
291
+ - cond=python: sla == 'gold'
292
+ - cond?local: echo "This command is only executed if sla is gold."
293
+ cleanup:
294
+ - local: rm temp_files
295
+
296
+
297
+ ### FIELDS
298
+
299
+ **name** _(string)_
300
+ : Just a name for the process. Does not do anything.
301
+
302
+ **require_version** _(string)_
303
+ : The required Automagix version for this script to run. Similar to the
304
+ [Python version specifiers](https://packaging.python.org/en/latest/specifications/version-specifiers/#version-specifiers).
305
+ Multiple conditions can be separated by comma. Allowed operators are: "==","!=",">=" (default),"<=",">","<","~="
306
+
307
+ **systems** _(associative array)_
308
+ : Define some systems. Value has to be a valid SSH destination like an
309
+ IP address or hostname. If Bundlewrap support is enabled, it has to
310
+ be a valid and existing Bundlewrap node or group name, or you can
311
+ precede your IP or hostname with `hostname!` to define a
312
+ non-Bundlewrap system.
313
+ You can refer to these systems in the command pipeline in multiple ways:
314
+
315
+ 1) remote@systemname as your command action (see below)
316
+
317
+ 2) via {SYSTEMS.systemname} which will be replaced with the value
318
+
319
+ 3) via SYSTEMS.systemname in python actions which contains the value
320
+
321
+ 4) via NODES.systemname in python actions to use the Bundlewrap node
322
+ object (Bundlewrap nodes only, no groups)
323
+
324
+ **vars** _(associative array)_
325
+ : Define some vars. These are accessible in the command pipeline via
326
+ {varname}. Note: Only valid Python variable names are allowed.
327
+ In python actions you can access these variables directly via `VARS.varname`.
328
+
329
+ **secrets** _(associative array)_
330
+ : Define teamvault secrets. Value has to be in this format:
331
+ _SECRETID_FIELD_. _FIELD_ must be one of username, password or file.
332
+ The resolved secret values are accessible in command line via
333
+ {secretname}. *(only if teamvault is enabled)*
334
+
335
+ **precommands** _(associative array)_
336
+ : Define a command which is executed before every shell command.
337
+ You can specify a command for local and remote commands separately.
338
+ This can be useful to source files with shell functions you want to use.
339
+
340
+ **always**, **cleanup** _(list of associative arrays)_
341
+ : See **ALWAYS / CLEANUP PIPELINE** section.
342
+
343
+ **pipeline** _(list of associative arrays)_
344
+ : See **PIPELINE** section.
345
+
346
+ ### PIPELINE
347
+
348
+ Here you define the commands automagix shall execute.
349
+
350
+ **KEY**: One of these possible command actions:
351
+
352
+ 1) **manual**: Some manual instruction for the user. The user has to
353
+ confirm, that automagix may proceed.
354
+
355
+ 2) **local**: Local shell command to execute. The Bash specified
356
+ in `bash_path` (default: /bin/bash) will be used for execution.
357
+ The environment is inherited with additional
358
+ **RUNNING_INSIDE_AUTOMAGIX** set to 1.
359
+
360
+ 3) **remote@systemname**: Remote shell command to execute. Systemname
361
+ has to be a defined system. The command will be run via SSH (without
362
+ pseudo-terminal allocation). It uses the standard SSH command.
363
+ Therefore your .ssh/config should be respected.
364
+ If systemname is a Bundlewrap group, the remote command will be
365
+ executed sequentially for every node.
366
+
367
+ 4) **python**: Python code to execute.
368
+ * `PERSISTENT_VARS`, `PVARS`, `SkipBatchItemException`, `AbortException`
369
+ are available, see corresponding sections in **TIPS & TRICKS**
370
+ * Notice that the variable `VARS` contains
371
+ the Automagix variables as a dictionary. `VARS` supports also
372
+ the attribute notation like `VARS.myvariable`. You can use it
373
+ to access or change the variables directly.
374
+ * The path to the executed script file is available as `SCRIPT_FILE_PATH`.
375
+ * You can refer to systems and constants via `SYSTEMS.systemname`
376
+ and `CONST.constantname`.
377
+ * If bundlewrap is enabled, the Bundlewrap repository object is
378
+ available via `AUTOMAGIX_BW_REPO` and system node objects are
379
+ available via `NODES.systemname` (replace "systemname").
380
+ Use `AUTOMAGIX_BW_REPO.reload()` to reinitialize the Bundlewrap
381
+ repository from the file system. This can be useful for using
382
+ newly created nodes (e.g. remote commands).
383
+
384
+
385
+ **ASSIGNMENT**: For **local**, **remote** and **python** action you
386
+ can also define a variable to which the output will be assigned.
387
+ To do this prefix the desired variablename and = before the action
388
+ key, e.g. `myvar=python: NODES.system.hostname`. Be careful when
389
+ working with multiline statements. In **python** the first line is
390
+ likely to set the variable. All variables will be converted to
391
+ strings when used to build commands in following steps.
392
+
393
+ **CONDITIONS**: You can define the command only to be executed if
394
+ your condition variable evaluates to "True" in Python. To achieve
395
+ this write the variable name followed by a question mark at the very
396
+ beginning like `cond?python: destroy_system()`. Be aware that all
397
+ output from **local** or **remote** commands will lead to a non-empty
398
+ string which evaluates to "True" in Python, but empty output will
399
+ evaluate to "False". Use `!?` instead of `?` to invert the condition.
400
+
401
+ **VALUE**: Your command. Variables will be replaced with Python
402
+ format function. Therefore, use curly brackets to refer to variables,
403
+ systems, secrets and constants.
404
+
405
+ Constants are available via CONST.KEY, where KEY is the key of your
406
+ constants in your **CONFIGURATION** file. There you can define some
407
+ widely used constants.
408
+
409
+ In most cases its a good idea to define your command in quotes to
410
+ avoid parsing errors, but it is not always necessary. Another way is
411
+ to use '|' to indicate a _literal scalar block_. There you can even
412
+ define whole program structures for python (see example).
413
+
414
+ #### Escaping in Pipeline
415
+
416
+ Because automagix uses Python's format() function:
417
+ `{` -> `{{`
418
+ `}` -> `}}`
419
+
420
+ Standard YAML escapes (see also https://yaml.org/spec/1.2/spec.html):
421
+ `'` -> `''`
422
+ `"` -> `\"`
423
+ `\ ` -> `\\`
424
+ `:` -> Please use quotes (double or single).
425
+
426
+
427
+ ### ALWAYS / CLEANUP PIPELINE
428
+
429
+ Same usage as the 'normal' command pipeline, but will be executed
430
+ every time at start of automagix (**always**) or at the end
431
+ (**cleanup**) even if aborted (a). The commands are executed without
432
+ --interactive flag, independend of the specified parameters.
433
+
434
+ Intended use case for **always**: python imports or informations that
435
+ are needed afterwards and do not change anything on systems.
436
+ You want to have these available even if using --jump|-j feature.
437
+
438
+ Intended use case for **cleanup**: Remove temporary files or artifacts.
439
+
440
+
441
+ ## ENVIRONMENT
442
+
443
+ **AUTOMAGIX_CONFIG**: Specify the path to the configuration file.
444
+ Default is "~/.automagix.cfg.yaml".
445
+
446
+ **AUTOMAGIX_**_config-variable-in-upper-case_: Set or overwrite the
447
+ corresponding configuration value. See **CONFIGURATION** section.
448
+ Works only for string and boolean values!
449
+ String values (case-insensitive 'true' or 'false') are converted
450
+ to `True` or `False` in Python, if the fields expects a boolean.
451
+ **All other values (int, float, dict, list, ...) are ignored!**
452
+
453
+ **AUTOMAGIX_TIME**: Set this to an arbitrary value to print the times
454
+ for the single steps and the whole script, e.g. `AUTOMAGIX_TIME=true`.
455
+
456
+
457
+ # TIPS & TRICKS
458
+
459
+ ### YAML Syntax
460
+
461
+ For multiline commands and variables YAML offers different possibilities
462
+ to write multiline strings. A look at https://yaml-multiline.info/ might
463
+ be helpful.
464
+
465
+ ### PERSISTENT_VARS
466
+
467
+ If you want to access variables in **python** action you defined in
468
+ preceeding command, you can use the **PERSISTENT_VARS** dictionary
469
+ (shortcut: **PVARS**).
470
+ This is added to the local scope of **python** actions and the
471
+ dictonary keys are also available as attributes.
472
+ Examples:
473
+ - To make all local variables of the actual command persistent use
474
+ `PERSISTENT_VARS.update(locals())`.
475
+ - To delete one persistent variable named "myvar" use
476
+ `del PERSISTENT_VARS['myvar']`
477
+ - To make variable "v2" persistent use `PERSISTENT_VARS['v2'] = v2`
478
+ or `PERSISTENT_VARS.v2 = v2`
479
+ - Use the shortcut like `PVARS.v2 = v2`
480
+
481
+ **Note: Following works ONLY with the shortcut "PVARS"**:
482
+
483
+ You can use these variables also as condition or as normal automagix
484
+ variable in curly brackets by using the shortcut and the attribute notation:
485
+
486
+ - python: PVARS.cond = some_function()
487
+ - PVARS.cond?local: echo 'This is only printed if "some_function" evaluates to "True"'
488
+ - PVARS.cond!?local: echo 'And this is printed if "some_function" evaluates to "False"'
489
+ - local: echo "The condition variable contains the value '{PVARS.cond}'."
490
+
491
+ *Since version 2.4.0 making variables global does not work any longer!*
492
+
493
+ ### Abort and Skip Exceptions
494
+
495
+ To abort the current automagix and jump to the next batch item you can
496
+ raise the `SkipBatchItemException`. For aborting the whole automagix
497
+ process raise `AbortException(return_code: int)`. In both cases the
498
+ cleanup pipeline is executed. Same is the case for selecting
499
+ `a`:abort or `c`:continue when asked (interactive or error).
500
+
501
+ ### Logging / Saving the output
502
+
503
+ **automagix** offers no own capability to log the output to a log file or
504
+ save it otherwise.
505
+
506
+ If you have _GNU screen_ installed, you may start a screen session with
507
+ `-L` and optional `-Logfile LOGFILE` in which you start **automagix**.
508
+ (This is how it works with "parallel processing", see **EXTRAS** section.)
509
+
510
+ A different approach is to use `tee`, e.g. `automagix [script file + options] 2>&1 | tee auto.log`.
511
+ Different to the screen approach this seems not to capture your input.
512
+
513
+ # BEST PRACTISES
514
+
515
+ There are different ways to start scripting with **automagix**. The
516
+ author's approach is mainly to consider the process and simply write
517
+ down, what to do (manual steps for complex or not automated steps)
518
+ and which commands to use.
519
+ Then start **automagix** in interactive mode (-i) and adjust the
520
+ single steps one by one. Replace manual steps, if suitable. Whenever
521
+ adjustment is needed, abort, adjust and restart **automagix** with
522
+ jump (-j) to the adjusted step.
523
+ From **automagix** 1.13.0 on you can use the reload scriptfile feature
524
+ instead. When asked for options (either because a command failed or
525
+ you are in interactive mode) you can use **-R** to reload the
526
+ scriptfile. If lines in the scriptfile have changed, or you need to
527
+ repeat steps, you can use R+/-$number to reload and adjust the
528
+ restart point (available since **automagix** 1.14.0). NOTICE: If using
529
+ vars-file, this reloads the script ONLY the active CSV row!
530
+
531
+ Repeat this procedure to automate more and more and increase quality,
532
+ whenever you feel like it.
533
+
534
+ Consider to put often used paths or code sequences in automagix
535
+ variables for better readability.
536
+ Do the same with variable content like URLs, to make it possible to
537
+ overwrite it by command line options. Where ever possible prefer to
538
+ use functions to determine already available information, such as BW
539
+ metadata, instead of defining things explicitly. This will make
540
+ things easier when using the script with different systems /
541
+ parameters.
542
+
543
+ Preferred way of using **automagix** is to put often used and complex
544
+ algorithms in python libraries and import them. Advantage of this
545
+ approach is that you can use your implemented functions multiple
546
+ times and build up a toolbox of nice functionality over time.
547
+
548
+
549
+ # NOTES
550
+
551
+ **Manual steps** will always cause automagix to stop and wait for
552
+ user input.
553
+
554
+ Be careful with **assignments** containing line breaks (echo, ...).
555
+ Using the variables may lead to unexpected behaviour or errors.
556
+ From version 1.14.0 on trailing new lines in **assignments**
557
+ of Shell commands (_local_, _remote@_) are removed.
558
+
559
+ Assignments containing **null bytes** are currently not supported.
560
+
561
+ Because the **always** pipeline should not change anything, aborting
562
+ while running this pipeline will not trigger a cleanup.
563
+
564
+ If you want to abort the **pipeline** without triggering the
565
+ **cleanup** pipeline, use CRTL+C.
566
+
567
+ While **aborting remote functions** automagix is not
568
+ able to determine still running processes invoked by the function,
569
+ because it only checks the processes for the commands (in this case
570
+ the function name) which is called in the pipeline.
571
+
572
+ User input questions are of following categories:
573
+ - [MS] **M**anual **S**tep
574
+ - [CF] **C**ommand **F**ailed
575
+ - [PF] **P**artial command **F**ailed (BW groups)
576
+ - [RR] **R**emote process still **R**unning
577
+ - [SE] **S**yntax **E**rror
578
+
579
+ The terminal (T) answer starts an interactive Bash-Shell.
580
+ Therefore .bashrc is executed, but the command prompt (PS1) is
581
+ replaced to indicate, that we are still in an automagix process.
582
+
583
+
584
+ # EXTRAS
585
+
586
+ ## Parallel processing
587
+ Requirement: GNU screen installed and accessible via `screen` command in bash.
588
+
589
+ This **automagix** version has the option to process multiple **automagix** instances at a time.
590
+ This is achieved by starting multiple [GNU screen](https://www.gnu.org/software/screen/) sessions.
591
+ Please make yourself comfortable with the screen controls before using this feature to avoid getting lost.
592
+
593
+ The main programm stays in a loop while attaching to the screen sessions and you will come back to it
594
+ if you detach a screen session. The **automagix-manager** runs in its own screen session and is
595
+ responsible for starting the automagix screens and status updates.
596
+
597
+ By default the programm starts with 10 parallel automagix instances. Use the main programm loop controls
598
+ to change the number of allowed parallel sessions (pressing 'm' followed by your desired number).
599
+
600
+ If you force the programm to terminate (e.g. keyboard interrupt, process kill, ...),
601
+ check for still running screen processes via `screen -list`. They are independent and may continue
602
+ running. Cleanup manually, if necessary.
603
+
604
+ The screens write their output to log files in the specified **logfile_dir** (see **CONFIGURATION** section).
605
+ These logfiles contain the escape sequences that are used to provide the colored output an the terminal.
606
+ You can use a pager that supports interpreting these sequences like the terminal to have a similar
607
+ experience (`more` or `less -r` worked for me).
608
+
609
+ ## Bash completion (experimental)
610
+ Automagix supports bash completion for parameters and the script directory via [argcomplete](https://github.com/kislyuk/argcomplete).
611
+
612
+ Therefor follow the installation instructions for argcomplete, which is at the current time
613
+
614
+ pip install argcomplete
615
+
616
+ and either global activation via executing
617
+
618
+ activate-global-python-argcomplete
619
+
620
+ or activation for automagix (e.g. in `.bashrc`)
621
+
622
+ eval "$(register-python-argcomplete automagix)"
623
+
624
+ Automagix will recognize the installed module and offer the completion automatically.
625
+
626
+ ## Progress bar (experimental)
627
+ You can activate an "apt-like" progress bar based on the amount of commands
628
+ by setting the configuration option `progress_bar` to `True` (config file or environment).
629
+
630
+ The status on the right displays `[elapsed time<remaining time, rate]`,
631
+ where rate is percentage/second if fast and second/percentage if slow.
632
+
633
+ Note, that using commands that heavily modify the terminal behaviour/output
634
+ (such as `top`, `watch`, `glances`, ...), may lead to a unreadable
635
+ or undesirable output. It might be a better idea to encourage the user
636
+ to open a separate terminal and type these commands there.
637
+
638
+ Using automagix itself as command should work, but may lead to confusing
639
+ output as well. Note, that the progress bar will be overwritten by the
640
+ new automagix instance for the duration of the automagix command.