Skip to content

Extend Algorithms Into Pillar #2466

Closed
Closed

Description

@l2ol33rt

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

Activity

  1. thatch45 commented on Nov 6, 2012

    @thatch45
    Contributor

    Thanks for filing this!We will get this added.

  2. vad commented on Apr 30, 2013

    @vad

    updates?

  3. thatch45 commented on Apr 30, 2013

    @thatch45
    Contributor

    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

  4. jacobsvante commented on Jun 9, 2013

    @jacobsvante
    Contributor

    +1! This would be an awesome feat.

  5. johnnoone commented on Jul 8, 2013

    @johnnoone
    Contributor

    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.

  6. inthecloud247 commented on Jul 8, 2013

    @inthecloud247
    Contributor

    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.

  7. qfel commented on Jul 12, 2013

    @qfel

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

  8. thatch45 commented on Jul 12, 2013

    @thatch45
    Contributor

    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

  9. l2ol33rt commented on Jul 16, 2013

    @l2ol33rt
    ContributorAuthor

    Thanks for the update Tom!

  10. pkruithof commented on Aug 7, 2013

    @pkruithof
    Contributor

    👍 I would really like this

  11. PinGwynn commented on Aug 27, 2013

    @PinGwynn

    a very necessary functionality

  12. TronPaul commented on Feb 1, 2014

    @TronPaul
    Contributor

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

  13. johnnoone commented on Feb 19, 2014

    @johnnoone
    Contributor

    Check my last proposal for this problem #3991 (comment)

  14. JensRantil commented on Apr 11, 2014

    @JensRantil
    Contributor

    👍 This would be a very much appreciated feature.

  15. stale commented on Jul 6, 2017

    @stale

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Featurestale

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions