Skip to content

[BUG] ext_pillar pillarstack opts matching: pillar.items returns nothing #57580

Open

Description

@daks

Looking at documentation for pillarstack ext_pillar https://docs.saltstack.com/en/latest/ref/pillar/all/salt.pillar.stack.html it should be possible to define stack config files depending of grains, pillar or opts, like in the example

ext_pillar:
  - stack:
      pillar:environment:
        dev: /path/to/dev/stack.cfg
        prod: /path/to/prod/stack.cfg
      grains:custom:grain:
        value:
          - /path/to/stack1.cfg
          - /path/to/stack2.cfg
      opts:custom:opt:
        value: /path/to/stack0.cfg

I tried pillar matching and it works but opts don't.

Here is one basic pillarstack setup that works. Minion has a 'saltenv' setting (it will be used later).
Pillarstack is configured to simply read all yml files in dev or prod directory and only set a corresponding env pillar.

### salt-master config file
ext_pillar:
  - stack:
      - /srv/pillar/dev/base.cfg

### salt-minion config file
saltenv: prod

### pillar directory
/srv/pillar$ tree .
.
├── dev
│   ├── base.cfg
│   └── env.yml
└── prod
    ├── base.cfg
    └── env.yml

### files content
$ cat */base.cfg
*.yml

