changes to in-memory generation to better support single or multi-host runs
This commit is contained in:
@ -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 }}"
|
||||
|
||||
|
||||
...
|
@ -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
|
||||
|
||||
|
||||
...
|
||||
|
@ -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."
|
||||
|
||||
|
||||
...
|
||||
|
@ -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(',') }}"
|
||||
|
||||
|
||||
# =========================================================================== #
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user