Repository navigation
Description
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
[-][BUG] pillarstack opts matching: pillar.items returns nothing[/-][+][BUG] ext_pillar pillarstack opts matching: pillar.items returns nothing[/+]frogunder commentedon Jun 8, 2020
@daks Thanks for reporting this issue.
I am seeing the same thing.
Thanks.
daks commentedon Jun 10, 2020
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.itemsto see the cache is wrong.so using pillar.raw
which is exactly what I want!
Adding debug statements in
stack.pyI can see:saltutil.refresh_pillarthe opts dict in stack.py knows the definedsaltenvpillar.itemsdo not see its value, which is why it returns nothing in this setupdaks commentedon Jun 10, 2020
Looking at the code, it seems that the
items()function insalt/modules/pillar.pytries to use apillarenvand only usessaltenvifpillarenv_from_saltenvis set in master config.To verify it works, I set this value but now I have an error
which is right because no pillarenv has been defined in pillars because I only use ext_pillar. I don't understand why
saltutil.refresh_pillarandpillar.rawworks as expected butpillar.itemshas a different behaviour.daks commentedon Jun 11, 2020
More information:
after adding dev and prod to my
pillar_rootsI got rid of this error message but I still see that when runningpillar.itemsit does not know about the saltenv and by consequence doesn't parse the expected files and returns nothing.frogunder commentedon Jun 11, 2020
@saltstack/team-core Can you take a look at this issue and give some input, please?
Thanks.
daks commentedon Aug 24, 2020
Hello, any news about this issue?
sagetherage commentedon Aug 25, 2020
@daks we are reviewing this today in the Triage Community meeting and will have more details soon. Thanks for the reminder!
5 remaining items
vskubriev commentedon Sep 25, 2020
Sorry. I'am lost. What kind of bug report are you talking about ?
Can you provide a correspond link ?
daks commentedon Sep 27, 2020
@vskubriev this one! see initial bug report #57580 (comment), for me using
pillar:environmentworks well on 2019.2daks commentedon Jan 12, 2022
hello, any news about this bug?
gbunt commentedon Nov 2, 2022
@daks fwiw i've been able to get pillarstack working based on
opts:saltenv, though still seem to have a problem withpillar_rootsnot 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).Note: We just happen to temporarily run a pillarstack for for the dev environment. Without that need,
ext_pillarwould simply look like:The following test pillar data is present:
In both environments the pillar
top.slsrefers to the test pillar:After a refresh_pillar, somehow only the
devpillar data is returned for all minions, regardless of their environment:Pillar data is successfully picked up from pillarstack:
I don't know why that is, given
pillar_rootsis 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.