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
|
hosts: all
|
||||||
gather_facts: no
|
gather_facts: no
|
||||||
become: no
|
become: no
|
||||||
@ -10,28 +10,37 @@
|
|||||||
|
|
||||||
|
|
||||||
vars:
|
vars:
|
||||||
# These vars are used to purposefully skip a node
|
provision_host: "{{ tower_provision_host | default(ansible_play_hosts | join(',')) }}"
|
||||||
skip_host : "{{ tower_skip_host | default('no') }}"
|
|
||||||
host_to_skip : "{{ tower_host_to_skip | default('lab-dev-2') }}"
|
|
||||||
|
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
- block:
|
- name: "Create in-memory inventory"
|
||||||
- name: "Test #1a - Copy file to machine - skipping {{ host_to_skip }}"
|
add_host:
|
||||||
copy:
|
name: "{{ item }}"
|
||||||
src : files/hello-ansible.txt
|
groups:
|
||||||
dest : "{{ check_file }}"
|
- remdiation
|
||||||
when: inventory_hostname != host_to_skip
|
delegate_to: localhost
|
||||||
when:
|
loop: "{{ provision_host.split(',') }}"
|
||||||
- skip_host | bool
|
|
||||||
|
|
||||||
|
|
||||||
|
# =========================================================================== #
|
||||||
|
|
||||||
|
|
||||||
|
- 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"
|
- name: "Test #1 - Copy file to machine"
|
||||||
copy:
|
copy:
|
||||||
src : files/hello-ansible.txt
|
src : files/hello-ansible.txt
|
||||||
dest : "{{ check_file }}"
|
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
|
hosts: all
|
||||||
gather_facts: no
|
gather_facts: no
|
||||||
become: 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_files:
|
||||||
- vars/defaults.yml
|
- vars/defaults.yml
|
||||||
|
|
||||||
@ -19,20 +46,25 @@
|
|||||||
register : r_check_file
|
register : r_check_file
|
||||||
|
|
||||||
|
|
||||||
rescue:
|
- name: "Test #2: Say Hello"
|
||||||
- name: Exception caught
|
|
||||||
debug:
|
debug:
|
||||||
msg:
|
var: r_check_file.stdout
|
||||||
- "host : {{ inventory_hostname }}"
|
|
||||||
- "rc : {{ r_check_file.rc }}"
|
|
||||||
- "stdout : {{ r_check_file.stdout }}"
|
|
||||||
- "stderr : {{ r_check_file.stderr }}"
|
|
||||||
|
|
||||||
|
|
||||||
always:
|
# rescue:
|
||||||
- name: Job complete
|
# - name: Exception caught
|
||||||
debug:
|
# debug:
|
||||||
msg: "Job has completed."
|
# 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
|
hosts: all
|
||||||
gather_facts: no
|
gather_facts: no
|
||||||
become: no
|
become: no
|
||||||
@ -10,16 +10,17 @@
|
|||||||
|
|
||||||
|
|
||||||
vars:
|
vars:
|
||||||
provision_host: "{{ tower_provision_host | default(ansible_play_hosts | random) }}"
|
provision_host: "{{ tower_provision_host | default(ansible_play_hosts | join(',')) }}"
|
||||||
|
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
- name: "Create in-memory inventory for {{ provision_host }}"
|
- name: "Create in-memory inventory"
|
||||||
add_host:
|
add_host:
|
||||||
name: "{{ provision_host }}"
|
name: "{{ item }}"
|
||||||
groups:
|
groups:
|
||||||
- remdiation
|
- remdiation
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
|
loop: "{{ provision_host.split(',') }}"
|
||||||
|
|
||||||
|
|
||||||
# =========================================================================== #
|
# =========================================================================== #
|
||||||
|
@ -1,12 +1,39 @@
|
|||||||
---
|
---
|
||||||
- name: Update all hosts
|
- name: Create inventory based on extra_vars
|
||||||
hosts: all
|
hosts: all
|
||||||
gather_facts: no
|
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
|
become: yes
|
||||||
|
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
- name: Update all hosts
|
- name: Update host packages to latest releases
|
||||||
package: name=* state=latest
|
package: name=* state=latest
|
||||||
async: 1800
|
async: 1800
|
||||||
poll : 3
|
poll : 3
|
||||||
|
Reference in New Issue
Block a user