Skip to content

Commit

Permalink
Fix Ansible manage inventories role (redhat-cop#651)
Browse files Browse the repository at this point in the history
* Split create vs update inventories

* Use original register name

* Add Debug message

- Add a debug message to try and catch if some people are receiving an empty JSON result from the Tower API.

* Ensure register var is reset each loop execution

* inventory_output to inventory_output_update

Renaming inventory_output to inventory_output_update for consistency

* Update process-inventory.yml

trigger GH actions

Co-authored-by: Øystein Bedin <oybed@users.noreply.github.com>
  • Loading branch information
2 people authored and jfilipcz committed Oct 20, 2021
1 parent 5de274a commit f3125c9
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions roles/ansible/tower/manage-inventories/tasks/process-inventory.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
Accept: "application/json"
validate_certs: "{{ ansible_tower.validate_certs | default(validate_tower_certs) | default(true) }}"
status_code: 200,201
register: inventory_output
register: inventory_output_create
when:
- (inv_id is not defined) or (inv_id | length == 0)

Expand All @@ -48,17 +48,23 @@
Accept: "application/json"
validate_certs: "{{ ansible_tower.validate_certs | default(validate_tower_certs) | default(true) }}"
status_code: 200,201
register: inventory_output
register: inventory_output_update
when:
- inv_id is defined
- inv_id | length > 0

- name: Display Debug message
ansible.builtin.debug:
msg:
- "Create - {{ inventory_output_create | default('EMPTY') }}"
- "Update - {{ inventory_output_update | default('EMPTY') }}"

- name: 'Get inventory id from the loaded inventory'
set_fact:
inv_id: "{{ inventory_output.json.id }}"
inv_id: "{{ inventory_output_create.json.id }}"
when:
- (inv_id is not defined) or (inv_id | length == 0)
- inventory_output is succeeded
- inventory_output_create is succeeded

- name: "Process the inventory host entries"
include_tasks: process-host.yml
Expand All @@ -81,7 +87,7 @@
- name: "Process the inventory sources"
include_tasks: process-source.yml
with_items:
- "{{ inventory.sources | default([])}}"
- "{{ inventory.sources | default([]) }}"
loop_control:
loop_var: source
when: inventory.sources is defined
Expand All @@ -90,4 +96,6 @@
set_fact:
org_id: ''
inv_id: ''
inventory_output_create: ''
inventory_output_update: ''
processed_inventories: "{{ processed_inventories + [ { 'name': inventory.name } ] }}"

0 comments on commit f3125c9

Please sign in to comment.