Skip to content

Commit

Permalink
fixes filetree_create not exporting constructed inventories when AAP …
Browse files Browse the repository at this point in the history
…< 2.4. Fixed Organization field check (#754)

* fixes filetree_create not exporting constructed inventories when AAP < 2.4. Fixed Organization field check

* fixes filetree_create not exporting constructed inventories when AAP < 2.4. Fixed Organization field check

* fixes filetree_create not exporting constructed inventories when AAP < 2.4. Fixed Organization field check
  • Loading branch information
ivarmu authored Jan 17, 2024
1 parent a6df606 commit 64d0005
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
3 changes: 2 additions & 1 deletion changelogs/fragments/issue_743.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
bugfixes:
- Avoid the hosts populated by a constructed inventory to be removed
- Organization not defined when exporting some inventory sources from Tower 3.7.2
- Constructed inventories can only be exported when AAP version is >= 4.5.0
12 changes: 8 additions & 4 deletions roles/filetree_create/tasks/all.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
---
- name: "Check if the connection is to an Ansible Tower or to Automation Platform"
- name: "Get the Tower/AAP instance version"
ansible.builtin.set_fact:
is_aap: "{{ lookup(controller_api_plugin, 'ping',
aap_version: "{{ lookup(controller_api_plugin, 'ping',
host=controller_hostname, oauth_token=controller_oauthtoken,
verify_ssl=controller_validate_certs).version is version('4.0.0', '>=') }}"
verify_ssl=controller_validate_certs).version }}"
- name: "Check if the connection is to an Ansible Tower or to Automation Platform"
ansible.builtin.set_fact:
is_aap: "{{ aap_version is version('4.0.0', '>=') }}"
have_constructed: "{{ aap_version is version('4.5.0', '>=') }}"
no_log: "{{ controller_configuration_filetree_create_secure_logging }}"

- name: "Block to get the organization_filter ID to filter all the queries"
Expand Down Expand Up @@ -32,7 +36,7 @@
when: "'inventory' in input_tag or 'all' in input_tag"
- name: "Export Constructed Inventories"
ansible.builtin.include_tasks: "constructed_inventory.yml"
when: "'inventory' in input_tag or 'all' in input_tag"
when: "('inventory' in input_tag or 'all' in input_tag) and have_constructed"
- name: "Export Credentials"
ansible.builtin.include_tasks: "credentials.yml"
when: "'credentials' in input_tag or 'all' in input_tag"
Expand Down
10 changes: 5 additions & 5 deletions roles/filetree_create/templates/current_inventory_sources.j2
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@ controller_inventory_sources:
{% for inventory_source in current_inventory_sources_asset_value %}
- name: "{{ inventory_source.name }}"
description: "{{ inventory_source.description }}"
{% if inventory_source.summary_fields.organization %}
{% if inventory_source.summary_fields.organization is defined %}
organization: "{{ inventory_source.summary_fields.organization.name }}"
{% endif %}
source: "{{ inventory_source.source | default('ToDo: The source of the inventory_source was originally missing and must be specified',true) }}"
{% if inventory_source.source_project %}
{% if inventory_source.source_project is defined and inventory_source.source_project != None %}
source_project: "{{ inventory_source.summary_fields.source_project.name }}"
{% endif %}
{% if inventory_source.source_path %}
{% if inventory_source.source_path is defined %}
source_path: "{{ inventory_source.source_path }}"
{% endif %}
{% if inventory_source.source_vars and inventory_source.source_vars != '---' and inventory_source.source_vars != '' %}
{% if inventory_source.source_vars is defined and inventory_source.source_vars != '---' and inventory_source.source_vars != '' %}
source_vars:
{{ inventory_source.source_vars | from_yaml | to_nice_yaml(indent=2) | indent(width=6, first=False) | replace("'{{", "!unsafe \'{{") }}
{%- endif %}
inventory: "{{ inventory_source.summary_fields.inventory.name }}"
update_on_launch: "{{ inventory_source.update_on_launch }}"
overwrite: "{{ inventory_source.overwrite }}"
{% if inventory_source.credential %}
{% if inventory_source.credential is defined %}
credential: "{{ inventory_source.summary_fields.credential.name }}"
{% endif %}
{% set query_notification_error = query(controller_api_plugin, inventory_source.related.notification_templates_error,
Expand Down

0 comments on commit 64d0005

Please sign in to comment.