From 77c271c73d46b0f4fbeb38c32febdc3ab9691dc5 Mon Sep 17 00:00:00 2001 From: Chris Hammer Date: Wed, 9 Feb 2022 17:02:54 -0500 Subject: [PATCH] updates to several things ;) --- README.md | 6 +++ facts.d/127.0.0.1 | 3 ++ facts.d/localhost | 3 ++ file-creation-test.yml | 33 +++++++++++++ file-test.yml => file-existence-test.yml | 0 inmem-test.yml | 59 ++++++++++++++++++++++++ machine-test.yml | 40 ++++++++-------- 7 files changed, 126 insertions(+), 18 deletions(-) create mode 100644 README.md create mode 100644 facts.d/127.0.0.1 create mode 100644 facts.d/localhost create mode 100644 file-creation-test.yml rename file-test.yml => file-existence-test.yml (100%) create mode 100644 inmem-test.yml diff --git a/README.md b/README.md new file mode 100644 index 0000000..d4fe261 --- /dev/null +++ b/README.md @@ -0,0 +1,6 @@ +# Tower Tests +A simple series of plays, files, templates, etc for testing Ansible Tower and/or Ansible Automation Platform + + +### Authors: +> Chris Hammer (chris.hammer@redhat.com) diff --git a/facts.d/127.0.0.1 b/facts.d/127.0.0.1 new file mode 100644 index 0000000..78d2f11 --- /dev/null +++ b/facts.d/127.0.0.1 @@ -0,0 +1,3 @@ +{ + "discovered_interpreter_python": "/usr/bin/python3" +} \ No newline at end of file diff --git a/facts.d/localhost b/facts.d/localhost new file mode 100644 index 0000000..78d2f11 --- /dev/null +++ b/facts.d/localhost @@ -0,0 +1,3 @@ +{ + "discovered_interpreter_python": "/usr/bin/python3" +} \ No newline at end of file diff --git a/file-creation-test.yml b/file-creation-test.yml new file mode 100644 index 0000000..557f7f9 --- /dev/null +++ b/file-creation-test.yml @@ -0,0 +1,33 @@ +--- +- name: Create a test file on current inventory + hosts: all + gather_facts: no + become: no + + + vars: + # These vars are used to purposefully skip a node + skip_host : "{{ tower_skip_host | default('no') }}" + host_to_skip : "{{ tower_host_to_skip | default('lab-dev-2') }}" + + + tasks: + - block: + - name: "Test #1a - Copy file to machine - skipping {{ host_to_skip }}" + copy: + src : files/hello-ansible.txt + dest : /tmp/hello-ansible.txt + when: inventory_hostname != host_to_skip + when: + - skip_host | bool + + + - name: "Test #1 - Copy file to machine" + copy: + src : files/hello-ansible.txt + dest : /tmp/hello-ansible.txt + when: + - not skip_host | bool + + +... diff --git a/file-test.yml b/file-existence-test.yml similarity index 100% rename from file-test.yml rename to file-existence-test.yml diff --git a/inmem-test.yml b/inmem-test.yml new file mode 100644 index 0000000..21d37af --- /dev/null +++ b/inmem-test.yml @@ -0,0 +1,59 @@ +--- +- name: Utilize workflow based on an in-memory inventory + hosts: localhost + gather_facts: no + become: no + + + vars: + provision_host: "{{ tower_provision_host | default('localhost') }}" + + + tasks: + - name: "Create in-memory inventory for {{ provision_host }}" + add_host: + name: "{{ provision_host }}" + groups: + - remdiation + + + + +# =========================================================================== # + + +- name: Verify file existance and handle errors if needed + hosts: remdiation + gather_facts: no + become: no + + + tasks: + - name: Run file test + block: + - name: "Test #1: register file contents" + command : + cmd : cat /tmp/hello-ansible.txt + changed_when : no + register : r_check_file + + + rescue: + - name: Exception caught + debug: + msg: + - "host : {{ inventory_hostname }}" + - "rc : {{ r_check_file.rc }}" + - "stdout : {{ r_check_file.stdout }}" + - "stderr : {{ r_check_file.stderr }}" + + + always: + - name: Job complete + debug: + msg: + - "host : {{ inventory_hostname }}" + - "failed : {{ r_check_file.failed }} {{ r_check_file.msg }}" + + +... diff --git a/machine-test.yml b/machine-test.yml index ab2940f..a6c5272 100644 --- a/machine-test.yml +++ b/machine-test.yml @@ -5,28 +5,32 @@ become: no + vars: + # These vars are used to purposefully skip a node + skip_host : "{{ tower_skip_host | default('no') }}" + host_to_skip : "{{ tower_host_to_skip | default('lab-dev-2') }}" + + tasks: - - name: Run tests against various hosts - block: - - name: "Test #1 - whoami" - command : - cmd : whoami - changed_when : no - register : r_cmd_whoami + - name: "Test #1 - whoami" + command : + cmd : whoami + changed_when : no + 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: "Results #1 - whoami" + debug: + msg: + - "rc : {{ r_cmd_whoami.rc }}" + - "stdout : {{ r_cmd_whoami.stdout }}" + - "stderr : {{ r_cmd_whoami.stderr }}" - - name: "Test #2 - Copy file to machine" - copy: - src : files/hello-ansible.txt - dest : /tmp/hello-ansible.txt - + - name: "Test #2 - induce failure (but only for a specified host)" + command: + cmd: /bin/false + when: + - fail_host | bool and inventory_hostname == host_to_fail ...