salt icon indicating copy to clipboard operation
salt copied to clipboard

Handle names with spaces in compound matching

Open ghost opened this issue 11 years ago • 21 comments

I've been trying to create a compound match against the grain 'virtual_subtype' - the value I'm interested in is 'Xen PV DomU'.

Unfortunately, you can't use spaces as part of a value to match in a compound match because it's split in a fairly naive way using string.split() - see: https://github.com/saltstack/salt/blob/develop/salt/minion.py#L2704

I'd love some way to escape spaces in a compound match so it would be possible to match against the exact value rather than a glob of 'Xen?PV?DomU' or PCRE of 'Xen\sPV\sDomU'.

ghost avatar Mar 03 '15 14:03 ghost

@tomjepp, thanks for the report. I suppose nobody has tried to compound match on grains containing spaces before.

jfindlay avatar Mar 09 '15 17:03 jfindlay

You can use P@virtual_subtype:Xen\sPV\sDomU to match on grains with spaces.

wwentland avatar May 22 '15 12:05 wwentland

@babilen I mentioned that as a specific workaround in the initial issue report!

"\s" is any whitespace character though, so it would also match a tab (for example). So it's not an exact match still.

ghost avatar May 22 '15 13:05 ghost

@tomjepp So you did. Sorry for the redundant information.

wwentland avatar May 22 '15 16:05 wwentland

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.

stale[bot] avatar Nov 07 '17 17:11 stale[bot]

This issue is still an issue in 2017.7.7. Please re-open. # salt -C 'G@virtual:physical or G@virtual_subtype:"Xen Dom0"' test.ping returns nothing.

Some other tests I have tried:

# salt -C 'G@virtual_subtype:"Xen Dom0"' test.ping
# salt -C 'G@virtual_subtype:Xen Dom0' test.ping
# salt -C 'G@virtual_subtype:Xen\ Dom0' test.ping
# salt -C 'G@"virtual_subtype:Xen Dom0"' test.ping
# salt -C '"G@virtual_subtype:Xen Dom0"' test.ping

This is actually quite frustrating because there's no default grain to just say "match all physical hosts" since even dom-0 physical hosts return "xen" for the virtual grain.

boltronics avatar Aug 17 '18 01:08 boltronics

Thank you for updating this issue. It is no longer marked as stale.

stale[bot] avatar Aug 19 '18 09:08 stale[bot]

Still an issue in salt 2018.3.2:

# salt -C 'G@osfullname:Centos' grains.item osfullname                                                                    
support.plymouth.edu:
    ----------
    osfullname:
        CentOS
...

# salt -C "G@osfullname:'Oracle Linux Server'" grains.item osfullname                                                     
No minions matched the target. No command was sent, no jid was assigned.
ERROR: No return received

# salt --version
salt 2018.3.2 (Oxygen)

jmcook1 avatar Dec 12 '18 14:12 jmcook1

And 2019.2.0 (Fluorine)

$ sudo salt 'test-vm1.test.local' grains.get manufacturer
test-vm1.test.local:
    VMware, Inc.

$ sudo salt -C 'G@manufacturer:VMware, Inc.' test.ping
No minions matched the target. No command was sent, no jid was assigned.
ERROR: No return received

$ salt --version
salt 2019.2.0 (Fluorine)

Workaround (wildcard)

sudo salt -C 'G@environment:test and G@osmajorrelease:5 and G@manufacturer:VMWare*' test.ping

chadgeary avatar May 01 '19 14:05 chadgeary

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.

stale[bot] avatar Jan 08 '20 17:01 stale[bot]

Still not fixed, please reopen.

ghost avatar Jan 08 '20 20:01 ghost

Thank you for updating this issue. It is no longer marked as stale.

stale[bot] avatar Jan 08 '20 20:01 stale[bot]

Still an issue with salt version: 3000.

mianosm avatar Mar 11 '20 22:03 mianosm

(ZD-5301)

Reconfirmed in 3001rc1:

# salt -C 'G@foo:"foo x"' test.ping
No minions matched the target. No command was sent, no jid was assigned.
ERROR: No return received

Master log excerpt:

2020-06-17 12:55:11,519 [salt.utils.minions:632 ][DEBUG   ][244] Evaluating final compound matching expr: set() set()
2020-06-17 12:55:11,519 [salt.utils.minions:637 ][ERROR   ][244] Invalid compound target: G@foo:"foo x"

oeuftete avatar Jun 17 '20 12:06 oeuftete

@xeacott attempting to assign you this issue

sagetherage avatar Jan 04 '21 18:01 sagetherage

This is still an issue. I'm trying salt -C 'bb* and G@productname:ProLiant DL380 Gen10' test.ping and it does not work. Have replaced the spaces with \s and it does not work.

bradawk1 avatar Oct 08 '21 13:10 bradawk1

Instead of using

salt -C 'G@virtual_subtype:Xen Dom0' test.ping

could you try using:

salt -C 'P@virtual_subtype:Xen\u0020Dom0' test.ping

Using the unicode character for space (\u0020) along with the "Grains PCRE" match type works for me when I need to use the compound matcher to match grains which have spaces in them.

onelittlehope avatar May 22 '22 15:05 onelittlehope

Closing as wont_fix, workaround available.

anilsil avatar Aug 22 '23 03:08 anilsil

LOL--great work-around.

I'll just get the unicode space character encoding tattooed on the back of my hand for easy reference...

darkpixel avatar Oct 06 '23 14:10 darkpixel

Hey...it's been a month, and I had to re-find this bug so I could remember the magic unicode embedding to match on a grain with spaces.

salt -G 'computerinfo:OsName:*Windows 11*' test.ping

...works just fine with spaces. Compound matching does not. Not with spaces, not with \s and not with \u0020.

This makes compound matches like this impossible:

salt -C 'G@computerinfo:OsName:*Windows\u002011* not G@computerinfo:OsHotFixes:KB5031354' state.sls automatically_upgrade_this_machine

darkpixel avatar Nov 06 '23 21:11 darkpixel