Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pillar.get in stack.cfg does not get nested values #52

Open
giorgiozeeman opened this issue Nov 7, 2018 · 3 comments
Open

pillar.get in stack.cfg does not get nested values #52

giorgiozeeman opened this issue Nov 7, 2018 · 3 comments

Comments

@giorgiozeeman
Copy link

giorgiozeeman commented Nov 7, 2018

Hello,

we are successfully using PillarStack with GitStack-Pillar.

However, we noticed that the pillar.get function in the PillarStack configuration file (stack.cfg), seems unable to retrieve nested items and it falls back to the default value.

We would like to use this function to be able to set a default value in case the nested variable is not defined.

The nested value actually exists in the pillar dictionary.

[saltmaster ~]# salt host.dev.acme.net pillar.item ssl_certs:cert_names
host.dev.acme.net:
    ----------
    ssl_certs:cert_names:
        - star_dev_acme_net

The pillar function works...

pillar['ssl_certs']['cert_names']  

pillar.ssl_certs.cert_names       

However the pillar.get function is unable to get the nested item and it always falls back to the default star_acme_net.

pillar.get('ssl_certs:cert_names', ['star_acme_net']) 

This is an excerpt of our /etc/salt/master

ext_pillar:
  - git:
    - __env__ https://bitbucket.acme.net/scm/salt/pillar.git
  - gitstack:
    - __env__ https://bitbucket.acme.net/scm/salt/pillar.git:
      - stack:
        - stack.cfg

This is the output of salt --versions

Salt Version:
           Salt: 2018.3.3

Dependency Versions:
           cffi: 1.6.0
       cherrypy: unknown
       dateutil: 1.5
      docker-py: Not Installed
          gitdb: 0.6.4
      gitpython: 1.0.1
          ioflo: Not Installed
         Jinja2: 2.7.2
        libgit2: 0.26.3
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.5.6
   mysql-python: Not Installed
      pycparser: 2.14
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: 0.26.4
         Python: 2.7.5 (default, Jul 13 2018, 13:06:57)
   python-gnupg: Not Installed
         PyYAML: 3.11
          PyZMQ: 15.3.0
           RAET: Not Installed
          smmap: 0.9.0
        timelib: Not Installed
        Tornado: 4.2.1
            ZMQ: 4.1.4

System Versions:
           dist: centos 7.5.1804 Core
         locale: UTF-8
        machine: x86_64
        release: 3.10.0-862.14.4.el7.x86_64
         system: Linux
        version: CentOS Linux 7.5.1804 Core

Thanks!

@b-a-t
Copy link

b-a-t commented Jan 22, 2019

I've faced with the same problem and the official answer is that pillar.get is a pure dict pillar method get, which has no idea of the nested hierarchy and complex keys. Contrary to that salt['pillar.get'] module function has knowledge about the nested keys and should work in such situation.

The only problem is that in the Stack config file salt is undefined and __salt__['pillar.get']('ssl_certs:cert_names', []) doesn't return given certificate names either....

See also: https://github.com/saltstack/salt/pull/7896/files

@bbinet
Copy link
Owner

bbinet commented Jan 23, 2019

This is not documented yet, but you can use the __stack__['traverse'] function as described in a previous comment: #13 (comment)
If this works for you, feel free to submit a pull request to add this feature to the readme.

@gbunt
Copy link

gbunt commented Jan 28, 2020

Haven't been able to get nested keys directly working either but this seems to works for me:

{%- set node = pillar.get('node') %}
regions/{{ node.region }}.yml

where node is defined in a stack config loaded before the one containing the above example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants