Salt: Custom Grains not updating/persisting

Created on 22 Aug 2017  路  5Comments  路  Source: saltstack/salt

Description of Issue/Question

Custom grains are not being recognized/persisting. We made a custom salt grain in the minion config ('/opt/local/etc/salt/minion') and performed saltutil.sync_grains which caused the grain to be updated but when we do run using cmd.run (which defaults to 'shell: /bin/sh'). It still performs our commands in /sh instead of /bash as we tried to set it.

Steps to Reproduce

  • edited Solaris 10u8 (2016.11.6) minion's config file to set custom
    grains: shell: /bin/bash
  • restarted minion with:
    Salt Master CLI entry --> salt 'target' minion.restart
    OR
    from minion './salt-minion -d' which reads 'salt minion shutdown' and then run again to start it up (verify if this is a correct alternative?)
  • ran 'salt 'target' grains.item shell' and it still reads /bin/sh.

Is there a more definitive procedure to add a custom grain to define shell usage?

Bonus inquiry: how to have cmd.run calls in a state/sls file to use the same instance of a bash terminal?
Is the following a legitimate process to achieve the same instance for each cmd.run call? --->
install_software: cmd.run: - names: -'. /h/scripts/my_script_that_sets_env_vars.sh' -'/h/scripts/service stop' -'sleep 30' -'/var/tmp/software/installation.bin' - cwd: '/h'


Versions Report

Salt-master: CentOS 7
Salt Version:

  • Salt: 2016.11.6

Dependency Versions:

  • cffi: 0.8.6
  • cherrypy: Not Installed
  • dateutil: 1.5
  • gitdb: Not Installed
  • gitpython: Not Installed
  • ioflo: Not Installed
  • Jinja2: 2.8
  • libgit2: Not Installed
  • libnacl: Not Installed
  • M2Crypto: Not Installed
  • Mako: 0.8.1
  • msgpack-pure: Not Installed
  • msgpack-python: 0.4.6
  • mysql-python: Not Installed
  • pycparser: 2.14
  • pycrypto: 2.6.1
  • pygit2: Not Installed
  • Python: 2.7.5 (default, )
  • python-gnupg: Not Installed
  • PyYAML: 3.11
  • PyZMQ: 15.3.0
  • RAET: Not Installed
  • smmap: Not Installed
  • timelib: Not Installed
  • Tornado: 4.2.1
  • ZMQ: 4.1.4

System Versions:

  • dist: centos 7.2.1511 Core
  • machine: x86_64
  • release:
  • system: Linux
  • version: CentOS Linux 7.2.1511 Core

Salt-minion: Solaris 10
Salt Version:

  • Salt: 2016.11.6

Dependency Versions:

  • cffi: 1.9.1
  • cherrypy: Not Installed
  • dateutil: 2.6.0
  • gitdb: 0.6.4
  • gitpython: 0.3.2 RC1
  • ioflo: 1.6.6
  • Jinja2: 2.8
  • libgit2: Not Installed
  • libnacl: 1.5.0
  • M2Crypto: 0.25.1
  • Mako: 1.0.6
  • msgpack-pure: Not Installed
  • msgpack-python: 0.4.8
  • mysql-python: Not Installed
  • pycparser: 2.17
  • pycrypto: 2.6.1
  • pygit2: Not Installed
  • Python: 2.7.12 (default, )
  • python-gnupg: 2.0.2
  • PyYAML: 3.12
  • PyZMQ: 16.0.2
  • RAET: 0.6.5
  • smmap: 0.9.0
  • timelib: Not Installed
  • Tornado: 4.4.2
  • ZMQ: 4.0.7

System Versions:

  • dist:
  • machine:
  • release:
  • system: SunOS
  • version: Not Installed
info-needed

Most helpful comment

Are you doing Grains or grains? the correct key is grains.

Also, you can just put shell: /bin/bash in /etc/salt/grains, and then the minion doesn't have to be restarted to load the grains, you just have to call saltutil.refresh_grains

All 5 comments

Are you doing Grains or grains? the correct key is grains.

Also, you can just put shell: /bin/bash in /etc/salt/grains, and then the minion doesn't have to be restarted to load the grains, you just have to call saltutil.refresh_grains

'grains', I changed the post to reflect proper capitalization.

Would that shell: /bin/bash be within a config file in /etc/salt/grains? Can you flesh out that method of defining grains?

Also, for my additional question, do you have a thought on it?

Thank you!

/etc/salt/grains is just a yaml formatted file that gets converted to a dictionary and added to the grains dictionary.

so

/etc/salt/grains

shell: /bin/bash

Should work.
Daniel

You can also use the grains.set module and it will put it in the /etc/salt/grains file.

https://docs.saltstack.com/en/latest/ref/modules/all/salt.modules.grains.html#salt.modules.grains.set

salt 'minionid' grains.set shell /bin/bash

Thank you for the information! I hadn't used saltutil.refresh_grains and that was why it was not reflected in the minion's salt 'target' grains.items listing.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lhost picture lhost  路  3Comments

Oloremo picture Oloremo  路  3Comments

saurabhnemade picture saurabhnemade  路  3Comments

sfozz picture sfozz  路  3Comments

mooperd picture mooperd  路  3Comments