What you're seeing is expected behavior -- but not friendly behavior. :)
Salt executions are always asynchronous. The master does a
fire-and-forget publish and the minion(s) return results back to the
master in the background. Salt's CLI performs various tricks to give
the appearance of synchronous behavior. Read on...
On Wed, Jan 29, 2014 at 5:50 PM, JanetB <
jbors...@gmail.com> wrote:
> The first time I
> execute it the result is empty
This is a timeout issue. The minion starts executing the job but
Salt's Python API doesn't wait long enough for the job to finish, thus
the empty return. The job is still running on the minion, however. You
can increase the timeout that Salt will wait by passing the "timeout"
kwarg. The curl syntax for that though salt-api is: ``-d
timeout="300"``.
If you're hitting timeout issues consistently you might want to
embrace the asynchronous behavior by starting the execution against
the /minions URL which will return a JID. You can then look up the
results with the /jobs/<JID HERE> URL. As minions return data that URL
will start to populate with the returns.
> the next time (if done soon enough) returns
> the job_id but not the result of the execution
Salt blocks multiple state runs from being executed at the same time
to avoid one stepping on the other.
> and the third time returns
> that the package is already installed.
At this point the original execution has finished successfully and
returned data to the master. When you run the state a second time the
package has been installed. You can see the result of the first job by
looking up the job ID:
# List all jobs and find the last state run. (Or just grab the JID
from the error message you posted above.)
salt-run jobs.list_jobs
# Look up the result of the job
salt-run jobs.lookup_jid <JID HERE>