sean_m_sullivan / sean_m_sullivan.controller_configuration / 2.2.0 / lookup / controller_object_diff Return difference for objects from Controller API Authors: Sean Sullivan (@sean-m-sullivan)sean_m_sullivan.controller_configuration.controller_object_diff (2.2.0) — lookup
Install with ansible-galaxy collection install sean_m_sullivan.controller_configuration:==2.2.0
collections: - name: sean_m_sullivan.controller_configuration version: 2.2.0
Takes results of GET requests from the Automation Platform Controller API. See U(https://docs.ansible.com/ansible-tower/latest/html/towerapi/index.html) for API usage.
Returns difference of on Unique Name and Organization, between two sets of groups
- name: Get the organization ID set_fact: controller_organization_id: "{{ lookup('awx.awx.controller_api', 'organizations', query_params={ 'name': 'Default' }, host=controller_hostname, username=controller_username, password=controller_password, verify_ssl=false) }}"
- name: "Get the API list of all Projects in the Default Organization" set_fact: controller_api_results: "{{ lookup('awx.awx.controller_api', 'projects', query_params={ 'organization': controller_organization_id.id } ,host=controller_hostname, username=controller_username, password=controller_password, verify_ssl=false) }}"
- name: "Get the API in a list form. Useful for making sure the results of one item is set to a list." set_fact: controller_api_results: "{{ query('awx.awx.controller_api', 'inventories', query_params={ 'organization': controller_organization_id.id } ,host=controller_hostname, username=controller_username, password=controller_password, verify_ssl=false) }}"
- name: "Find the difference of Project between what is on the Controller versus curated list." set_fact: project_difference: "{{ lookup('infra.controller_configuration.controller_object_diff', api_list=controller_api_results, compare_list=differential_item.differential_test_items, with_present=true, set_absent=true ) }}"
- name: Add Projects include_role: name: infra.controller_configuration.projects vars: controller_projects: "{{ project_difference }}"
api_list: description: - The list of objects returned from the controller api. - Requires at least two items in the list elements: dict required: true type: list set_absent: default: true description: - Set state of items not in the compare list to 'absent' type: boolean compare_list: description: - The list of objects to compare the api_list to. elements: dict required: true type: list with_present: default: true description: - Include items in the original compare list in the output, and set state to 'present' type: boolean warn_on_empty_api: default: true description: - If the API list is empty, issue an ansible warning and return the empty list. - This allows the module to be idempotent. - Setting to false will make the lookup error and fail when there is an empty list. type: boolean
_raw: description: - Items that are not in the compare list will only return with Name, Organization, and State. - When set_absent is true, items that are not in the compare list will be set to absent. - When with_present is true items that are not in the compare list with be appended to the compare list. returned: on successful differential type: list