-
Couldn't load subscription status.
- Fork 94
Description
I'm using reclass and salt for a new configuration management setup and found I needed to do some things with reclass that it didn't yet do so I added in functionality to do the basic inventory querying mentioned in the todo list, to allow references to dicts and lists to be merged and to allow references to be nested. The new code is available at https://github.com/AndrewPickford/reclass/tree/master/reclass
The inventory querying works using a new key type - exports to hold values which other node definitions can read using a $[] query, for example with:
# nodes/node1.yml
exports:
test_one:
name: ${name}
value: 6
test_two: ${dict}
parameters:
name: node1
dict:
a: 1
b: 2
exp_value_test: $[ exports:test_two ]
exp_if_test1: $[ exports:test_one if exports:test_one:value == 7 ]
exp_if_test2: $[ exports:test_one if exports:test_one:name == self:name ]
# nodes/node2.yml
exports:
test_one:
name: ${name}
value: 7
test_two: ${dict}
parameters:
name: node2
dict:
a: 11
b: 22running reclass.py --nodeinfo node1 gives (listing only the exports and parameters):
exports:
test_one:
name: node1
value: 6
test_two:
a: 1
b: 2
parameters:
dict:
a: 1
b: 2
exp_if_test1:
node2:
name: node2
value: 7
exp_if_test2:
node1:
name: node1
value: 6
exp_value_test:
node1:
a: 1
b: 2
node2:
a: 11
b: 22
name: node1Exports defined for a node can be a simple value or a reference to a parameter in the node definition. The
I've also run into a use case for nested references, for example:
# nodes/node1.yml
parameters:
alpha:
one: ${beta:${alpha:two}}
two: a
beta:
a: 99reclass.py --nodeinfo node1 then gives:
parameters:
alpha:
one: 99
two: a
beta:
a: 99The ${beta:${alpha:two}} construct first resolves the ${alpha:two} reference to the value 'a', then resolves the reference ${beta:a} to the value 99
Finally referenced lists or dicts can be merged:
# nodes/test.yml
classes:
- test1
- test2
parameters:
one:
a: 1
b: 2
two:
c: 3
d: 4
three:
e: 5
# classes/test1.yml
parameters:
three: ${one}
# classes/test2.yml
parameters:
three: ${two}running reclass.py --nodeinfo node1 then gives:
parameters:
one:
a: 1
b: 2
three:
a: 1
b: 2
c: 3
d: 4
e: 5
two:
c: 3
d: 4This first sets the parameter three to the value of parameter one (class test1) then merges parameter two into parameter three (class test2) and finally merges the parameter three definition given in the node definition into the final value for parameter three.
The code works but isn't yet production ready. There are some tests to write for the inventory query operations, more informative errors need to be returned in the case of inventory query syntax errors, some documentation added for the new functionality and a couple of brute force kludges need to be finessed away.
My question is then: is this functionality something to put into the reclass main line once the new code is polished up?