Hi,
I am using SaltStack with multiple environment definitions, and wanted to know if/how mine functions interact with environments.
I am trying to use a single master that works with multiple environments. I wanted the machines to be split into different groups based on their defined enviroment (currently just using lists of the machine names).
I have the basic setup working ok.
My setup is:
/etc/salt/master
file_roots:
base:
- /vagrant/env/base/state
demo:
- /vagrant/env/demo/state
prod:
- /vagrant/env/prod/state
pillar_roots:
base:
- /vagrant/env/base/pillar
demo:
- /vagrant/env/demo/pillar
prod:
- /vagrant/env/prod/pillar
Pillar data defines configuration that is specific to each environment.
/vagrant/env/base/pillar/top.sls
base:
'*':
- match: glob
- config
demo:
'slave1':
- match: list
- config
prod:
'slave2,slave3':
- match: list
- config
This seems to be doing what I expect and allows different config to be defined per environment.
Where I have the problem is when a state file uses mine functions to query for machines. I was hoping that the machines would be divided by environment.
With a state file that queries a mine, the mine returns all machines, not just those matching the environment.
example.sls
{% set p = salt['pillar.get']('stuff', {}) %}
{%- set value = p.get('value', 'default-value') %}
{%- set force_mine_update = salt['mine.send']('network.get_hostname') %}
{%- set host_dict = salt['mine.get']('*', 'network.get_hostname', 'glob') %}
{%- set host_list = host_dict.values() %}
{%- set hosts = host_list|join(',') %}
/tmp/example-debug.txt:
file.managed:
- contents: |
value => {{ value }}
hosts => {{ hosts }}
Running
sudo salt slave1 state.sls example saltenv=demo
gives output in /tmp/example-debug.txt
value => demo-value
hosts => slave1,slave3,slave2
so that all machines are listed, not just those from the demo environment.
(The above is just a simple example to demonstrate the problem. I am actually
using the formula from
https://github.com/saltstack-formulas/zookeeper-formula)
Am I doing something wrong, or is this expected behaviour?
Is there a way to ensure that only the machines from the relevant environment are returned from mine.get?
Thanks,
Ross