salt icon indicating copy to clipboard operation
salt copied to clipboard

mine.get not returning data in a state.orchestrate sls

Open calvinhp opened this issue 8 years ago • 7 comments

Description of Issue/Question

mine.get is not working correctly from inside an orchestration.

Setup

Add a mine_function to a pillar to return network.ip_addrs

Create an orch.sls with the following contents

{% set app_servers = salt.saltutil.runner('mine.get',
        tgt='*',
        fun='network.ip_addrs') %}

{% for app_server in app_servers.keys() %}

test-{{ app_server }}:
  salt.function:
    - tgt: {{ app_server }}
    - fun: test.ping

{% endfor %}

Steps to Reproduce Issue

When running the following, app_servers will be an empty dictionary

$ sudo salt-run state.orchestrate orch

but if I run the same function via saltutil.runner it returns as I expect

$ sudo salt-call saltutil.runner mine.get tgt='*' fun='network.ip_addrs'

gives me this output

local:
    ----------
    minion01:
        - 10.192.2.58
    minion02:
        - 10.192.2.59

Versions Report

Salt Version:
           Salt: 2018.3.0

Dependency Versions:
           cffi: Not Installed
       cherrypy: 3.5.0
       dateutil: 2.4.2
      docker-py: Not Installed
          gitdb: 0.6.4
      gitpython: 1.0.1
          ioflo: Not Installed
         Jinja2: 2.8
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: 1.0.3
   msgpack-pure: Not Installed
 msgpack-python: 0.4.6
   mysql-python: Not Installed
      pycparser: Not Installed
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: Not Installed
         Python: 2.7.12 (default, Nov 20 2017, 18:23:56)
   python-gnupg: Not Installed
         PyYAML: 3.11
          PyZMQ: 15.2.0
           RAET: Not Installed
          smmap: 0.9.0
        timelib: 0.2.4
        Tornado: 4.2.1
            ZMQ: 4.1.4

System Versions:
           dist: Ubuntu 16.04 xenial
         locale: UTF-8
        machine: x86_64
        release: 4.4.0-97-generic
         system: Linux
        version: Ubuntu 16.04 xenial

calvinhp avatar Jun 07 '18 14:06 calvinhp

was this working previously? are you just seeing it in 2018.3.0?

Ch3LL avatar Jun 08 '18 18:06 Ch3LL

@Ch3LL Since he hasn't responded and I have just found this same issue after upgrading to 2018.3.1 on Friday, I'll add some additional information.

I find that I cannot get mine data from the master with salt-run commands. This is a problem as any mine data you want to use to control the flow of your orchestration or pillar will fail because they're rendered on the master (which is why saltutil.runner is used).

I upgraded from 2017.7.0 to 2018.3.1. This functionality has worked for us since 2016.3.3 and now doesn't work in 2018.3.1. This currently works in our 2017.7.0 production environments, but doesn't work in my test environment that I just upgraded to 2018.3.1.

salt-run mine.get '*' <mine function>

robertpenberthy avatar Jun 18 '18 16:06 robertpenberthy

It does not work for me either. Same behavior on 2018.3.1.

edit: It looks like it works if I'm using tgt_type='pillar' instead of 'glob'

marceliq avatar Jun 19 '18 13:06 marceliq

thanks for clarifying the versions it was working in that helped me bisect the issue. The bisect showed this commit: bc307964d9783530b6a4b742becd343e98ad750e which is this pr: https://github.com/saltstack/salt/pull/44890

particularly i found its the diff of this file that created the problem:

diff --git a/salt/utils/minions.py b/salt/utils/minions.py
index 2049f5549a27..f0e18625016c 100644
--- a/salt/utils/minions.py
+++ b/salt/utils/minions.py
@@ -228,6 +228,10 @@ def _pki_minions(self):
         Retreive complete minion list from PKI dir.
         Respects cache if configured
         '''
+        if self.opts.get('__role') == 'master':
+            # Compiling pillar directly on the master, just return the master's
+            # ID as that is the only one that is available.
+            return [self.opts['id']]
         minions = []
         pki_cache_fn = os.path.join(self.opts['pki_dir'], self.acc, '.key_cache')
         try:
@@ -241,7 +245,10 @@ def _pki_minions(self):
                         minions.append(fn_)
             return minions
         except OSError as exc:
-            log.error('Encountered OSError while evaluating  minions in PKI dir: {0}'.format(exc))
+            log.error(
+                'Encountered OSError while evaluating minions in PKI dir: %s',
+                exc
+            )
             return minions
 
     def _check_cache_minions(self,

I created a docker container to quickly replicate this:

  1. docker run -it -v ~/git/salt/:/testing/ ch3ll/issues:48020 (where ~/git/salt is a local cloned git repo of salt)
  2. bash -x ~/run.sh

ping @terminalmage

Ch3LL avatar Jun 21 '18 19:06 Ch3LL

This was fixed in https://github.com/saltstack/salt/pull/48765.

terminalmage avatar Aug 07 '18 18:08 terminalmage

seems to returned bug in 2019.2.0 ?

skob avatar May 13 '19 16:05 skob

@skob can you please open a new issue with the details around the issue you are seeing for the 2019.2.0 version.

Ch3LL avatar May 17 '19 14:05 Ch3LL