From 5efa293f29dc4f4a75e655635e1d9cdd138049c6 Mon Sep 17 00:00:00 2001 From: Chris Hammer Date: Wed, 9 Feb 2022 11:53:19 -0500 Subject: [PATCH] re-work machine-test.yml; add block-test.yml --- block-test.yml | 64 +++++++++++++++++++++++++++++++++++++++++ files/hello-ansible.txt | 1 + machine-test.yml | 47 +++++------------------------- 3 files changed, 72 insertions(+), 40 deletions(-) create mode 100644 block-test.yml create mode 100644 files/hello-ansible.txt diff --git a/block-test.yml b/block-test.yml new file mode 100644 index 0000000..be89fc6 --- /dev/null +++ b/block-test.yml @@ -0,0 +1,64 @@ +--- +- name: Tests machine connections via Ansible Tower/Ansible Automation Platform + hosts: all + gather_facts: no + become: no + + + vars: + induce_failure : "{{ tower_induce_failure | default('yes') }}" + host_to_fail : "{{ tower_host_to_fail | default('lab-prod-1') }}" + + + tasks: + - name: Run tests against various hosts + block: + - name: "Test #1 - whoami" + command: + cmd: whoami + register: r_cmd_whoami + + + - 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 (but only for a specified 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." + + +... diff --git a/files/hello-ansible.txt b/files/hello-ansible.txt new file mode 100644 index 0000000..ebf76a2 --- /dev/null +++ b/files/hello-ansible.txt @@ -0,0 +1 @@ +Hello from Ansible! diff --git a/machine-test.yml b/machine-test.yml index 2ed32c4..f20af13 100644 --- a/machine-test.yml +++ b/machine-test.yml @@ -5,18 +5,13 @@ become: no - vars: - induce_failure : "{{ tower_induce_failure | default('yes') }}" - host_to_fail : "{{ tower_host_to_fail | default('lab-prod-1') }}" - - tasks: - name: Run tests against various hosts block: - name: "Test #1 - whoami" - command: - cmd: whoami - register: r_cmd_whoami + command : + cmd : whoami + register : r_cmd_whoami - name: "Results #1 - whoami" @@ -27,38 +22,10 @@ - "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." + - name: "Test #2 - Copy file to machine" + copy: + src : files/hello-ansible.txt + dest : /tmp/hello-ansible.txt ...