mirror of
https://github.com/ansible/awx.git
synced 2024-10-30 05:25:29 +03:00
Make org an optional parameter for both inv source and inv source update modules
This commit is contained in:
parent
4133ec974b
commit
a0b8f6a25d
@ -131,7 +131,6 @@ options:
|
|||||||
organization:
|
organization:
|
||||||
description:
|
description:
|
||||||
- Name of the inventory source's inventory's organization.
|
- Name of the inventory source's inventory's organization.
|
||||||
required: True
|
|
||||||
type: str
|
type: str
|
||||||
extends_documentation_fragment: awx.awx.auth
|
extends_documentation_fragment: awx.awx.auth
|
||||||
'''
|
'''
|
||||||
@ -174,7 +173,7 @@ def main():
|
|||||||
enabled_value=dict(),
|
enabled_value=dict(),
|
||||||
host_filter=dict(),
|
host_filter=dict(),
|
||||||
credential=dict(),
|
credential=dict(),
|
||||||
organization=dict(required=True),
|
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(),
|
||||||
@ -203,14 +202,10 @@ 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')
|
||||||
|
|
||||||
# Attempt to look up inventory source based on the provided name and inventory ID
|
lookup_data = {'name': inventory}
|
||||||
org_id = module.resolve_name_to_id('organizations', organization)
|
if organization:
|
||||||
inventory_object = module.get_one('inventories', **{
|
lookup_data['organization'] = module.resolve_name_to_id('organizations', organization)
|
||||||
'data': {
|
inventory_object = module.get_one('inventories', data=lookup_data)
|
||||||
'name': inventory,
|
|
||||||
'organization': org_id,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
if not inventory_object:
|
if not inventory_object:
|
||||||
module.fail_json(msg='The specified inventory was not found.')
|
module.fail_json(msg='The specified inventory was not found.')
|
||||||
|
@ -36,7 +36,6 @@ options:
|
|||||||
description:
|
description:
|
||||||
- Name of the inventory source's inventory's organization.
|
- Name of the inventory source's inventory's organization.
|
||||||
type: str
|
type: str
|
||||||
required: True
|
|
||||||
wait:
|
wait:
|
||||||
description:
|
description:
|
||||||
- Wait for the job to complete.
|
- Wait for the job to complete.
|
||||||
@ -91,7 +90,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(required=True),
|
organization=dict(),
|
||||||
wait=dict(default=False, type='bool'),
|
wait=dict(default=False, type='bool'),
|
||||||
interval=dict(default=1.0, type='float'),
|
interval=dict(default=1.0, type='float'),
|
||||||
timeout=dict(default=None, type='int'),
|
timeout=dict(default=None, type='int'),
|
||||||
@ -108,13 +107,10 @@ def main():
|
|||||||
interval = module.params.get('interval')
|
interval = module.params.get('interval')
|
||||||
timeout = module.params.get('timeout')
|
timeout = module.params.get('timeout')
|
||||||
|
|
||||||
org_id = module.resolve_name_to_id('organizations', organization)
|
lookup_data = {'name': inventory}
|
||||||
inventory_object = module.get_one('inventories', **{
|
if organization:
|
||||||
'data': {
|
lookup_data['organization'] = module.resolve_name_to_id('organizations', organization)
|
||||||
'name': inventory,
|
inventory_object = module.get_one('inventories', data=lookup_data)
|
||||||
'organization': org_id,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
if not inventory_object:
|
if not inventory_object:
|
||||||
module.fail_json(msg='The specified inventory was not found.')
|
module.fail_json(msg='The specified inventory was not found.')
|
||||||
|
@ -24,12 +24,11 @@ def project(base_inventory):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_inventory_source_create(run_module, admin_user, base_inventory, project, organization):
|
def test_inventory_source_create(run_module, admin_user, base_inventory, project):
|
||||||
source_path = '/var/lib/awx/example_source_path/'
|
source_path = '/var/lib/awx/example_source_path/'
|
||||||
result = run_module('tower_inventory_source', dict(
|
result = run_module('tower_inventory_source', dict(
|
||||||
name='foo',
|
name='foo',
|
||||||
inventory=base_inventory.name,
|
inventory=base_inventory.name,
|
||||||
organization='test-org',
|
|
||||||
state='present',
|
state='present',
|
||||||
source='scm',
|
source='scm',
|
||||||
source_path=source_path,
|
source_path=source_path,
|
||||||
@ -46,6 +45,30 @@ def test_inventory_source_create(run_module, admin_user, base_inventory, project
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.django_db
|
||||||
|
def test_create_inventory_source_implied_org(run_module, admin_user):
|
||||||
|
org = Organization.objects.create(name='test-org')
|
||||||
|
inv = Inventory.objects.create(name='test-inv', organization=org)
|
||||||
|
|
||||||
|
# Credential is not required for ec2 source, because of IAM roles
|
||||||
|
result = run_module('tower_inventory_source', dict(
|
||||||
|
name='Test Inventory Source',
|
||||||
|
inventory='test-inv',
|
||||||
|
source='ec2',
|
||||||
|
state='present'
|
||||||
|
), admin_user)
|
||||||
|
assert result.pop('changed', None), result
|
||||||
|
|
||||||
|
inv_src = InventorySource.objects.get(name='Test Inventory Source')
|
||||||
|
assert inv_src.inventory == inv
|
||||||
|
|
||||||
|
result.pop('invocation')
|
||||||
|
assert result == {
|
||||||
|
"name": "Test Inventory Source",
|
||||||
|
"id": inv_src.id,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_create_inventory_source_multiple_orgs(run_module, admin_user):
|
def test_create_inventory_source_multiple_orgs(run_module, admin_user):
|
||||||
org = Organization.objects.create(name='test-org')
|
org = Organization.objects.create(name='test-org')
|
||||||
@ -82,7 +105,6 @@ def test_create_inventory_source_with_venv(run_module, admin_user, base_inventor
|
|||||||
result = run_module('tower_inventory_source', dict(
|
result = run_module('tower_inventory_source', dict(
|
||||||
name='foo',
|
name='foo',
|
||||||
inventory=base_inventory.name,
|
inventory=base_inventory.name,
|
||||||
organization='test-org',
|
|
||||||
state='present',
|
state='present',
|
||||||
source='scm',
|
source='scm',
|
||||||
source_project=project.name,
|
source_project=project.name,
|
||||||
@ -99,7 +121,7 @@ def test_create_inventory_source_with_venv(run_module, admin_user, base_inventor
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_custom_venv_no_op(run_module, admin_user, base_inventory, mocker, project, organization):
|
def test_custom_venv_no_op(run_module, admin_user, base_inventory, mocker, project):
|
||||||
"""If the inventory source is modified, then it should not blank fields
|
"""If the inventory source is modified, then it should not blank fields
|
||||||
unrelated to the params that the user passed.
|
unrelated to the params that the user passed.
|
||||||
This enforces assumptions about the behavior of the AnsibleModule
|
This enforces assumptions about the behavior of the AnsibleModule
|
||||||
@ -119,7 +141,6 @@ def test_custom_venv_no_op(run_module, admin_user, base_inventory, mocker, proje
|
|||||||
name='foo',
|
name='foo',
|
||||||
description='this is the changed description',
|
description='this is the changed description',
|
||||||
inventory=base_inventory.name,
|
inventory=base_inventory.name,
|
||||||
organization='test-org',
|
|
||||||
source='scm', # is required, but behavior is arguable
|
source='scm', # is required, but behavior is arguable
|
||||||
state='present',
|
state='present',
|
||||||
source_project=project.name,
|
source_project=project.name,
|
||||||
@ -136,7 +157,6 @@ def test_falsy_value(run_module, admin_user, base_inventory):
|
|||||||
result = run_module('tower_inventory_source', dict(
|
result = run_module('tower_inventory_source', dict(
|
||||||
name='falsy-test',
|
name='falsy-test',
|
||||||
inventory=base_inventory.name,
|
inventory=base_inventory.name,
|
||||||
organization='test-org',
|
|
||||||
source='ec2',
|
source='ec2',
|
||||||
update_on_launch=True
|
update_on_launch=True
|
||||||
), admin_user)
|
), admin_user)
|
||||||
@ -149,7 +169,6 @@ def test_falsy_value(run_module, admin_user, base_inventory):
|
|||||||
result = run_module('tower_inventory_source', dict(
|
result = run_module('tower_inventory_source', dict(
|
||||||
name='falsy-test',
|
name='falsy-test',
|
||||||
inventory=base_inventory.name,
|
inventory=base_inventory.name,
|
||||||
organization='test-org',
|
|
||||||
# source='ec2',
|
# source='ec2',
|
||||||
update_on_launch=False
|
update_on_launch=False
|
||||||
), admin_user)
|
), admin_user)
|
||||||
@ -185,7 +204,6 @@ def test_missing_required_credential(run_module, admin_user, base_inventory):
|
|||||||
result = run_module('tower_inventory_source', dict(
|
result = run_module('tower_inventory_source', dict(
|
||||||
name='Test Azure Source',
|
name='Test Azure Source',
|
||||||
inventory=base_inventory.name,
|
inventory=base_inventory.name,
|
||||||
organization='test-org',
|
|
||||||
source='azure_rm',
|
source='azure_rm',
|
||||||
state='present'
|
state='present'
|
||||||
), admin_user)
|
), admin_user)
|
||||||
@ -199,7 +217,6 @@ def test_source_project_not_for_cloud(run_module, admin_user, base_inventory, pr
|
|||||||
result = run_module('tower_inventory_source', dict(
|
result = run_module('tower_inventory_source', dict(
|
||||||
name='Test ec2 Inventory Source',
|
name='Test ec2 Inventory Source',
|
||||||
inventory=base_inventory.name,
|
inventory=base_inventory.name,
|
||||||
organization='test-org',
|
|
||||||
source='ec2',
|
source='ec2',
|
||||||
state='present',
|
state='present',
|
||||||
source_project=project.name
|
source_project=project.name
|
||||||
@ -214,7 +231,6 @@ def test_source_path_not_for_cloud(run_module, admin_user, base_inventory):
|
|||||||
result = run_module('tower_inventory_source', dict(
|
result = run_module('tower_inventory_source', dict(
|
||||||
name='Test ec2 Inventory Source',
|
name='Test ec2 Inventory Source',
|
||||||
inventory=base_inventory.name,
|
inventory=base_inventory.name,
|
||||||
organization='test-org',
|
|
||||||
source='ec2',
|
source='ec2',
|
||||||
state='present',
|
state='present',
|
||||||
source_path='where/am/I'
|
source_path='where/am/I'
|
||||||
@ -228,7 +244,6 @@ def test_source_path_not_for_cloud(run_module, admin_user, base_inventory):
|
|||||||
def test_scm_source_needs_project(run_module, admin_user, base_inventory):
|
def test_scm_source_needs_project(run_module, admin_user, base_inventory):
|
||||||
result = run_module('tower_inventory_source', dict(
|
result = run_module('tower_inventory_source', dict(
|
||||||
name='SCM inventory without project',
|
name='SCM inventory without project',
|
||||||
organization='test-org',
|
|
||||||
inventory=base_inventory.name,
|
inventory=base_inventory.name,
|
||||||
state='present',
|
state='present',
|
||||||
source='scm',
|
source='scm',
|
||||||
|
@ -31,7 +31,6 @@
|
|||||||
credential: "{{ openstack_cred }}"
|
credential: "{{ openstack_cred }}"
|
||||||
overwrite: true
|
overwrite: true
|
||||||
update_on_launch: true
|
update_on_launch: true
|
||||||
organization: Default
|
|
||||||
source_vars:
|
source_vars:
|
||||||
private: false
|
private: false
|
||||||
source: openstack
|
source: openstack
|
||||||
@ -48,7 +47,6 @@
|
|||||||
credential: "Does Not Exit"
|
credential: "Does Not Exit"
|
||||||
source_project: "Does Not Exist"
|
source_project: "Does Not Exist"
|
||||||
source_script: "Does Not Exist"
|
source_script: "Does Not Exist"
|
||||||
organization: Default
|
|
||||||
state: absent
|
state: absent
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
|
@ -34,14 +34,14 @@
|
|||||||
organization: "{{ org_name }}"
|
organization: "{{ org_name }}"
|
||||||
state: present
|
state: present
|
||||||
|
|
||||||
- name: Create another inventory w/ same name
|
- name: Create another inventory w/ same name, different org
|
||||||
tower_inventory:
|
tower_inventory:
|
||||||
name: "{{ inv_name }}"
|
name: "{{ inv_name }}"
|
||||||
organization: Default
|
organization: Default
|
||||||
state: present
|
state: present
|
||||||
register: created_inventory
|
register: created_inventory
|
||||||
|
|
||||||
- name: Create an Inventory Source
|
- name: Create an Inventory Source (specifically connected to the randomly generated org)
|
||||||
tower_inventory_source:
|
tower_inventory_source:
|
||||||
name: "{{ inv_source1 }}"
|
name: "{{ inv_source1 }}"
|
||||||
source: scm
|
source: scm
|
||||||
@ -51,7 +51,7 @@
|
|||||||
organization: "{{ created_org.id }}"
|
organization: "{{ created_org.id }}"
|
||||||
inventory: "{{ inv_name }}"
|
inventory: "{{ inv_name }}"
|
||||||
|
|
||||||
- name: Create Another Inventory Source (for testing org-based lookup)
|
- name: Create Another Inventory Source
|
||||||
tower_inventory_source:
|
tower_inventory_source:
|
||||||
name: "{{ inv_source2 }}"
|
name: "{{ inv_source2 }}"
|
||||||
source: scm
|
source: scm
|
||||||
@ -61,7 +61,7 @@
|
|||||||
organization: Default
|
organization: Default
|
||||||
inventory: "{{ inv_name }}"
|
inventory: "{{ inv_name }}"
|
||||||
|
|
||||||
- name: Create Yet Another Inventory Source (one more to make lookup plugin find multiple inventory sources)
|
- name: Create Yet Another Inventory Source (to make lookup plugin find multiple inv sources)
|
||||||
tower_inventory_source:
|
tower_inventory_source:
|
||||||
name: "{{ inv_source3 }}"
|
name: "{{ inv_source3 }}"
|
||||||
source: scm
|
source: scm
|
||||||
|
@ -104,7 +104,6 @@ The following notes are changes that may require changes to playbooks:
|
|||||||
- The `notification_configuration` parameter of `tower_notification_template` has changed from a string to a dict. Please use the `lookup` plugin to read an existing file into a dict.
|
- The `notification_configuration` parameter of `tower_notification_template` has changed from a string to a dict. Please use the `lookup` plugin to read an existing file into a dict.
|
||||||
- `tower_credential` no longer supports passing a file name to ssh_key_data.
|
- `tower_credential` no longer supports passing a file name to ssh_key_data.
|
||||||
- The HipChat `notification_type` has been removed and can no longer be created using the `tower_notification_template` module.
|
- The HipChat `notification_type` has been removed and can no longer be created using the `tower_notification_template` module.
|
||||||
- The `tower_inventory_source` module now requires the `organization` parameter in order to specify the inventory source's inventory's organization.
|
|
||||||
|
|
||||||
{% if collection_package | lower() == "awx" %}
|
{% if collection_package | lower() == "awx" %}
|
||||||
## Running Unit Tests
|
## Running Unit Tests
|
||||||
|
Loading…
Reference in New Issue
Block a user