FAQ
Hi,

I have a grains key contains a list of values:

# salt *test_vm* grains.get roles
test_vm_0:
     - openstack_vm
     - test_server

The following code got rendering syntax error, it cannot handle the
list of values "- TypeError: unhashable type: 'list'"


{% set test_config = salt['grains.filter_by']({
     ['- openstack_vm', '- test_server'] : {
        'config_source' = 'salt://config/config.sh'
   },
}, grain='roles') %}

What is the workaround to fix it?

Thank you.

  - j

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

  • Seth House at Aug 17, 2014 at 5:13 pm

    On Sat, Aug 16, 2014 at 4:58 AM, jupiter wrote:
    I have a grains key contains a list of values:
    What is the workaround to fix it?
    grains.filter_by doesn't support passing a list. It's an interesting
    use-case. Please do file an issue to add support.

    There is a match.filter_by function that could be used for this to
    match roles on the current machine. It is in the next version of Salt
    (currently in RC), though I expect it would back-port cleanly to the
    current version. It uses Salt's compound command syntax and would be
    used like this:

    {% set test_config = salt['match.filter_by']({
         'G@roles:openstack_vm and G@roles:test_server': {
            'config_source' = 'salt://config/config.sh'
       },
    }) %}

    https://github.com/saltstack/salt/blob/23fbd41/salt/modules/match.py#L293

    --
    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.
  • Nobody at Aug 18, 2014 at 11:47 am
    Hmm, all my minions are installed centos 6.5 system salt package which does
    not support that feature. Anyway, I've filed the issue #15061.

    By the way, can grains.filter_by support regex filtering? If that works, I
    can make a new grains vm_type for a workaround.

    {% set test_config = salt['grains.filter_by']({
         '*openstack_vm*test_server*' : {
       'config_source' = 'salt://config/config.sh'
       },
    }, grain='vm_type') %}

    Thanks for the response, much appreciate it.

    - j


    On Monday, August 18, 2014 3:13:06 AM UTC+10, Seth House wrote:

    On Sat, Aug 16, 2014 at 4:58 AM, jupiter <jupit...@gmail.com <javascript:>>
    wrote:
    I have a grains key contains a list of values:
    What is the workaround to fix it?
    grains.filter_by doesn't support passing a list. It's an interesting
    use-case. Please do file an issue to add support.

    There is a match.filter_by function that could be used for this to
    match roles on the current machine. It is in the next version of Salt
    (currently in RC), though I expect it would back-port cleanly to the
    current version. It uses Salt's compound command syntax and would be
    used like this:

    {% set test_config = salt['match.filter_by']({
    'G@roles:openstack_vm and G@roles:test_server': {
    'config_source' = 'salt://config/config.sh'
    },
    }) %}

    https://github.com/saltstack/salt/blob/23fbd41/salt/modules/match.py#L293
    --
    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.
  • Seth House at Aug 18, 2014 at 4:01 pm
    Thanks for filing that issue.
    On Mon, Aug 18, 2014 at 5:47 AM, nobody wrote:
    By the way, can grains.filter_by support regex filtering?
    No. The current behavior is just to do a plain dictionary lookup for a
    key. A quick workaround for you could be to whip up your own custom
    module. You could use the ``grains.filter_by`` as a starting point or
    go the route of doing a regex match. There is a half-example here:

    https://groups.google.com/d/msg/salt-users/klSf3MO8ruA/zOkFV8Or0ysJ

    --
    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.
  • Vishal Biyani at Mar 21, 2016 at 10:03 am
    I am a bit late to the party but I faced a similar situation. Thankfully I
    could get a workaround that was good enough for me:

    {% set role_filter = salt['grains.filter_by']({
         'some_role': { 'role_key': 'role_value' },
         'default': { 'some_key': 'some_value'},
    },
    *grain='roles:0',*
    default='default',

    Notice the *roles:0* used to match against first in roles list

    Thanks
    -Vishal
    On Monday, 18 August 2014 17:17:41 UTC+5:30, nobody wrote:

    Hmm, all my minions are installed centos 6.5 system salt package which
    does not support that feature. Anyway, I've filed the issue #15061.

    By the way, can grains.filter_by support regex filtering? If that works,
    I can make a new grains vm_type for a workaround.
    --
    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 @
postedAug 16, '14 at 10:58a
activeMar 21, '16 at 10:03a
posts5
users3

People

Translate

site design / logo © 2022 Grokbase