FAQ
Hi All,

(I noticed a earlier post, but didnt cover this :)

Assume I get a dict returned from my minions. Is there a way to merge such
a data set from different minions on the master?

IP's are found in grains, but for argument sake:

Think of 'salt \* module.get_all_server_IPs' ... and sort/process them
based on segments.

The last part would typically be handled in a central place.

I looked at http://docs.saltstack.com/en/latest/ref/peer.html but that
feels somewhat to decentralized.

Anybody suggestions?

Thanx a lot.

Regards,

Gerard.

--
You received this message because you are subscribed to the Google Groups "Salt-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Daniel Jagszent at Sep 25, 2014 at 8:32 am
    Hello Gerard,

    you want to merge these dicts on the master, right? Then writing a
    runner would be an option for you (
    http://docs.saltstack.com/en/latest/ref/runners/ )

    E.g. save this file in a diirectory on the master that is in the
    runner_dirslist as dict_merge.py

    '''
    Merge some dicts!
    '''

    import logging
    import salt.utils

    log = logging.getLogger(__name__)

    def merge():
       local_client = salt.client.LocalClient(__opts__['conf_file'])
       cmd_response = client.cmd('*', 'module.get_all_server_IPs')
       # cmd_response is a dict with all responses of all minions
       # the minion id is the key of the minion's return value
       if cmd_response:
         merged_dict = {}
         for minion_id in sorted(cmd_response):
           # do your merging, this one is probably not really what you want
           merged_dict.update(cmd_response[minion_id])
         return merged_dict
       else:
         # Call was not successful
         return None


    Then you are abel to run this command on the command line
    $ salt-run dict_merge.merge
    and get your merged dicts.
    Gerard Petersen 25. September 2014 09:22
    Hi All,

    (I noticed a earlier post, but didnt cover this :)

    Assume I get a dict returned from my minions. Is there a way to merge
    such a data set from different minions on the master?

    IP's are found in grains, but for argument sake:

    Think of 'salt \* module.get_all_server_IPs' ... and sort/process them
    based on segments.

    The last part would typically be handled in a central place.

    I looked at http://docs.saltstack.com/en/latest/ref/peer.html but that
    feels somewhat to decentralized.

    Anybody suggestions?

    Thanx a lot.

    Regards,

    Gerard.
    --
    You received this message because you are subscribed to the Google
    Groups "Salt-users" group.
    To unsubscribe from this group and stop receiving emails from it, send
    an email to salt-users+unsubscribe@googlegroups.com
    For more options, visit https://groups.google.com/d/optout.
  • Gerard Petersen at Sep 28, 2014 at 11:15 am
    Dear Daniel,

    Thanx so much for your awesome code snippet. I managed to combine it with
    some commandline trickery involving sort, uniq, awk, etc. But your code was
    my missing link.

    Thanx again!

    Regards,

    Gerard.
    On Thursday, September 25, 2014 10:32:08 AM UTC+2, Daniel Jagszent wrote:

    Hello Gerard,

    you want to merge these dicts on the master, right? Then writing a runner
    would be an option for you (
    http://docs.saltstack.com/en/latest/ref/runners/ )

    E.g. save this file in a diirectory on the master that is in the
    runner_dirs list as dict_merge.py

    '''
    Merge some dicts!
    '''

    import logging
    import salt.utils

    log = logging.getLogger(__name__)

    def merge():
    local_client = salt.client.LocalClient(__opts__['conf_file'])
    cmd_response = client.cmd('*', 'module.get_all_server_IPs')
    # cmd_response is a dict with all responses of all minions
    # the minion id is the key of the minion's return value
    if cmd_response:
    merged_dict = {}
    for minion_id in sorted(cmd_response):
    # do your merging, this one is probably not really what you want
    merged_dict.update(cmd_response[minion_id])
    return merged_dict
    else:
    # Call was not successful
    return None


    Then you are abel to run this command on the command line
    $ salt-run dict_merge.merge
    and get your merged dicts.

    Gerard Petersen <javascript:>
    25. September 2014 09:22
    Hi All,

    (I noticed a earlier post, but didnt cover this :)

    Assume I get a dict returned from my minions. Is there a way to merge such
    a data set from different minions on the master?

    IP's are found in grains, but for argument sake:

    Think of 'salt \* module.get_all_server_IPs' ... and sort/process them
    based on segments.

    The last part would typically be handled in a central place.

    I looked at http://docs.saltstack.com/en/latest/ref/peer.html but that
    feels somewhat to decentralized.

    Anybody suggestions?

    Thanx a lot.

    Regards,

    Gerard.
    --
    You received this message because you are subscribed to the Google Groups
    "Salt-users" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to salt-users+...@googlegroups.com <javascript:>.
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups "Salt-users" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupsalt-users @
postedSep 25, '14 at 7:22a
activeSep 28, '14 at 11:15a
posts3
users2

People

Translate

site design / logo © 2022 Grokbase