Skip to content
This repository has been archived by the owner on Jun 29, 2022. It is now read-only.

Commit

Permalink
Handle exit status appropriately. Closes #500.
Browse files Browse the repository at this point in the history
- Don't fail on an unreachable exit status.
- Don't fail on a failed exit status during discovery.
- Fail on a failed exit status during scanning.
  • Loading branch information
chambridge committed Dec 1, 2017
1 parent 99219ca commit 563db37
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 8 additions & 5 deletions rho/ansible_utils.py
Expand Up @@ -93,7 +93,7 @@ class AnsibleProcessException(Exception):
# pylint: disable=too-many-arguments
def run_with_vault(cmd_string, vault_pass, env=None, log_path=None,
log_to_stdout=None, ansible_verbosity=0,
print_before_run=False):
print_before_run=False, error_on_failure=True):
"""Runs ansible command allowing for password to be provided after
process triggered.
Expand Down Expand Up @@ -177,7 +177,10 @@ def run_with_vault(cmd_string, vault_pass, env=None, log_path=None,
print('Error: unexpected Ansible output')
sys.exit(1)

if child.exitstatus or child.signalstatus:
raise AnsibleProcessException(
'Ansible process failed with status %s, signal status %s' %
(child.exitstatus, child.signalstatus))
if (child.exitstatus != 0 and child.exitstatus != 4) or child.signalstatus:
if error_on_failure is False and child.exitstatus == 2:
pass
else:
raise AnsibleProcessException(
'Ansible process failed with status %s, signal status %s' %
(child.exitstatus, child.signalstatus))
2 changes: 1 addition & 1 deletion rho/host_discovery.py
Expand Up @@ -126,7 +126,7 @@ def create_ping_inventory(vault, vault_pass, profile_ranges, profile_port,
log_path=PING_LOG_PATH,
env=my_env,
log_to_stdout=tail_discovery_scan,
ansible_verbosity=0)
ansible_verbosity=0, error_on_failure=False)

with open(PING_LOG_PATH, 'r') as ping_log:
success_hosts, failed_hosts = process_ping_output(ping_log)
Expand Down

0 comments on commit 563db37

Please sign in to comment.