Extend Algorithms Into Pillar
Add extend algorithm into pillar system.
--- top.sls ---
base:
'saltminiontest1*':
- base_users.sls
'saltminiontest2*':
- ext_users.sls
--- base_users.sls ---
users:
user1:
uid: 503
shell: /bin/bash
home: /home/user1
user2:
fullname: User 2
uid: 504
shell: /bin/bash
home: /home/user2
--- ext_users.sls ---
include:
- base_users
extend:
users:
user3:
fullname: User 3
uid: 505
shell: /bin/bash
home: /home/user3
Thanks for filing this!We will get this added.
updates?
There is acctually a closed pull req from about a year ago that does this that I did not merge at the time which I am not regrettign not merging. But I have been unable to find it to see how they pulled it off for re-evaluation
+1! This would be an awesome feat.
Hi. I am currently working on introducing a new option overlap into pillar inclusion system. The idea behind is that sometimes we need to aggregate datas over SLS files in order to reuse them in jinja loops. Or replace them, etc.
the development is available here https://github.com/johnnoone/salt/tree/pillar-extended
Here the specs:
overlap accepts 3 values :
- update: this is the default, included keys overlap top keys
- merge: top keys overlap included keys
- extend: every overlapping keys will be merged if they are list or dict. Otherwise an error will be raised (in order to avoid messy pillar definitions).
Consider this example.
# users.sls
john:
age: 21
location: Seattle
roberto:
age: 42
location: São Paulo
skills:
- cooking
- driving
# top.sls
include:
- users:
overlap: {{ STRATEGY }}
john:
age: 23
eyes: brown
daniel:
eyes: blue
skills:
- leadership
When {{ STRATEGY }} is merge
john:
age: 23
eyes: brown
daniel:
eyes: blue
roberto:
age: 42
location: São Paulo
skills:
- leadership
When {{ STRATEGY }} is update
john:
age: 21
location: Seattle
daniel:
eyes: blue
roberto:
age: 42
location: São Paulo
skills:
- cooking
- driving
When {{ STRATEGY }} is extend
john:
age: 23
eyes: brown
location: Seattle
daniel:
eyes: blue
roberto:
age: 42
location: São Paulo
skills:
- cooking
- driving
- leadership
Any suggestion are welcome.
Sounds really cool. I'm not sure that the merge and update examples you gave are entirely clear. I would expect a merge to include all keys, and if there are duplicates it will turn the key value into a list. And for update it would combine the keys but eliminate duplicates by assigning the newest value where there is a conflict. Looks like a cool idea! Excited to see this progress.
Slightly different approach to the problem:
I'm currently just using a custom renderer:
- all my pillar SLS are lists of dicts instead of dicts
- just JINJA-include base SLS files
SLS files referenced from top.sls use
#!jinja|yaml|merge
Where merge expects a list of dicts and produces a dict. So a file like
#!jinja|yaml|merge
- a: 1
b: 2
- a: 3
renders to
{"a": 3, "b": 2}
Works quite well in practice and is very customizable (you can choose the strategy depending on the suffix of a key name).
We recently had some updates to the include statement sta might solve this, since they allow for things to be included at the right times, lemme look up the pull that added it
Thanks for the update Tom!
:+1: I would really like this
a very necessary functionality
Include does not solve my particular use case. Would love to see an extend so I can combine pillar files simply.
Check my last proposal for this problem https://github.com/saltstack/salt/issues/3991#issuecomment-35486558
:+1: This would be a very much appreciated feature.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.