From 243a52ea75335d143d2593cfcee531a6c55f8b13 Mon Sep 17 00:00:00 2001 From: Chris Hammer Date: Wed, 9 Feb 2022 10:55:51 -0500 Subject: [PATCH] re-work machine-test.yml; includes additional tests and error handling. --- ansible.cfg | 4 ++-- machine-test.yml | 61 ++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 56 insertions(+), 9 deletions(-) diff --git a/ansible.cfg b/ansible.cfg index 881826b..f3230d5 100644 --- a/ansible.cfg +++ b/ansible.cfg @@ -15,8 +15,8 @@ timeout = 30 host_key_checking = False display_skipped_hosts = False interpreter_python = auto_silent -bin_ansible_callbacks = True -callbacks_enabled = yaml, timer, profile_tasks +#bin_ansible_callbacks = True +#callbacks_enabled = yaml, timer, profile_tasks deprecation_warnings = False diff --git a/machine-test.yml b/machine-test.yml index 51ed495..2ed32c4 100644 --- a/machine-test.yml +++ b/machine-test.yml @@ -5,13 +5,60 @@ become: no + vars: + induce_failure : "{{ tower_induce_failure | default('yes') }}" + host_to_fail : "{{ tower_host_to_fail | default('lab-prod-1') }}" + + tasks: - - name: "Test #1 - whoami" - command: - cmd: whoami - register: r_cmd_whoami + - name: Run tests against various hosts + block: + - name: "Test #1 - whoami" + command: + cmd: whoami + register: r_cmd_whoami - - name: "Results #1 - whoami" - debug: - var: r_cmd_whoami.stdout + - name: "Results #1 - whoami" + debug: + msg: + - "rc : {{ r_cmd_whoami.rc }}" + - "stdout : {{ r_cmd_whoami.stdout }}" + - "stderr : {{ r_cmd_whoami.stderr }}" + + + - name: "Test #2 - uptime" + command: + cmd: uptime + register: r_cmd_uptime + + + - name: "Results #2 - uptime" + debug: + msg: + - "rc : {{ r_cmd_uptime.rc }}" + - "stdout : {{ r_cmd_uptime.stdout }}" + - "stderr : {{ r_cmd_uptime.stderr }}" + + + - name: "Test #3 - induce failure (only for single host)" + command: + cmd: /bin/false + when: + - inventory_hostname == host_to_fail + - induce_failure + + + rescue: + - name: Exception caught! + debug: + msg: "Fail condition for {{ inventory_hostname }}!" + + + always: + - name: Job complete + debug: + msg: "Job has completed." + + +...