salt icon indicating copy to clipboard operation
salt copied to clipboard

Extend Algorithms Into Pillar

Open l2ol33rt opened this issue 14 years ago • 15 comments

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

l2ol33rt avatar Nov 06 '12 16:11 l2ol33rt

Thanks for filing this!We will get this added.

thatch45 avatar Nov 06 '12 16:11 thatch45

updates?

vad avatar Apr 30 '13 14:04 vad

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

thatch45 avatar Apr 30 '13 19:04 thatch45

+1! This would be an awesome feat.

jacobsvante avatar Jun 09 '13 17:06 jacobsvante

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.

johnnoone avatar Jul 08 '13 02:07 johnnoone

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.

inthecloud247 avatar Jul 08 '13 02:07 inthecloud247

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).

qfel avatar Jul 12 '13 15:07 qfel

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

thatch45 avatar Jul 12 '13 20:07 thatch45

Thanks for the update Tom!

l2ol33rt avatar Jul 16 '13 06:07 l2ol33rt

:+1: I would really like this

pkruithof avatar Aug 07 '13 10:08 pkruithof

a very necessary functionality

PinGwynn avatar Aug 27 '13 18:08 PinGwynn

Include does not solve my particular use case. Would love to see an extend so I can combine pillar files simply.

TronPaul avatar Feb 01 '14 16:02 TronPaul

Check my last proposal for this problem https://github.com/saltstack/salt/issues/3991#issuecomment-35486558

johnnoone avatar Feb 19 '14 10:02 johnnoone

:+1: This would be a very much appreciated feature.

JensRantil avatar Apr 11 '14 11:04 JensRantil

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.

stale[bot] avatar Jul 06 '17 23:07 stale[bot]