mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02: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:
parent
fde7de80df
commit
9c5ec886a6
4 changed files with 20 additions and 10 deletions
2
Makefile
2
Makefile
|
@ -32,7 +32,7 @@ pep8:
|
|||
pep8 -r --ignore=E501,E221,W291,W391,E302,E251,E203,W293,E231,E303,E201,E225 lib/ bin/
|
||||
|
||||
pyflakes:
|
||||
pyflakes lib/ansible/*.py
|
||||
pyflakes lib/ansible/*.py bin/*
|
||||
|
||||
clean:
|
||||
@echo "Cleaning up distutils stuff"
|
||||
|
|
|
@ -181,6 +181,9 @@ class Cli(object):
|
|||
if utils.has_dark_hosts(results):
|
||||
buf += utils.dark_hosts_msg(results)
|
||||
|
||||
if not utils.has_hosts(results):
|
||||
print "ERROR: no hosts matched"
|
||||
|
||||
print buf
|
||||
|
||||
########################################################
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue