diff --git a/file-creation-single.yml b/file-creation-single.yml deleted file mode 100644 index d3a6b68..0000000 --- a/file-creation-single.yml +++ /dev/null @@ -1,45 +0,0 @@ ---- -- name: Create inventory based on passed extra_vars - hosts: all - gather_facts: no - become: no - - - vars_files: - - vars/defaults.yml - - - vars: - provision_host: "{{ tower_provision_host | default(ansible_play_hosts | random) }}" - - - tasks: - - name: "Create in-memory inventory for {{ provision_host }}" - add_host: - name: "{{ provision_host }}" - groups: - - remdiation - delegate_to: localhost - - -# =========================================================================== # - - -- name: Create a test file on remediation group - hosts: remdiation - gather_facts: no - become: no - - - vars_files: - - vars/defaults.yml - - - tasks: - - name: "Test #1 - Copy file to machine" - copy: - src : files/hello-ansible.txt - dest : "{{ check_file }}" - - -... diff --git a/file-creation-test.yml b/file-creation-test.yml index fcd527c..1a9d2ab 100644 --- a/file-creation-test.yml +++ b/file-creation-test.yml @@ -1,5 +1,5 @@ --- -- name: Create a test file on current inventory +- name: Create inventory based on extra_vars hosts: all gather_facts: no become: no @@ -10,28 +10,37 @@ 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(ansible_play_hosts | join(',')) }}" tasks: - - block: - - name: "Test #1a - Copy file to machine - skipping {{ host_to_skip }}" - copy: - src : files/hello-ansible.txt - dest : "{{ check_file }}" - when: inventory_hostname != host_to_skip - when: - - skip_host | bool + - name: "Create in-memory inventory" + add_host: + name: "{{ item }}" + groups: + - remdiation + delegate_to: localhost + loop: "{{ provision_host.split(',') }}" +# =========================================================================== # + + +- name: Create a test file on remediation group + hosts: remdiation + gather_facts: no + become: no + + + vars_files: + - vars/defaults.yml + + + tasks: - name: "Test #1 - Copy file to machine" copy: src : files/hello-ansible.txt dest : "{{ check_file }}" - when: - - not skip_host | bool ... diff --git a/file-existence-test.yml b/file-existence-test.yml index f35c66f..7eff3d5 100644 --- a/file-existence-test.yml +++ b/file-existence-test.yml @@ -1,10 +1,37 @@ --- -- name: Verify file existance and handle errors if needed +- name: Create inventory based on extra_vars hosts: all gather_facts: no become: no + vars_files: + - vars/defaults.yml + + + vars: + provision_host: "{{ tower_provision_host | default(ansible_play_hosts | join(',')) }}" + + + tasks: + - name: "Create in-memory inventory" + add_host: + name: "{{ item }}" + groups: + - remdiation + delegate_to: localhost + loop: "{{ provision_host.split(',') }}" + + +# =========================================================================== # + + +- name: Verify file existance and handle errors if needed + hosts: remdiation + gather_facts: no + become: no + + vars_files: - vars/defaults.yml @@ -19,20 +46,25 @@ register : r_check_file - rescue: - - name: Exception caught + - name: "Test #2: Say Hello" debug: - msg: - - "host : {{ inventory_hostname }}" - - "rc : {{ r_check_file.rc }}" - - "stdout : {{ r_check_file.stdout }}" - - "stderr : {{ r_check_file.stderr }}" + var: r_check_file.stdout - always: - - name: Job complete - debug: - msg: "Job has completed." +# 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: "Job has completed." ... diff --git a/file-removal-test.yml b/file-removal-test.yml index c35655a..4c5b8c2 100644 --- a/file-removal-test.yml +++ b/file-removal-test.yml @@ -1,5 +1,5 @@ --- -- name: Create inventory based on passed extra_vars +- name: Create inventory based on extra_vars hosts: all gather_facts: no become: no @@ -10,16 +10,17 @@ vars: - provision_host: "{{ tower_provision_host | default(ansible_play_hosts | random) }}" + provision_host: "{{ tower_provision_host | default(ansible_play_hosts | join(',')) }}" tasks: - - name: "Create in-memory inventory for {{ provision_host }}" + - name: "Create in-memory inventory" add_host: - name: "{{ provision_host }}" + name: "{{ item }}" groups: - remdiation delegate_to: localhost + loop: "{{ provision_host.split(',') }}" # =========================================================================== # diff --git a/update-hosts.yml b/update-hosts.yml index 109463e..5db1e2b 100644 --- a/update-hosts.yml +++ b/update-hosts.yml @@ -1,12 +1,39 @@ --- -- name: Update all hosts +- name: Create inventory based on extra_vars hosts: all gather_facts: no + become: no + + + vars_files: + - vars/defaults.yml + + + vars: + provision_host: "{{ tower_provision_host | default(ansible_play_hosts | join(',')) }}" + + + tasks: + - name: "Create in-memory inventory" + add_host: + name: "{{ item }}" + groups: + - remdiation + delegate_to: localhost + loop: "{{ provision_host.split(',') }}" + + +# =========================================================================== # + + +- name: Update remdiation hosts + hosts: remdiation + gather_facts: no become: yes tasks: - - name: Update all hosts + - name: Update host packages to latest releases package: name=* state=latest async: 1800 poll : 3