grains.setval not working

734 views
Skip to first unread message

Mark Shields

unread,
Jun 6, 2013, 9:37:37 AM6/6/13
to salt-...@googlegroups.com
I attempted to set a custom grain with grains.setval, and while the data returned showed it was successfully, a subsequent 'grains.item roles' does not return it:

strongbow files # salt ab04 grains.setval roles ossec-client
ab04:
  roles: ossec-client
strongbow files # salt ab04 grains.item roles               
ab04:
  roles:
      build
      storage
      mysql
      megaraid
      cass
strongbow files # salt ab04 grains.item saltversion         
ab04:
  saltversion: 0.15.3
strongbow files # 

Here's the sys.doc for it:


strongbow files # salt ab04 sys.doc grains.setval           
grains.setval:

    Set a grains value in the grains config file

    CLI Example::

        salt '*' grains.setval key val
    



Can someone replicate this?

David Boucha

unread,
Jun 6, 2013, 12:13:58 PM6/6/13
to salt users list
What version of Salt are you on?  There was an issue where you had to restart the salt-minion service for the new grain to appear. I'm pretty sure that has been fixed in 0.15.3.


--
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.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Dave Boucha  |  Sr. Engineer


5272 South College Drive, Suite 301 | Murray, UT 84123

office 801-305-3563
da...@saltstack.com | www.saltstack.com

Mark Shields

unread,
Jun 6, 2013, 3:10:49 PM6/6/13
to salt-...@googlegroups.com
That was the first thing I did.  As posted in the first post:

strongbow files # salt ab04 grains.item saltversion         
ab04:
  saltversion: 0.15.3


That said, I went back and checked, and it does set it, but not in the place I expected:

ab04 salt # cat /etc/salt/grains                                                                                       │
roles: ossec-client                                                                                                    │
ab04 salt #  

Here's the place I expected it:

/etc/salt/minion.d/grains.conf

I was unaware of /etc/salt/grains.  

Once I removed grains.conf, the grain I set showed up via salt.  I'll be migrating all my grains.conf to the /etc/salt/grains, then.

Mark Shields

unread,
Jun 6, 2013, 3:17:08 PM6/6/13
to salt-...@googlegroups.com
Looks like I spoke too soon for this working for me.

Using grains.setval overrides any existing keys:


strongbow ~ # salt ab04 grains.setval roles build                                                                      
ab04:
  roles: build
strongbow ~ # salt ab04 grains.setval roles cass 
ab04:
  roles: cass
strongbow ~ # 


ab04 salt # grep roles !$
grep roles grains
roles: cass
ab04 salt # 

grains.setval doesn't appear to accept multiple values with one key, either:

# salt ab04 sys.doc grains.setval roles ossec build storage mysql megaraid cass
Traceback (most recent call last):
  File "/usr/bin/salt", line 10, in <module>
    salt_main()
  File "/usr/lib/python2.6/site-packages/salt/scripts.py", line 103, in salt_main
    client.run()
  File "/usr/lib/python2.6/site-packages/salt/cli/__init__.py", line 107, in run
    self._output_ret(ret, out)
  File "/usr/lib/python2.6/site-packages/salt/cli/__init__.py", line 125, in _output_ret
    self._print_docs(ret)
  File "/usr/lib/python2.6/site-packages/salt/cli/__init__.py", line 153, in _print_docs
    if ret[host][fun]:
TypeError: string indices must be integers, not str


Should I file a bug for this?  This doesn't seem like correct behavior, both for overriding current values/not working with multiple values, even those present.

David Boucha

unread,
Jun 6, 2013, 4:22:42 PM6/6/13
to salt users list
Yeah, it should overwrite present values that you're not setting.


--
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.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Badmeischter

unread,
Jun 7, 2013, 3:08:31 AM6/7/13
to salt-...@googlegroups.com
Hi Mark, are you setting the 'roles' grain in your minion config file by any chance? I'm doing the same, set certain values from the CMDB as grains in /etc/minion.d/grains.conf, when setting up a system. I noticed that grains settings in the minion configuration file take precedence over values set from the command line.


Am Donnerstag, 6. Juni 2013 15:37:37 UTC+2 schrieb Mark Shields:
I attempted to set a custom grain with grains.setval, and while the data returned showed it was successfully, a subsequent 'grains.item roles' does not return it:

strongbow files # salt ab04 grains.setval roles ossec-client
ab04:
  roles: ossec-client
strongbow files # salt ab04 grains.item roles               
ab04:
  roles:
      build
      storage
      mysql
      megaraid
      cass

If what you are trying to do did work, you would lose all of these settings. If you want to preserve existing settings and simply add ossec-client to the list of roles try this:

salt ab04 grains.setval roles '["ossec-client", "build", "storage", "mysql", "megaraid", "cass"]'

There might be smarter ways to reuse the existing settings, I'm just to new to salt an python to tell.

Mark Shields

unread,
Jun 7, 2013, 10:03:08 AM6/7/13
to salt-users
I am, using the grains.conf under minion.d:

/etc/salt/minion.d/grains.conf


Looks like I'll need to migrate to /etc/salt/grains.

- Mark Shields


--
You received this message because you are subscribed to a topic in the Google Groups "Salt-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/salt-users/5rPSdt0aJs8/unsubscribe?hl=en-US.
To unsubscribe from this group and all its topics, send an email to salt-users+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages