Commit graph

35 commits

Author SHA1 Message Date
0001c775d6
Set available variables before evaluating the condition 2022-10-07 15:21:41 +02:00
3ff7ab51eb
Don't crash if repr()/dump() are used before parse() 2022-10-01 12:03:29 +02:00
28f1d3308a
Refactored main parse method 2022-09-18 17:57:21 +02:00
4a56566c58
Use pre-commit with black + yamllint
* Added pre-commit config
  * Added yamllint config
  * Updated example YAML files to match the yamllint config
  * black'd existing Python code
2022-09-18 17:32:23 +02:00
f42df48a1b Don't reset the cache on pop if no deletion occurs
When the stack is being pop'd, it is not necessary to reset it if no
variable is either reset to its previous value or deleted.
2022-09-18 12:12:59 +02:00
91a90def13 Use copy.copy() instead of the copy() method, which might not exist 2022-09-18 11:51:06 +02:00
14ea834823 Fixed MutableMapping import source 2022-09-18 10:33:00 +02:00
47a2704164 locals clause removed from block instruction 2022-09-18 10:13:51 +02:00
fcdfe9241d Vars added to debugging output 2022-09-18 10:13:37 +02:00
f2d1e2da50 Implemented vars clause
* Can be used on any instruction
  * Variables are evaluated before condition is checked
2022-09-18 10:06:19 +02:00
2fd5ba9bb4 Sorted instruction definitions 2022-09-18 09:45:38 +02:00
446280ab6e run_once clause
When the run_once clause is present and set to a truthy value, the
instruction it is attached to will only be executed the first time it is
encountered.
2022-09-17 12:22:40 +02:00
14fca45cb7 Refactoring - run_once() renamed to run_iteration() 2022-09-17 12:06:21 +02:00
6b58f873a9 More code documentation 2022-09-17 12:01:06 +02:00
285cf74195 Code documentation - Variable cache 2022-09-17 10:51:35 +02:00
0f03f5d539 Don't reset the variable cache if nothing changes on pop() 2022-09-17 10:47:45 +02:00
6ca723c74e Doc update regarding variables' behavior 2022-09-17 10:30:37 +02:00
9c4cc09021 Copy variables when storing them on the stack 2022-09-17 10:21:06 +02:00
0519be9316 Changed how variables work again
Script variables are not longer saved before entering a block. Only
variables declared as locals and loop variables are saved. This allows a
block to use `set_var` to change a variable.
2022-09-17 10:10:18 +02:00
46e675dedb Cleaner implementation of the variable cache
* Separate implementation that acts as a MutableMapping
  * I'm still not sure about this. Also, there is a design error in
    there, because it's not possible to "return" a value from a block
    unless it's written to a fact.
2022-09-07 21:24:07 +02:00
b79e9f8faf Some comments 2022-09-04 23:44:02 +02:00
cbe1bd65bf loop - Always process the value using the templar
* When the loop value is a list, its items may be templates or
    structures which contain templates. Because of that, they need to go
    through the templar.
2022-09-04 23:37:01 +02:00
91ff8296d6 More cache/loop fixes
* When the loop variable state is restored, the cache must also be
    modified.
  * What needs to be done depends on whether a host fact by the same
    name also exist.
  * Fuck that cache thing. It's going away next time I can hack on this.
2022-09-04 23:20:26 +02:00
57bf02e79d Variable cache - Reset after block execution
* When a block is done executing, local variables must be restored to
    their previous values ; however, host variables may have been
    updated inside the block. Therefore it is necessary to reset the
    variable cache.
2022-09-04 23:16:56 +02:00
d1d997f7ae Actually use the variable cache
* The merged (host+local) variable cache should not be reset at each
    instruction.
2022-09-04 23:14:01 +02:00
7e5eb8e414 Fixed caching problem in set_fact
* Since facts have a lower priority than local variables, set_fact
    should only update the cache if no local variable uses the same
    name
2022-09-04 23:00:15 +02:00
a5b1ac5c4c Better loop variable state handling
* Loops caused local scripts variables to be backed up then restored,
    which would have caused a set_var in a loop to have no effect.
  * Instead, we back up the state of the variable (existing or not,
    value) and either restore the original value or delete the variable
    if it didn't exist.
2022-09-04 22:54:03 +02:00
1b1c1281a2 Use abc for the instruction class and its abstract methods 2022-09-04 22:44:06 +02:00
c587f1479c Fixed weird indentation 2022-09-04 12:21:09 +02:00
36477385a1 Changed the long debugging output for loop/when 2022-09-04 12:20:49 +02:00
cc439110ae Remove allowed field names from instruction data
* It's pointless to have a distinct set of allowed fields for each
    instruction in the program
2022-09-04 11:50:42 +02:00
5ef2ffc55c Debugging support
* Support for dumping parsed programs as strings (both a basic,
    repr-like version and an indented version that is easier to read)
  * Display the parsed program if verbosity is high enough
  * Program tracing if verbosity is high enough
2022-09-04 11:35:07 +02:00
7b44cdc731 create_group - add_host and parent options
* The `add_host` option can be used to add the current host to the
    group being created. It avoids having to use a separate `add_host`
    instruction in this case.
  * The `parent` option can specify the parent group. It avoids having
    to use a separate `add_child` instruction in this case.
2022-09-03 10:43:01 +02:00
5f719d7ab8 "block" instruction implemented
The "block" instruction allows mulitple instructions to be grouped in
order to be executed based on a single condition, in a common loop, with
a local variable scope. In addition, it provides a way to recover from
errors.
2022-09-02 20:26:36 +02:00
17aa8e8c46 Initial import of the WIP plugin 2022-09-02 18:00:22 +02:00