$ cat */*.yml
---
env: dev
---
env: prod

Results of commands

$ salt 'minion1' config.get saltenv
minion1:
    prod

$ salt 'minion1' pillar.items
minion1:
    ----------
    env:
        dev

config.get returns the __opts__ salt dictionary which contains saltenv.
Now we change pillarstack config to match on this opts saltenv value:

ext_pillar:
  - stack:
      opts:saltenv:
        dev: /srv/pillar/dev/base.cfg
        prod: /srv/pillar/prod/base.cfg
$ salt 'minion1' config.get saltenv
minion1:
    prod

$ salt 'minion1' pillar.items
minion1:
    ----------

As you can see, the saltenv is set and pillar.items returns nothing.
What's weird is that:

$ salt 'minion1' pillar.get env
minion1:
    prod

A specific pillar.get correctly returns the expected value!

Adding some awful log.debug() inside salt/pillar/stack.py I see that it parses the right /srv/pillar/{dev,prod}/base.cfg and *.yml files depending of the saltenv setting

I don't really understand where this bug can be, from inside or outside stack.py (pillarstack) but it seems the module does the job correctly, reading the right files and filling pillar data... but... still pillar.items returns nothing.

Master and minion on version 2019.2.5+ds-1, running on Debian 9.

Activity

  1. added
    bug
    on Jun 8, 2020
  2. changed the title [-][BUG] pillarstack opts matching: pillar.items returns nothing[/-] [+][BUG] ext_pillar pillarstack opts matching: pillar.items returns nothing[/+] on Jun 8, 2020
  3. frogunder commented on Jun 8, 2020

    @frogunder
    Contributor

    @daks Thanks for reporting this issue.

    I am seeing the same thing.

    Thanks.

  4. added this to the Approved milestone on Jun 8, 2020
  5. added
    severity-high
    on Jun 8, 2020
  6. daks commented on Jun 10, 2020

    @daks
    ContributorAuthor

    OK, reading this doc https://docs.saltstack.com/en/latest/topics/pillar/#in-memory-pillar-data-vs-on-demand-pillar-data I understand that using pillar.items to see the cache is wrong.

    so using pillar.raw

    $ salt 'minion1' pillar.raw
    minion1:
        ----------
        env:
            prod
    

    which is exactly what I want!

    Adding debug statements in stack.py I can see:

    • that when running saltutil.refresh_pillar the opts dict in stack.py knows the defined saltenv
    • but pillar.items do not see its value, which is why it returns nothing in this setup
  7. daks commented on Jun 10, 2020

    @daks
    ContributorAuthor

    Looking at the code, it seems that the items() function in salt/modules/pillar.py tries to use a pillarenv and only uses saltenv if pillarenv_from_saltenv is set in master config.
    To verify it works, I set this value but now I have an error

    2020-06-10 17:00:19,680 [salt.pillar      :521 ][DEBUG   ][6478] pillarenv 'prod' not found in the configured pillar environments (base)
    

    which is right because no pillarenv has been defined in pillars because I only use ext_pillar. I don't understand why saltutil.refresh_pillar and pillar.raw works as expected but pillar.items has a different behaviour.

  8. daks commented on Jun 11, 2020

    @daks
    ContributorAuthor

    More information:

    after adding dev and prod to my pillar_roots I got rid of this error message but I still see that when running pillar.items it does not know about the saltenv and by consequence doesn't parse the expected files and returns nothing.

  9. frogunder commented on Jun 11, 2020

    @frogunder
    Contributor

    @saltstack/team-core Can you take a look at this issue and give some input, please?

    Thanks.

  10. added
    Magnesium
    on Jun 15, 2020
  11. daks commented on Aug 24, 2020

    @daks
    ContributorAuthor

    Hello, any news about this issue?

  12. sagetherage commented on Aug 25, 2020

    @sagetherage
    Contributor

    @daks we are reviewing this today in the Triage Community meeting and will have more details soon. Thanks for the reminder!

  13. 5 remaining items

  14. vskubriev commented on Sep 25, 2020

    @vskubriev

    I suspect that pillar:environment: doesn't work for the same reason. While simple declaration works as expected. I mean the case with example from doc:

    ext_pillar:
      - stack:
          pillar:environment:
            dev: /path/to/dev/stack.cfg
            prod: /path/to/prod/stack.cfg
    

    In my previous tests using pillar:environment worked fine. (see initial bug report). Was tested on 2019.2 not on recent versions

    Sorry. I'am lost. What kind of bug report are you talking about ?
    Can you provide a correspond link ?

  15. daks commented on Sep 27, 2020

    @daks
    ContributorAuthor

    @vskubriev this one! see initial bug report #57580 (comment), for me using pillar:environment works well on 2019.2

  16. removed
    Magnesium
    on Sep 29, 2020
  17. added
    Phosphorus v3005.0
    on Jun 18, 2021
  18. daks commented on Jan 12, 2022

    @daks
    ContributorAuthor

    hello, any news about this bug?

  19. removed
    Phosphorus v3005.0
    on Mar 30, 2022
  20. gbunt commented on Nov 2, 2022

    @gbunt

    @daks fwiw i've been able to get pillarstack working based on opts:saltenv, though still seem to have a problem with pillar_roots not being picked up properly. This test was a mixed environment where master and it's local minion are on v3002.2 (env: production) and 2 other minions still run v2019.2.5 (env: dev).

    • master pillar config:
    pillar_roots:
      production:
        - /srv/salt/prod/pillar
      dev:
        - /srv/salt/dev/pillar
        
    ext_pillar:
      - stack:
          opts:saltenv:
            production:
              - /srv/salt/prod/pillar/stack/pillarstack.cfg
              - /srv/salt/prod/pillar/stack/classstack.cfg
      - stack_fork:
          opts:saltenv:
            dev:
              - /srv/salt/dev/pillar/stack/pillarstack.cfg
              - /srv/salt/dev/pillar/stack/classstack.cfg
    

    Note: We just happen to temporarily run a pillarstack for for the dev environment. Without that need, ext_pillar would simply look like:

    ext_pillar:
      - stack:
          opts:saltenv:
            production:
              - /srv/salt/prod/pillar/stack/pillarstack.cfg
              - /srv/salt/prod/pillar/stack/classstack.cfg
            dev:
              - /srv/salt/dev/pillar/stack/pillarstack.cfg
              - /srv/salt/dev/pillar/stack/classstack.cfg
    
    • minion config production environment:
    saltenv: production
    lock_saltenv: True
    state_top_saltenv: production
    pillarenv_from_saltenv: True
    
    • minion config dev environment:
    saltenv: dev
    lock_saltenv: True
    state_top_saltenv: dev
    pillarenv_from_saltenv: True
    
    $ salt '*' config.get saltenv
    0611d599-d9aa-42db-94e5-a51da1011eaf:
        dev
    6cd6afb6-0759-403e-9dee-a3db09cfea10:
        dev
    c2966744-eb31-461e-8baf-8b9208f5eadf:
        production
    

    The following test pillar data is present:

    # /srv/salt/prod/pillar/test/init.sls:
    test:
      env: production
      
    # /srv/salt/dev/pillar/test/init.sls:
    test:
      env: dev
    

    In both environments the pillar top.sls refers to the test pillar:

    production:
      '*':
        - test
    
    dev:
      '*':
        - test
    

    After a refresh_pillar, somehow only the dev pillar data is returned for all minions, regardless of their environment:

    $ salt '*' pillar.items test:env
    c2966744-eb31-461e-8baf-8b9208f5eadf:
        ----------
        test:env:
            dev
    6cd6afb6-0759-403e-9dee-a3db09cfea10:
        ----------
        test:env:
            dev
    0611d599-d9aa-42db-94e5-a51da1011eaf:
        ----------
        test:env:
            dev
    
    • Adding pillarstack test data:
    # /srv/salt/prod/pillar/stack/defaults/test.yml:
    test:
      pillarstack:
        env: production
    
    # /srv/salt/dev/pillar/stack/defaults/test.yml:
    test:
      pillarstack:
        env: dev
    

    Pillar data is successfully picked up from pillarstack:

    $ salt '*' pillar.items test
    6cd6afb6-0759-403e-9dee-a3db09cfea10:
        ----------
        test:
            ----------
            env:
                dev
            pillarstack:
                ----------
                env:
                    dev
    c2966744-eb31-461e-8baf-8b9208f5eadf:
        ----------
        test:
            ----------
            env:
                dev
            pillarstack:
                ----------
                env:
                    production
    0611d599-d9aa-42db-94e5-a51da1011eaf:
        ----------
        test:
            ----------
            env:
                dev
            pillarstack:
                ----------
                env:
                    dev
    

    I don't know why that is, given pillar_roots is correctly configured for each environment. One thing i noticed, is that it seems the first environment in alphabetical order seems to be picked when i rename the environments.
    Haven't tested v3005.1 yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Pillarbugseverity-high

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions