mirror of
https://github.com/ansible/awx.git
synced 2026-03-13 23:17:32 -02:30
Add ability to look up inventory sources by org name/ID
This commit is contained in:
@@ -128,6 +128,10 @@ options:
|
|||||||
- list of notifications to send on error
|
- list of notifications to send on error
|
||||||
type: list
|
type: list
|
||||||
elements: str
|
elements: str
|
||||||
|
organization:
|
||||||
|
description:
|
||||||
|
- Name of organization for project.
|
||||||
|
type: str
|
||||||
extends_documentation_fragment: awx.awx.auth
|
extends_documentation_fragment: awx.awx.auth
|
||||||
'''
|
'''
|
||||||
|
|
||||||
@@ -140,6 +144,7 @@ EXAMPLES = '''
|
|||||||
credential: previously-created-credential
|
credential: previously-created-credential
|
||||||
overwrite: True
|
overwrite: True
|
||||||
update_on_launch: True
|
update_on_launch: True
|
||||||
|
organization: Default
|
||||||
source_vars:
|
source_vars:
|
||||||
private: false
|
private: false
|
||||||
'''
|
'''
|
||||||
@@ -168,6 +173,10 @@ def main():
|
|||||||
enabled_value=dict(),
|
enabled_value=dict(),
|
||||||
host_filter=dict(),
|
host_filter=dict(),
|
||||||
credential=dict(),
|
credential=dict(),
|
||||||
|
source_regions=dict(),
|
||||||
|
instance_filters=dict(),
|
||||||
|
group_by=dict(),
|
||||||
|
organization=dict(),
|
||||||
overwrite=dict(type='bool'),
|
overwrite=dict(type='bool'),
|
||||||
overwrite_vars=dict(type='bool'),
|
overwrite_vars=dict(type='bool'),
|
||||||
custom_virtualenv=dict(),
|
custom_virtualenv=dict(),
|
||||||
@@ -195,6 +204,12 @@ def main():
|
|||||||
source_project = module.params.get('source_project')
|
source_project = module.params.get('source_project')
|
||||||
state = module.params.get('state')
|
state = module.params.get('state')
|
||||||
|
|
||||||
|
new_fields = {}
|
||||||
|
organization_id = None
|
||||||
|
organization = module.params.get('organization')
|
||||||
|
if organization:
|
||||||
|
organization_id = module.get_one_by_name_or_id('organizations', organization)
|
||||||
|
|
||||||
# Attempt to look up inventory source based on the provided name and inventory ID
|
# Attempt to look up inventory source based on the provided name and inventory ID
|
||||||
inventory_id = module.resolve_name_to_id('inventories', inventory)
|
inventory_id = module.resolve_name_to_id('inventories', inventory)
|
||||||
inventory_source = module.get_one('inventory_sources', **{
|
inventory_source = module.get_one('inventory_sources', **{
|
||||||
|
|||||||
@@ -32,6 +32,11 @@ options:
|
|||||||
- The name of the inventory source to update.
|
- The name of the inventory source to update.
|
||||||
required: True
|
required: True
|
||||||
type: str
|
type: str
|
||||||
|
organization:
|
||||||
|
description:
|
||||||
|
- Name of organization for project.
|
||||||
|
type: str
|
||||||
|
required: False
|
||||||
extends_documentation_fragment: awx.awx.auth
|
extends_documentation_fragment: awx.awx.auth
|
||||||
'''
|
'''
|
||||||
|
|
||||||
@@ -40,6 +45,7 @@ EXAMPLES = '''
|
|||||||
tower_inventory_source_update:
|
tower_inventory_source_update:
|
||||||
inventory: "My Inventory"
|
inventory: "My Inventory"
|
||||||
inventory_source: "Example Inventory Source"
|
inventory_source: "Example Inventory Source"
|
||||||
|
organization: Default
|
||||||
|
|
||||||
- name: Update all inventory sources
|
- name: Update all inventory sources
|
||||||
tower_inventory_source_update:
|
tower_inventory_source_update:
|
||||||
@@ -69,6 +75,7 @@ def main():
|
|||||||
argument_spec = dict(
|
argument_spec = dict(
|
||||||
inventory=dict(required=True),
|
inventory=dict(required=True),
|
||||||
inventory_source=dict(required=True),
|
inventory_source=dict(required=True),
|
||||||
|
organization=dict(),
|
||||||
)
|
)
|
||||||
|
|
||||||
# Create a module for ourselves
|
# Create a module for ourselves
|
||||||
@@ -78,6 +85,12 @@ def main():
|
|||||||
inventory = module.params.get('inventory')
|
inventory = module.params.get('inventory')
|
||||||
inventory_source = module.params.get('inventory_source')
|
inventory_source = module.params.get('inventory_source')
|
||||||
|
|
||||||
|
new_fields = {}
|
||||||
|
organization_id = None
|
||||||
|
organization = module.params.get('organization')
|
||||||
|
if organization:
|
||||||
|
organization_id = module.get_one_by_name_or_id('organizations', organization)
|
||||||
|
|
||||||
# Attempt to look up the inventory the user specified (these will fail the module if not found)
|
# Attempt to look up the inventory the user specified (these will fail the module if not found)
|
||||||
inventory_object = module.get_one_by_name_or_id('inventories', inventory)
|
inventory_object = module.get_one_by_name_or_id('inventories', inventory)
|
||||||
# Return all inventory sources related to the specified inventory
|
# Return all inventory sources related to the specified inventory
|
||||||
|
|||||||
@@ -43,7 +43,8 @@ no_api_parameter_ok = {
|
|||||||
# /survey spec is now how we handle associations
|
# /survey spec is now how we handle associations
|
||||||
# We take an organization here to help with the lookups only
|
# We take an organization here to help with the lookups only
|
||||||
'tower_job_template': ['survey_spec', 'organization'],
|
'tower_job_template': ['survey_spec', 'organization'],
|
||||||
# Organization is how we looking job templates
|
'tower_inventory_source': ['organization'],
|
||||||
|
# Organization is how we are looking up job templates
|
||||||
'tower_workflow_job_template_node': ['organization'],
|
'tower_workflow_job_template_node': ['organization'],
|
||||||
# Survey is how we handle associations
|
# Survey is how we handle associations
|
||||||
'tower_workflow_job_template': ['survey'],
|
'tower_workflow_job_template': ['survey'],
|
||||||
|
|||||||
@@ -9,13 +9,20 @@
|
|||||||
inv_name: "AWX-Collection-tests-tower_inventory_source_update-inv-{{ test_id }}"
|
inv_name: "AWX-Collection-tests-tower_inventory_source_update-inv-{{ test_id }}"
|
||||||
inv_source1: "AWX-Collection-tests-tower_inventory_source_update-source1-{{ test_id }}"
|
inv_source1: "AWX-Collection-tests-tower_inventory_source_update-source1-{{ test_id }}"
|
||||||
inv_source2: "AWX-Collection-tests-tower_inventory_source_update-source2-{{ test_id }}"
|
inv_source2: "AWX-Collection-tests-tower_inventory_source_update-source2-{{ test_id }}"
|
||||||
|
org_name: "AWX-Collection-tests-tower_inventory_source_update-org-{{ test_id }}"
|
||||||
|
|
||||||
|
|
||||||
- block:
|
- block:
|
||||||
|
|
||||||
|
- name: "Create a new organization"
|
||||||
|
tower_organization:
|
||||||
|
name: "{{ org_name }}"
|
||||||
|
register: created_org
|
||||||
|
|
||||||
- name: Create a git project without credentials
|
- name: Create a git project without credentials
|
||||||
tower_project:
|
tower_project:
|
||||||
name: "{{ project_name }}"
|
name: "{{ project_name }}"
|
||||||
organization: Default
|
organization: "{{ org_name }}"
|
||||||
scm_type: git
|
scm_type: git
|
||||||
scm_url: https://github.com/ansible/test-playbooks
|
scm_url: https://github.com/ansible/test-playbooks
|
||||||
wait: true
|
wait: true
|
||||||
@@ -23,7 +30,14 @@
|
|||||||
- name: Create an Inventory
|
- name: Create an Inventory
|
||||||
tower_inventory:
|
tower_inventory:
|
||||||
name: "{{ inv_name }}"
|
name: "{{ inv_name }}"
|
||||||
organization: Default
|
organization: "{{ org_name }}"
|
||||||
|
state: present
|
||||||
|
register: created_inventory
|
||||||
|
|
||||||
|
- name: Create another inventory w/ same name
|
||||||
|
tower_inventory:
|
||||||
|
name: "{{ inv_name }}"
|
||||||
|
organization: "{{ org_name }}"
|
||||||
state: present
|
state: present
|
||||||
register: created_inventory
|
register: created_inventory
|
||||||
|
|
||||||
@@ -34,21 +48,24 @@
|
|||||||
source_project: "{{ project_name }}"
|
source_project: "{{ project_name }}"
|
||||||
source_path: inventories/inventory.ini
|
source_path: inventories/inventory.ini
|
||||||
description: Source for Test inventory
|
description: Source for Test inventory
|
||||||
|
organization: "{{ created_org.id }}"
|
||||||
inventory: "{{ inv_name }}"
|
inventory: "{{ inv_name }}"
|
||||||
|
|
||||||
- name: Create Another Inventory Source
|
- name: Create Another Inventory Source (for testing org-based lookup)
|
||||||
tower_inventory_source:
|
tower_inventory_source:
|
||||||
name: "{{ inv_source2 }}"
|
name: "{{ inv_source2 }}"
|
||||||
source: scm
|
source: scm
|
||||||
source_project: "{{ project_name }}"
|
source_project: "{{ project_name }}"
|
||||||
source_path: inventories/create_10_hosts.ini
|
source_path: inventories/create_10_hosts.ini
|
||||||
description: Source for Test inventory
|
description: Source for Test inventory
|
||||||
|
organization: Default
|
||||||
inventory: "{{ inv_name }}"
|
inventory: "{{ inv_name }}"
|
||||||
|
|
||||||
- name: Test Inventory Source Update
|
- name: Test Inventory Source Update
|
||||||
tower_inventory_source_update:
|
tower_inventory_source_update:
|
||||||
inventory: "{{ inv_name }}"
|
inventory: "{{ inv_name }}"
|
||||||
inventory_source: "{{ inv_source1 }}"
|
inventory_source: "{{ inv_source1 }}"
|
||||||
|
organization: Default
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
@@ -59,6 +76,7 @@
|
|||||||
tower_inventory_source_update:
|
tower_inventory_source_update:
|
||||||
inventory: "{{ inv_name }}"
|
inventory: "{{ inv_name }}"
|
||||||
inventory_source: "{{ item }}"
|
inventory_source: "{{ item }}"
|
||||||
|
organization: "{{ created_org.id }}"
|
||||||
loop: "{{ query('awx.awx.tower_api', 'inventory_sources', query_params={ 'inventory': created_inventory.id }, return_ids=True ) }}"
|
loop: "{{ query('awx.awx.tower_api', 'inventory_sources', query_params={ 'inventory': created_inventory.id }, return_ids=True ) }}"
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
@@ -78,3 +96,8 @@
|
|||||||
name: "{{ project_name }}"
|
name: "{{ project_name }}"
|
||||||
organization: Default
|
organization: Default
|
||||||
state: absent
|
state: absent
|
||||||
|
|
||||||
|
- name: "Remove the organization"
|
||||||
|
tower_organization:
|
||||||
|
name: "{{ org_name }}"
|
||||||
|
state: absent
|
||||||
|
|||||||
Reference in New Issue
Block a user