salt icon indicating copy to clipboard operation
salt copied to clipboard

Globbing Broken when Using Reactor

Open rallytime opened this issue 11 years ago • 4 comments

Following some of the examples in the Reactor documentation, I have the following set up:

In /etc/salt/master:

reactor:
  - 'salt/minion/*/start':
    - /srv/reactor/start.sls
/srv/reactor/start.sls

In /srv/reactor/start.sls

clean_tmp:
  local.cmd.run:
    - tgt: '*'
    - arg:
      - rm -rf /tmp/*

Where basically the minion /tmp/ directory should be cleaned out upon minion start-up. I can see the reactor sending events from the master:

[DEBUG   ] Rendered data from file: /srv/reactor/start.sls:
clean_tmp:
  local.cmd.run:
    - tgt: '*'
    - arg:
      - rm -rf /tmp/*


[DEBUG   ] Results of YAML rendering:
OrderedDict([('clean_tmp', OrderedDict([('local.cmd.run', [OrderedDict([('tgt', '*')]), OrderedDict([('arg', ['rm -rf /tmp/*'])])])]))])

And the event is fired on the minion:

[INFO    ] User root Executing command cmd.run with jid 20150316184206483633
[DEBUG   ] Command details {'tgt_type': 'glob', 'jid': '20150316184206483633', 'tgt': '*', 'ret': '', 'user': 'root', 'arg': ['rm -rf /tmp/*'], 'fun': 'cmd.run'}
[INFO    ] Starting a new job with PID 10925
[INFO    ] Executing command 'rm -rf /tmp/*' in directory '/root'
[DEBUG   ] output:
[INFO    ] Returning information for job: 20150316184206483633

But when looking in the /tmp/ directory, the are still files:

# ls /tmp/
test_file.txt

After some testing and debugging, if I change the start.sls file to do something other than rm -rf /tmp/* (for example, touch /tmp/foo or rm -rf /tmp/specific_file_name) it works just fine. It appears that passing in the * is causing a problem.

Also note that this exact same set up works just fine on 2014.7.2 and the HEAD of the 2014.7 branch.

rallytime avatar Mar 16 '15 18:03 rallytime

I think this is related to the problem I am seeing. It seems cmdmod no longer handles globbing. For example:

$ salt-call cmd.run cmd='ls /etc/*'
local:
    ls: cannot access /etc/*: No such file or directory

Same problem with ?, for example: salt-call cmd.run cmd='ls /etc/host?'

Versions:

           Salt: 2015.2.0
         Python: 2.7.5 (default, Jun 17 2014, 18:11:42)
         Jinja2: 2.7.3
       M2Crypto: 0.21.1
 msgpack-python: 0.4.4
   msgpack-pure: Not Installed
       pycrypto: 2.6.1
        libnacl: Not Installed
         PyYAML: 3.10
          ioflo: Not Installed
          PyZMQ: 14.3.1
           RAET: Not Installed
            ZMQ: 4.0.4
           Mako: Not Installed

luxi2001 avatar Mar 23 '15 22:03 luxi2001

Globbing still works when vt.Terminal is used, instead of TimedProc (use_vt=True). Also works when python_shell=True. I see this is intended behaviour in #19914

luxi2001 avatar Mar 26 '15 11:03 luxi2001

Oh, you're totally right @luxi2001. That is the expected behavior here, and I even knew about that change. I just didn't think it through in terms of using the reactor. Thanks for posting that information and hopefully this will help others that might be running into this issue. :)

rallytime avatar Mar 26 '15 14:03 rallytime

That seems like a rather large backward incompatible change... I've been seeing traces of this all over. Notably with | (pipes) in cmd.run's

bjackson@dev-salt01:~$ sudo salt-call cmd.run "ps -ef | grep salt"
[INFO    ] Executing command 'ps -ef | grep salt' in directory '/root'
[ERROR   ] Command 'ps -ef | grep salt' failed with return code: 1
[ERROR   ] output: error: garbage option

Usage:
 ps [options]

 Try 'ps --help <simple|list|output|threads|misc|all>'
  or 'ps --help <s|l|o|t|m|a>'
 for additional help text.

For more details see ps(1).
local:
    error: garbage option

    Usage:
     ps [options]

     Try 'ps --help <simple|list|output|threads|misc|all>'
      or 'ps --help <s|l|o|t|m|a>'
     for additional help text.

    For more details see ps(1).
bjackson@dev-salt01:~$ sudo salt-call cmd.run "ps -ef | grep salt" python_shell=True
[INFO    ] Executing command 'ps -ef | grep salt' in directory '/root'
local:
    root       925 31247  0 16:29 pts/0    00:00:00 sudo salt-call cmd.run ps -ef | grep salt python_shell=True
    root       926   925 44 16:29 pts/0    00:00:00 /usr/bin/python /usr/bin/salt-call cmd.run ps -ef | grep salt python_shell=True
    root       956   926  0 16:29 pts/0    00:00:00 /bin/bash -c ps -ef | grep salt
    root       958   956  0 16:29 pts/0    00:00:00 grep salt
    root     20179     1  0 Mar19 ?        00:00:00 /usr/bin/python /usr/bin/salt-minion
    root     20196 20179  0 Mar19 ?        00:03:38 /usr/bin/python /usr/bin/salt-minion
    root     28112     1  0 Mar19 ?        00:00:00 /usr/bin/python /usr/bin/salt-master -d
    root     28113 28112  0 Mar19 ?        00:35:20 /usr/bin/python /usr/bin/salt-master -d
    root     28114 28112  0 Mar19 ?        00:00:00 /usr/bin/python /usr/bin/salt-master -d
    root     28115 28112  0 Mar19 ?        00:00:00 /usr/bin/python /usr/bin/salt-master -d
    root     28160 28112  0 Mar19 ?        01:25:28 /usr/bin/python /usr/bin/salt-master -d
    root     28161 28112  0 Mar19 ?        00:00:00 /usr/bin/python /usr/bin/salt-master -d
    root     28163 28161  0 Mar19 ?        00:00:22 /usr/bin/python /usr/bin/salt-master -d
    root     28166 28161  0 Mar19 ?        00:00:22 /usr/bin/python /usr/bin/salt-master -d
    root     28169 28161  0 Mar19 ?        00:00:22 /usr/bin/python /usr/bin/salt-master -d
    root     28170 28161  0 Mar19 ?        00:00:22 /usr/bin/python /usr/bin/salt-master -d
    root     28171 28161  0 Mar19 ?        00:00:22 /usr/bin/python /usr/bin/salt-master -d
    root     28183 28161  0 Mar19 ?        00:00:11 /usr/bin/python /usr/bin/salt-master -d
bjackson@dev-salt01:~$ 

iggy avatar Mar 26 '15 16:03 iggy