Salt: Targetting minions based on multiple grains in Python Client

Created on 14 Jun 2017  路  8Comments  路  Source: saltstack/salt

I am trying to to query minions matching a set of grains using the python client
Note, this works when I target using a single grain, but not using multiple grains

Initial Setup :

saltclient = salt.client.LocalClient()

Here is the things I have tried

saltclient.cmd('env:qa,client:someone','grains.items', expr_form='grain')

saltclient.cmd('env:qa and client:someone','grains.items', expr_form='grain')

saltclient.cmd('env:qa and client:someone','grains.items', expr_form='compound')

In all the cases, I am not able to target any minion

Version Report

Salt Version:
Salt: 2016.11.4

Dependency Versions:
cffi: Not Installed
cherrypy: Not Installed
dateutil: 2.5.3
docker-py: Not Installed
gitdb: Not Installed
gitpython: Not Installed
ioflo: Not Installed
Jinja2: 2.9.6
libgit2: Not Installed
libnacl: Not Installed
M2Crypto: Not Installed
Mako: 1.0.3
msgpack-pure: Not Installed
msgpack-python: 0.4.8
mysql-python: Not Installed
pycparser: Not Installed
pycrypto: 2.6.1
pycryptodome: Not Installed
pygit2: Not Installed
Python: 2.7.12 (default, Nov 19 2016, 06:48:10)
python-gnupg: 0.4.0
PyYAML: 3.12
PyZMQ: 16.0.2
RAET: Not Installed
smmap: Not Installed
timelib: Not Installed
Tornado: 4.5.1
ZMQ: 4.1.6

System Versions:
dist: LinuxMint 18 sarah
machine: x86_64
release: 4.4.0-21-generic
system: Linux
version: LinuxMint 18 sarah

Bug P3 severity-medium

All 8 comments

Thanks for the report @ramaseshan we'll take a look and get this one fixed.

Just a small questions, what does P3 mean in the label ?

@ramaseshan P3 is the priority of the issue and represents our best guess as to the amount of Salt users that are affected by this particular issue.

@ramaseshan Following the documentation here it will work if you use the compound matching but you need to specify what each qualifier is, so something like this:

saltclient.cmd('G@env:qa and G@client:someone','grains.items', expr_form='compound')

will give you what you want.

@garethgreenaway I can confirm that a compound expr is working.

Does this mean that, this is the right way to do it ? Or even with expr_form='grain' should also be working.

To me compound looks to be the right way to do it.

@ramaseshan If you're matching with multiple qualifiers then you want to use the compound match and the example above is the one to use. It's not going to work with expr_form=grain because that's looking for a single grain like this example: https://docs.saltstack.com/en/latest/topics/targeting/grains.html

I believe this issue should be considered resolved. If the issue is not considered resolved or persists, please feel free to re-open this issue.

Hello, maybe I am doing this incorrectly, but I am still unable to get any minions based on the commands above..

From the CLI I run:

salt -G 'os:ios' test.ping and I get data returned but running the equiv in the Python client I get nothing:

import salt.client
client = salt.client.LocalClient()

client.cmd('os:ios', 'test.ping', expr_form='grain')
No minions matched the target. No command was sent, no jid was assigned.
{}

client.cmd('* and G@os:ios, test.ping, expr_form='compound')
No minions matched the target. No command was sent, no jid was assigned.
{}

I should note the targets are proxy minions..

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sagetherage picture sagetherage  路  3Comments

nixjdm picture nixjdm  路  3Comments

golmaal picture golmaal  路  3Comments

qiushics picture qiushics  路  3Comments

mooperd picture mooperd  路  3Comments