Skip to content

Commit

Permalink
Optionally display Skipping [host] messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
James Martin committed Sep 26, 2013
1 parent 0ee236b commit d5f20e6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
5 changes: 5 additions & 0 deletions examples/ansible.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ timeout = 10
# replacing {file}, {host} and {uid} and strftime codes with proper values.
ansible_managed = Ansible managed: {file} modified on %Y-%m-%d %H:%M:%S by {uid} on {host}

# by default, ansible-playbook will display "Skipping [host]" if it determines a task
# should not be run on a host. Set this to "no" if you don't want to see these "Skipping"
# messages.
# display_skipped_hosts: yes

# by default (as of 1.3), Ansible will raise errors when attempting to dereference
# Jinja2 variables that are not set in templates or action lines. Uncomment this line
# to revert the behavior to pre-1.3.
Expand Down
23 changes: 12 additions & 11 deletions lib/ansible/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def get_cowsay_info():
cowsay, noncow = get_cowsay_info()

def log_lockfile():
tempdir = tempfile.gettempdir()
tempdir = tempfile.gettempdir()
uid = os.getuid()
path = os.path.join(tempdir, ".ansible-lock.%s" % uid)
return path
Expand All @@ -93,7 +93,7 @@ def log_flock(runner):
fcntl.lockf(LOG_LOCK, fcntl.LOCK_EX)
except OSError:
pass


def log_unflock(runner):
if runner is not None:
Expand Down Expand Up @@ -471,7 +471,7 @@ def on_failed(self, host, results, ignore_errors=False):
super(PlaybookRunnerCallbacks, self).on_failed(host, results, ignore_errors=ignore_errors)

def on_ok(self, host, host_result):

item = host_result.get('item', None)

host_result2 = host_result.copy()
Expand Down Expand Up @@ -519,13 +519,14 @@ def on_error(self, host, err):
super(PlaybookRunnerCallbacks, self).on_error(host, err)

def on_skipped(self, host, item=None):
msg = ''
if item:
msg = "skipping: [%s] => (item=%s)" % (host, item)
else:
msg = "skipping: [%s]" % host
display(msg, color='cyan', runner=self.runner)
super(PlaybookRunnerCallbacks, self).on_skipped(host, item)
if constants.DISPLAY_SKIPPED_HOSTS:
msg = ''
if item:
msg = "skipping: [%s] => (item=%s)" % (host, item)
else:
msg = "skipping: [%s]" % host
display(msg, color='cyan', runner=self.runner)
super(PlaybookRunnerCallbacks, self).on_skipped(host, item)

def on_no_hosts(self):
display("FATAL: no hosts matched or all hosts have already failed -- aborting\n", color='red', runner=self.runner)
Expand Down Expand Up @@ -581,7 +582,7 @@ def on_task_start(self, name, is_conditional):
msg = "TASK: [%s]" % name
if is_conditional:
msg = "NOTIFIED: [%s]" % name

if hasattr(self, 'start_at'):
if name == self.start_at or fnmatch.fnmatch(name, self.start_at):
# we found out match, we can get rid of this now
Expand Down
1 change: 1 addition & 0 deletions lib/ansible/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ def shell_expand_path(path):

ANSIBLE_NOCOLOR = get_config(p, DEFAULTS, 'nocolor', 'ANSIBLE_NOCOLOR', None, boolean=True)
ANSIBLE_NOCOWS = get_config(p, DEFAULTS, 'nocows', 'ANSIBLE_NOCOWS', None, boolean=True)
DISPLAY_SKIPPED_HOSTS = get_config(p, DEFAULTS, 'display_skipped_hosts', 'DISPLAY_SKIPPED_HOSTS', True, boolean=True)
ANSIBLE_SSH_ARGS = get_config(p, 'ssh_connection', 'ssh_args', 'ANSIBLE_SSH_ARGS', None)
ANSIBLE_SSH_CONTROL_PATH = get_config(p, 'ssh_connection', 'control_path', 'ANSIBLE_SSH_CONTROL_PATH', "%(directory)s/ansible-ssh-%%h-%%p-%%r")
PARAMIKO_RECORD_HOST_KEYS = get_config(p, 'paramiko_connection', 'record_host_keys', 'ANSIBLE_PARAMIKO_RECORD_HOST_KEYS', True, boolean=True)
Expand Down

0 comments on commit d5f20e6

Please sign in to comment.