mirror of
https://github.com/ansible/awx.git
synced 2026-03-04 02:01:01 -03:30
add instance groups
This commit is contained in:
@@ -61,6 +61,11 @@ options:
|
|||||||
description:
|
description:
|
||||||
- Credentials to be used by hosts belonging to this inventory when accessing Red Hat Insights API.
|
- Credentials to be used by hosts belonging to this inventory when accessing Red Hat Insights API.
|
||||||
type: str
|
type: str
|
||||||
|
instance_groups:
|
||||||
|
description:
|
||||||
|
- list of Instance Groups for this Organization to run on.
|
||||||
|
type: list
|
||||||
|
elements: str
|
||||||
state:
|
state:
|
||||||
description:
|
description:
|
||||||
- Desired state of the resource.
|
- Desired state of the resource.
|
||||||
@@ -104,6 +109,7 @@ def main():
|
|||||||
variables=dict(type='dict'),
|
variables=dict(type='dict'),
|
||||||
kind=dict(choices=['', 'smart'], default=''),
|
kind=dict(choices=['', 'smart'], default=''),
|
||||||
host_filter=dict(),
|
host_filter=dict(),
|
||||||
|
instance_groups=dict(type="list", elements='str'),
|
||||||
insights_credential=dict(),
|
insights_credential=dict(),
|
||||||
state=dict(choices=['present', 'absent'], default='present'),
|
state=dict(choices=['present', 'absent'], default='present'),
|
||||||
)
|
)
|
||||||
@@ -158,12 +164,20 @@ def main():
|
|||||||
if insights_credential is not None:
|
if insights_credential is not None:
|
||||||
inventory_fields['insights_credential'] = module.resolve_name_to_id('credentials', insights_credential)
|
inventory_fields['insights_credential'] = module.resolve_name_to_id('credentials', insights_credential)
|
||||||
|
|
||||||
|
association_fields = {}
|
||||||
|
|
||||||
|
instance_group_names = module.params.get('instance_groups')
|
||||||
|
if instance_group_names is not None:
|
||||||
|
association_fields['instance_groups'] = []
|
||||||
|
for item in instance_group_names:
|
||||||
|
association_fields['instance_groups'].append(module.resolve_name_to_id('instance_groups', item))
|
||||||
|
|
||||||
# We need to perform a check to make sure you are not trying to convert a regular inventory into a smart one.
|
# We need to perform a check to make sure you are not trying to convert a regular inventory into a smart one.
|
||||||
if inventory and inventory['kind'] == '' and inventory_fields['kind'] == 'smart':
|
if inventory and inventory['kind'] == '' and inventory_fields['kind'] == 'smart':
|
||||||
module.fail_json(msg='You cannot turn a regular inventory into a "smart" inventory.')
|
module.fail_json(msg='You cannot turn a regular inventory into a "smart" inventory.')
|
||||||
|
|
||||||
# If the state was present and we can let the module build or update the existing inventory, this will return on its own
|
# If the state was present and we can let the module build or update the existing inventory, this will return on its own
|
||||||
module.create_or_update_if_needed(inventory, inventory_fields, endpoint='inventories', item_type='inventory')
|
module.create_or_update_if_needed(inventory, inventory_fields, endpoint='inventories', item_type='inventory', associations=association_fields,)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
@@ -86,6 +86,11 @@ options:
|
|||||||
description:
|
description:
|
||||||
- Execution Environment to use for the JT.
|
- Execution Environment to use for the JT.
|
||||||
type: str
|
type: str
|
||||||
|
instance_groups:
|
||||||
|
description:
|
||||||
|
- list of Instance Groups for this Organization to run on.
|
||||||
|
type: list
|
||||||
|
elements: str
|
||||||
forks:
|
forks:
|
||||||
description:
|
description:
|
||||||
- The number of parallel or simultaneous processes to use while executing the playbook.
|
- The number of parallel or simultaneous processes to use while executing the playbook.
|
||||||
@@ -366,6 +371,7 @@ def main():
|
|||||||
vault_credential=dict(),
|
vault_credential=dict(),
|
||||||
credentials=dict(type='list', elements='str'),
|
credentials=dict(type='list', elements='str'),
|
||||||
execution_environment=dict(),
|
execution_environment=dict(),
|
||||||
|
instance_groups=dict(type="list", elements='str'),
|
||||||
forks=dict(type='int'),
|
forks=dict(type='int'),
|
||||||
limit=dict(),
|
limit=dict(),
|
||||||
verbosity=dict(type='int', choices=[0, 1, 2, 3, 4], default=0),
|
verbosity=dict(type='int', choices=[0, 1, 2, 3, 4], default=0),
|
||||||
@@ -564,6 +570,12 @@ def main():
|
|||||||
for item in notifications_error:
|
for item in notifications_error:
|
||||||
association_fields['notification_templates_error'].append(module.resolve_name_to_id('notification_templates', item))
|
association_fields['notification_templates_error'].append(module.resolve_name_to_id('notification_templates', item))
|
||||||
|
|
||||||
|
instance_group_names = module.params.get('instance_groups')
|
||||||
|
if instance_group_names is not None:
|
||||||
|
association_fields['instance_groups'] = []
|
||||||
|
for item in instance_group_names:
|
||||||
|
association_fields['instance_groups'].append(module.resolve_name_to_id('instance_groups', item))
|
||||||
|
|
||||||
on_change = None
|
on_change = None
|
||||||
new_spec = module.params.get('survey_spec')
|
new_spec = module.params.get('survey_spec')
|
||||||
if new_spec is not None:
|
if new_spec is not None:
|
||||||
|
|||||||
@@ -45,6 +45,11 @@ options:
|
|||||||
default: "present"
|
default: "present"
|
||||||
choices: ["present", "absent"]
|
choices: ["present", "absent"]
|
||||||
type: str
|
type: str
|
||||||
|
instance_groups:
|
||||||
|
description:
|
||||||
|
- list of Instance Groups for this Organization to run on.
|
||||||
|
type: list
|
||||||
|
elements: str
|
||||||
notification_templates_started:
|
notification_templates_started:
|
||||||
description:
|
description:
|
||||||
- list of notifications to send on start
|
- list of notifications to send on start
|
||||||
@@ -108,6 +113,7 @@ def main():
|
|||||||
description=dict(),
|
description=dict(),
|
||||||
default_environment=dict(),
|
default_environment=dict(),
|
||||||
max_hosts=dict(type='int', default="0"),
|
max_hosts=dict(type='int', default="0"),
|
||||||
|
instance_groups=dict(type="list", elements='str'),
|
||||||
notification_templates_started=dict(type="list", elements='str'),
|
notification_templates_started=dict(type="list", elements='str'),
|
||||||
notification_templates_success=dict(type="list", elements='str'),
|
notification_templates_success=dict(type="list", elements='str'),
|
||||||
notification_templates_error=dict(type="list", elements='str'),
|
notification_templates_error=dict(type="list", elements='str'),
|
||||||
@@ -124,7 +130,6 @@ def main():
|
|||||||
description = module.params.get('description')
|
description = module.params.get('description')
|
||||||
default_ee = module.params.get('default_environment')
|
default_ee = module.params.get('default_environment')
|
||||||
max_hosts = module.params.get('max_hosts')
|
max_hosts = module.params.get('max_hosts')
|
||||||
# instance_group_names = module.params.get('instance_groups')
|
|
||||||
state = module.params.get('state')
|
state = module.params.get('state')
|
||||||
|
|
||||||
# Attempt to look up organization based on the provided name
|
# Attempt to look up organization based on the provided name
|
||||||
@@ -136,6 +141,12 @@ def main():
|
|||||||
# Attempt to look up associated field items the user specified.
|
# Attempt to look up associated field items the user specified.
|
||||||
association_fields = {}
|
association_fields = {}
|
||||||
|
|
||||||
|
instance_group_names = module.params.get('instance_groups')
|
||||||
|
if instance_group_names is not None:
|
||||||
|
association_fields['instance_groups'] = []
|
||||||
|
for item in instance_group_names:
|
||||||
|
association_fields['instance_groups'].append(module.resolve_name_to_id('instance_groups', item))
|
||||||
|
|
||||||
notifications_start = module.params.get('notification_templates_started')
|
notifications_start = module.params.get('notification_templates_started')
|
||||||
if notifications_start is not None:
|
if notifications_start is not None:
|
||||||
association_fields['notification_templates_started'] = []
|
association_fields['notification_templates_started'] = []
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
inv_name1: "AWX-Collection-tests-tower_inventory-inv1-{{ test_id }}"
|
inv_name1: "AWX-Collection-tests-tower_inventory-inv1-{{ test_id }}"
|
||||||
inv_name2: "AWX-Collection-tests-tower_inventory-inv2-{{ test_id }}"
|
inv_name2: "AWX-Collection-tests-tower_inventory-inv2-{{ test_id }}"
|
||||||
cred_name1: "AWX-Collection-tests-tower_inventory-cred1-{{ test_id }}"
|
cred_name1: "AWX-Collection-tests-tower_inventory-cred1-{{ test_id }}"
|
||||||
|
group_name1: "AWX-Collection-tests-tower_instance_group-group1-{{ test_id }}"
|
||||||
|
|
||||||
- block:
|
- block:
|
||||||
- name: Create an Insights Credential
|
- name: Create an Insights Credential
|
||||||
@@ -25,17 +26,30 @@
|
|||||||
that:
|
that:
|
||||||
- "result is changed"
|
- "result is changed"
|
||||||
|
|
||||||
- name: Create an Inventory
|
- name: Create an Instance Group
|
||||||
tower_inventory:
|
tower_instance_group:
|
||||||
name: "{{ inv_name1 }}"
|
name: "{{ group_name1 }}"
|
||||||
organization: Default
|
|
||||||
insights_credential: "{{ result.id }}"
|
|
||||||
state: present
|
state: present
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- "result is changed"
|
- "result is changed"
|
||||||
|
|
||||||
|
- name: Create an Inventory
|
||||||
|
tower_inventory:
|
||||||
|
name: "{{ inv_name1 }}"
|
||||||
|
organization: Default
|
||||||
|
insights_credential: "{{ result.id }}"
|
||||||
|
instance_groups:
|
||||||
|
- "{{ group_name1 }}"
|
||||||
|
state: present
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- "result is changed"
|
||||||
|
|
||||||
- name: Test Inventory module idempotency
|
- name: Test Inventory module idempotency
|
||||||
tower_inventory:
|
tower_inventory:
|
||||||
name: "{{ result.id }}"
|
name: "{{ result.id }}"
|
||||||
@@ -158,6 +172,11 @@
|
|||||||
- "{{ inv_name2 }}"
|
- "{{ inv_name2 }}"
|
||||||
- "copy_{{ inv_name1 }}"
|
- "copy_{{ inv_name1 }}"
|
||||||
|
|
||||||
|
- name: Delete the instance groups
|
||||||
|
tower_instance_group:
|
||||||
|
name: "{{ group_name1 }}"
|
||||||
|
state: absent
|
||||||
|
|
||||||
- name: Delete Insights Credential
|
- name: Delete Insights Credential
|
||||||
tower_credential:
|
tower_credential:
|
||||||
name: "{{ cred_name1 }}"
|
name: "{{ cred_name1 }}"
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
lab1: "AWX-Collection-tests-tower_job_template-lab1-{{ test_id }}"
|
lab1: "AWX-Collection-tests-tower_job_template-lab1-{{ test_id }}"
|
||||||
email_not: "AWX-Collection-tests-tower_job_template-email-not-{{ test_id }}"
|
email_not: "AWX-Collection-tests-tower_job_template-email-not-{{ test_id }}"
|
||||||
webhook_not: "AWX-Collection-tests-tower_notification_template-wehbook-not-{{ test_id }}"
|
webhook_not: "AWX-Collection-tests-tower_notification_template-wehbook-not-{{ test_id }}"
|
||||||
|
group_name1: "AWX-Collection-tests-tower_instance_group-group1-{{ test_id }}"
|
||||||
|
|
||||||
- name: Create a Demo Project
|
- name: Create a Demo Project
|
||||||
tower_project:
|
tower_project:
|
||||||
@@ -48,6 +49,16 @@
|
|||||||
name: "{{ lab1 }}"
|
name: "{{ lab1 }}"
|
||||||
organization: Default
|
organization: Default
|
||||||
|
|
||||||
|
- name: Create an Instance Group
|
||||||
|
tower_instance_group:
|
||||||
|
name: "{{ group_name1 }}"
|
||||||
|
state: present
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- "result is changed"
|
||||||
|
|
||||||
- name: Add email notification
|
- name: Add email notification
|
||||||
tower_notification_template:
|
tower_notification_template:
|
||||||
name: "{{ email_not }}"
|
name: "{{ email_not }}"
|
||||||
@@ -81,7 +92,11 @@
|
|||||||
project: "{{ proj1 }}"
|
project: "{{ proj1 }}"
|
||||||
inventory: Demo Inventory
|
inventory: Demo Inventory
|
||||||
playbook: hello_world.yml
|
playbook: hello_world.yml
|
||||||
credentials: ["{{ cred1 }}", "{{ cred2 }}"]
|
credentials:
|
||||||
|
- "{{ cred1 }}"
|
||||||
|
- "{{ cred2 }}"
|
||||||
|
instance_groups:
|
||||||
|
- "{{ group_name1 }}"
|
||||||
job_type: run
|
job_type: run
|
||||||
state: present
|
state: present
|
||||||
register: jt1_result
|
register: jt1_result
|
||||||
@@ -384,6 +399,11 @@
|
|||||||
organization: Default
|
organization: Default
|
||||||
state: absent
|
state: absent
|
||||||
|
|
||||||
|
- name: Delete the instance groups
|
||||||
|
tower_instance_group:
|
||||||
|
name: "{{ group_name1 }}"
|
||||||
|
state: absent
|
||||||
|
|
||||||
- name: Delete webhook notification
|
- name: Delete webhook notification
|
||||||
tower_notification_template:
|
tower_notification_template:
|
||||||
name: "{{ webhook_not }}"
|
name: "{{ webhook_not }}"
|
||||||
|
|||||||
@@ -1,7 +1,12 @@
|
|||||||
---
|
---
|
||||||
|
- name: Generate a test ID
|
||||||
|
set_fact:
|
||||||
|
test_id: "{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
|
||||||
|
|
||||||
- name: Generate an org name
|
- name: Generate an org name
|
||||||
set_fact:
|
set_fact:
|
||||||
org_name: "AWX-Collection-tests-tower_organization-org-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
|
org_name: "AWX-Collection-tests-tower_organization-org-{{ test_id }}"
|
||||||
|
group_name1: "AWX-Collection-tests-tower_instance_group-group1-{{ test_id }}"
|
||||||
|
|
||||||
- name: Make sure {{ org_name }} is not there
|
- name: Make sure {{ org_name }} is not there
|
||||||
tower_organization:
|
tower_organization:
|
||||||
@@ -28,10 +33,22 @@
|
|||||||
that:
|
that:
|
||||||
- "result is not changed"
|
- "result is not changed"
|
||||||
|
|
||||||
|
- name: Create an Instance Group
|
||||||
|
tower_instance_group:
|
||||||
|
name: "{{ group_name1 }}"
|
||||||
|
state: present
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- "result is changed"
|
||||||
|
|
||||||
- name: "Pass in all parameters"
|
- name: "Pass in all parameters"
|
||||||
tower_organization:
|
tower_organization:
|
||||||
name: "{{ org_name }}"
|
name: "{{ org_name }}"
|
||||||
description: "A description"
|
description: "A description"
|
||||||
|
instance_groups:
|
||||||
|
- "{{ group_name1 }}"
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
@@ -48,6 +65,11 @@
|
|||||||
that:
|
that:
|
||||||
- "result is changed"
|
- "result is changed"
|
||||||
|
|
||||||
|
- name: Delete the instance groups
|
||||||
|
tower_instance_group:
|
||||||
|
name: "{{ group_name1 }}"
|
||||||
|
state: absent
|
||||||
|
|
||||||
- name: "Remove the organization"
|
- name: "Remove the organization"
|
||||||
tower_organization:
|
tower_organization:
|
||||||
name: "{{ org_name }}"
|
name: "{{ org_name }}"
|
||||||
|
|||||||
Reference in New Issue
Block a user