From 6b58f3a0cd89e4304fadfa7297d7243aee98d505 Mon Sep 17 00:00:00 2001 From: Chris Hammer Date: Wed, 23 Feb 2022 17:58:20 -0500 Subject: [PATCH] re-work file-removal-test.yml to function like file-creation-single.yml --- file-removal-test.yml | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/file-removal-test.yml b/file-removal-test.yml index 65897f7..c28b819 100644 --- a/file-removal-test.yml +++ b/file-removal-test.yml @@ -1,33 +1,36 @@ --- -- name: Remove a file from current inventory - hosts: all +- name: Create inventory based on passed extra_vars + hosts: localhost 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') }}" + provision_host: "{{ tower_provision_host | default('localhost') }}" tasks: - - block: - - name: "Test #1a - Remove file from machine - skipping {{ host_to_skip }}" + - name: "Create in-memory inventory for {{ provision_host }}" + add_host: + name: "{{ provision_host }}" + groups: + - remdiation + + +# =========================================================================== # + + +- name: Remove file from hosts + hosts: remdiation + gather_facts: no + become: no + + + tasks: + - name: "Remove file from {{ inventory_hostname }}" file: path : /tmp/hello-ansible.txt state : absent - when: inventory_hostname != host_to_skip - when: - - skip_host | bool - - - - name: "Test #1 - Remove file from machine" - file: - path : /tmp/hello-ansible.txt - state : absent - when: - - not skip_host | bool ...