mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 05:42:50 +00:00
Import cleanup, plus have /bin/ansible remind you if no hosts were matched by a pattern (for instance, assume
there was a typo in the pattern)
This commit is contained in:
@@ -22,8 +22,6 @@ import fnmatch
|
||||
import multiprocessing
|
||||
import signal
|
||||
import os
|
||||
import ansible.constants as C
|
||||
import ansible.connection
|
||||
import Queue
|
||||
import random
|
||||
import jinja2
|
||||
@@ -31,17 +29,14 @@ import traceback
|
||||
import tempfile
|
||||
import subprocess
|
||||
|
||||
import ansible.constants as C
|
||||
import ansible.connection
|
||||
from ansible import utils
|
||||
from ansible import errors
|
||||
|
||||
# should be True except in debug
|
||||
CLEANUP_FILES = True
|
||||
|
||||
try:
|
||||
import json
|
||||
except ImportError:
|
||||
import simplejson as json
|
||||
|
||||
################################################
|
||||
|
||||
def _executor_hook(job_queue, result_queue):
|
||||
@@ -170,7 +165,7 @@ class Runner(object):
|
||||
cmd = subprocess.Popen([host_list], stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False)
|
||||
out, err = cmd.communicate()
|
||||
try:
|
||||
groups = json.loads(out)
|
||||
groups = utils.json_loads(out)
|
||||
except:
|
||||
raise errors.AnsibleError("invalid JSON response from script: %s" % host_list)
|
||||
for (groupname, hostlist) in groups.iteritems():
|
||||
@@ -309,7 +304,7 @@ class Runner(object):
|
||||
out, err = cmd.communicate()
|
||||
inject2 = {}
|
||||
try:
|
||||
inject2 = json.loads(out)
|
||||
inject2 = utils.json_loads(out)
|
||||
except:
|
||||
raise errors.AnsibleError("%s returned invalid result when called with hostname %s" % (
|
||||
Runner._external_variable_script,
|
||||
|
||||
@@ -149,6 +149,14 @@ def has_dark_hosts(results):
|
||||
''' are there any uncontactable hosts? '''
|
||||
return len(results['dark'].keys()) > 0
|
||||
|
||||
def has_contacted_hosts(results):
|
||||
''' are there any contacted hosts? '''
|
||||
return len(results['contacted'].keys()) > 0
|
||||
|
||||
def has_hosts(results):
|
||||
''' did ansible run against any hosts at all? '''
|
||||
return has_contacted_hosts(results) or has_dark_hosts(results)
|
||||
|
||||
def contacted_hosts(results):
|
||||
''' what are the contactable hosts? '''
|
||||
return sorted(results['contacted'])
|
||||
@@ -186,7 +194,11 @@ def async_poll_status(jid, host, clock, result):
|
||||
else:
|
||||
return "<job %s> polling on %s, %s remaining" % (jid, host, clock)
|
||||
|
||||
def json_loads(data):
|
||||
return json.loads(data)
|
||||
|
||||
def parse_json(data):
|
||||
''' this version for module return data only '''
|
||||
try:
|
||||
return json.loads(data)
|
||||
except:
|
||||
|
||||
Reference in New Issue
Block a user