mine.get works in command line but not inside orchestrator SLS
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 15.7k
- Forks
- 5.6k
- Avg merge
- 2d 44m
- Merged PRs (30d)
- 80
Description
Description
I want to loop on a list of minions inside an orchestration SLS file, targeting them with a pillar role. Salt mine is defined inside a dedicated pillar.
Setup
mine pillar:
mine_functions:
grains.item:
- id
Orchestration SLS test file:
{% set groups = ['db','back','front'] %}
{% for group in groups %}
{% set routes = pillar['netflow']['routes'][group] %}
{% for route in routes %}
{% set targets = salt['mine.get'](tgt='role:{{ route[0] }}', fun='grains.item', tgt_type='pillar', exclude_minion=true).items() | list %}
Test {{ group }} {{ route }}:
cmd.run:
- name: echo "targets={{ targets }}"
{% endfor %}
{% endfor %}
The routes variable is retrieved from the netflow pillar:
netflow:
timeout: 3
routes:
front:
- [ 'back', 'tcp', 22 ]
- [ 'db', 'tcp', 1521 ]
back:
- [ 'front', 'tcp', 80 ]
- [ 'db', 'tcp', 1521 ]
db:
- [ 'db', 'tcp', 1521 ]
Minion role pillars:
minion1 has role: 'db'
minion2 and minion4 have role: 'back'
minion3 has role: 'front'
Steps to Reproduce the behavior
After refreshing pillars and updating salt mine, a cache.mine command returns the correct result:
# salt-run cache.mine
minion1:
----------
grains.item:
----------
id:
minion1
minion2:
----------
grains.item:
----------
id:
minion2
minion3:
----------
grains.item:
----------
id:
minion3
minion4:
----------
grains.item:
----------
id:
minion4
When targeting the two minions having a role of 'back', the runner command line from the master gives the expected result:
# salt-run mine.get tgt='role:back' fun='grains.item' tgt_type='pillar'
minion2:
----------
id:
minion2
minion4:
----------
id:
minion4
Doing the same thing when executing the orchestrator returns an empty list:
# salt-run state.orchestrate orch.test1
master:
----------
ID: Test db ['db', 'tcp', 1521]
Function: cmd.run
Name: echo "targets=[]"
Result: True
Comment: Command "echo "targets=[]"" run
Started: 15:24:35.409293
Duration: 6.648 ms
Changes:
----------
pid:
44590
retcode:
0
stderr:
stdout:
targets=[]
----------
ID: Test back ['front', 'tcp', 80]
Function: cmd.run
Name: echo "targets=[]"
Result: True
Comment: Command "echo "targets=[]"" run
Started: 15:24:35.416172
Duration: 5.844 ms
Changes:
----------
pid:
44591
retcode:
0
stderr:
stdout:
targets=[]
----------
ID: Test back ['db', 'tcp', 1521]
Function: cmd.run
Name: echo "targets=[]"
Result: True
Comment: Command "echo "targets=[]"" run
Started: 15:24:35.422251
Duration: 5.815 ms
Changes:
----------
pid:
44592
retcode:
0
stderr:
stdout:
targets=[]
----------
ID: Test front ['back', 'tcp', 22]
Function: cmd.run
Name: echo "targets=[]"
Result: True
Comment: Command "echo "targets=[]"" run
Started: 15:24:35.428300
Duration: 5.847 ms
Changes:
----------
pid:
44593
retcode:
0
stderr:
stdout:
targets=[]
----------
ID: Test front ['db', 'tcp', 1521]
Function: cmd.run
Name: echo "targets=[]"
Result: True
Comment: Command "echo "targets=[]"" run
Started: 15:24:35.434381
Duration: 6.042 ms
Changes:
----------
pid:
44594
retcode:
0
stderr:
stdout:
targets=[]
Summary for master
------------
Succeeded: 5 (changed=5)
Failed: 0
------------
Total states run: 5
Total run time: 30.196 ms
Expected behavior
Orchestrator result should be:
# salt-run state.orchestrate orch.test1
master:
----------
ID: Test db ['db', 'tcp', 1521]
Function: cmd.run
Name: echo "targets=[ minion1 ]"
Result: True
Comment: Command "echo "targets=[ minion1 ]"" run
Started: 15:24:35.409293
Duration: 6.648 ms
Changes:
----------
pid:
44590
retcode:
0
stderr:
stdout:
targets=[ minion1 ]
----------
ID: Test back ['front', 'tcp', 80]
Function: cmd.run
Name: echo "targets=[ minion3 ]"
Result: True
Comment: Command "echo "targets=[ minion3 ]"" run
Started: 15:24:35.416172
Duration: 5.844 ms
Changes:
----------
pid:
44591
retcode:
0
stderr:
stdout:
targets=[ minion3 ]
----------
ID: Test back ['db', 'tcp', 1521]
Function: cmd.run
Name: echo "targets=[ minion1 ]"
Result: True
Comment: Command "echo "targets=[ minion1 ]"" run
Started: 15:24:35.422251
Duration: 5.815 ms
Changes:
----------
pid:
44592
retcode:
0
stderr:
stdout:
targets=[ minion1 ]
----------
ID: Test front ['back', 'tcp', 22]
Function: cmd.run
Name: echo "targets=[ minion2, minion4 ]"
Result: True
Comment: Command "echo "targets=[ minion2, minion4 ]"" run
Started: 15:24:35.428300
Duration: 5.847 ms
Changes:
----------
pid:
44593
retcode:
0
stderr:
stdout:
targets=[ minion2, minion4 ]
----------
ID: Test front ['db', 'tcp', 1521]
Function: cmd.run
Name: echo "targets=[ minion1 ]"
Result: True
Comment: Command "echo "targets=[ minion1 ]"" run
Started: 15:24:35.434381
Duration: 6.042 ms
Changes:
----------
pid:
44594
retcode:
0
stderr:
stdout:
targets=[ minion1 ]
Summary for master
------------
Succeeded: 5 (changed=5)
Failed: 0
------------
Total states run: 5
Total run time: 30.196 ms
Versions Report
salt --versions-report
(Provided by running salt --versions-report. Please also mention any differences in master/minion versions.)Salt Version:
Salt: 3002.2
Dependency Versions:
cffi: Not Installed
cherrypy: unknown
dateutil: 2.7.3
docker-py: Not Installed
gitdb: 2.0.6
gitpython: 3.0.7
Jinja2: 2.10.1
libgit2: Not Installed
M2Crypto: Not Installed
Mako: 1.1.0
msgpack: 0.6.2
msgpack-pure: Not Installed
mysql-python: Not Installed
pycparser: Not Installed
pycrypto: 2.6.1
pycryptodome: 3.6.1
pygit2: Not Installed
Python: 3.8.5 (default, Jul 28 2020, 12:59:40)
python-gnupg: 0.4.5
PyYAML: 5.3.1
PyZMQ: 18.1.1
smmap: 2.0.5
timelib: Not Installed
Tornado: 4.5.3
ZMQ: 4.3.2
System Versions:
dist: ubuntu 20.04 focal
locale: utf-8
machine: x86_64
release: 5.4.0-58-generic
system: Linux
version: Ubuntu 20.04 focal
Additional context
Add any other context about the problem here.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the discrepancy with salt-run cache.mine, mine.get, and state.orchestrate orch.test1, comparing command-line and orchestration results. Trace how salt['mine.get'] resolves pillar targeting inside the orchestration SLS. Done means the orchestrator returns the same role-targeted minions as the command-line runner, with coverage for the reported setup.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devops, infrastructure
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100