Fill in the new execution environment collection module

as well as changes to other ones that need to be able to attach EEs.
This commit is contained in:
Jeff Bradberry
2020-11-19 14:06:32 -05:00
committed by Shane McDonald
parent c1133b3f6d
commit 6d935f740c
8 changed files with 91 additions and 29 deletions

View File

@@ -14,7 +14,7 @@ from rest_framework.fields import ( # noqa
BooleanField, CharField, ChoiceField, DictField, DateTimeField, EmailField, BooleanField, CharField, ChoiceField, DictField, DateTimeField, EmailField,
IntegerField, ListField, NullBooleanField IntegerField, ListField, NullBooleanField
) )
from rest_framework.serializers import PrimaryKeyRelatedField from rest_framework.serializers import PrimaryKeyRelatedField # noqa
logger = logging.getLogger('awx.conf.fields') logger = logging.getLogger('awx.conf.fields')

View File

@@ -353,7 +353,7 @@ class UnifiedJobTemplate(PolymorphicModel, CommonModelNameNotUnique, ExecutionEn
if self.inventory.organization.default_environment is not None: if self.inventory.organization.default_environment is not None:
return self.inventory.organization.default_environment return self.inventory.organization.default_environment
if settings.DEFAULT_EXECUTION_ENVIRONMENT is not None: if settings.DEFAULT_EXECUTION_ENVIRONMENT is not None:
return settings.DEFAULT_EXECUTION_ENVIRONMENT return settings.DEFAULT_EXECUTION_ENVIRONMENT
return ExecutionEnvironment.objects.filter(organization=None, managed_by_tower=True).first() return ExecutionEnvironment.objects.filter(organization=None, managed_by_tower=True).first()
def create_unified_job(self, **kwargs): def create_unified_job(self, **kwargs):

View File

@@ -22,30 +22,34 @@ description:
- Create, update, or destroy Execution Environments in Ansible Tower. See - Create, update, or destroy Execution Environments in Ansible Tower. See
U(https://www.ansible.com/tower) for an overview. U(https://www.ansible.com/tower) for an overview.
options: options:
name:
description:
- Name to use for the execution environment.
required: True
type: str
image: image:
description: description:
- The fully qualified name of the container image - The fully qualified url of the container image.
required: True required: True
type: str type: str
description:
description:
- Description to use for the execution environment.
type: str
organization:
description:
- The organization the execution environment belongs to.
type: str
credential:
description:
- Name of the credential to use for the execution environment.
type: str
state: state:
description: description:
- Desired state of the resource. - Desired state of the resource.
choices: ["present", "absent"] choices: ["present", "absent"]
default: "present" default: "present"
type: str type: str
credential:
description:
- Name of the credential to use for the job template.
- Deprecated, use 'credentials'.
type: str
description:
description:
- Description to use for the job template.
type: str
organization:
description:
- TODO
type: str
extends_documentation_fragment: awx.awx.auth extends_documentation_fragment: awx.awx.auth
''' '''
@@ -53,6 +57,7 @@ extends_documentation_fragment: awx.awx.auth
EXAMPLES = ''' EXAMPLES = '''
- name: Add EE to Tower - name: Add EE to Tower
tower_execution_environment: tower_execution_environment:
name: "My EE"
image: quay.io/awx/ee image: quay.io/awx/ee
''' '''
@@ -64,22 +69,49 @@ import json
def main(): def main():
# Any additional arguments that are not fields of the item can be added here # Any additional arguments that are not fields of the item can be added here
argument_spec = dict( argument_spec = dict(
name=dict(required=True),
image=dict(required=True), image=dict(required=True),
description=dict(default=''),
organization=dict(),
credential=dict(default=''),
state=dict(choices=['present', 'absent'], default='present'),
) )
# Create a module for ourselves # Create a module for ourselves
module = TowerAPIModule(argument_spec=argument_spec) module = TowerAPIModule(argument_spec=argument_spec)
# Extract our parameters # Extract our parameters
name = module.params.get('name')
image = module.params.get('image') image = module.params.get('image')
description = module.params.get('description')
state = module.params.get('state') state = module.params.get('state')
existing_item = module.get_one('execution_environments', name_or_id=image) existing_item = module.get_one('execution_environments', name_or_id=name)
if state == 'absent': if state == 'absent':
module.delete_if_needed(image) module.delete_if_needed(existing_item)
module.create_or_update_if_needed(existing_item, image, endpoint='execution_environments', item_type='execution_environment') new_fields = {
'name': name,
'image': image,
}
if description:
new_fields['description'] = description
# Attempt to look up the related items the user specified (these will fail the module if not found)
organization = module.params.get('organization')
if organization:
new_fields['organization'] = module.resolve_name_to_id('organizations', organization)
credential = module.params.get('credential')
if credential:
new_fields['credential'] = module.resolve_name_to_id('credentials', credential)
module.create_or_update_if_needed(
existing_item, new_fields,
endpoint='execution_environments',
item_type='execution_environment'
)
if __name__ == '__main__': if __name__ == '__main__':

View File

@@ -177,6 +177,7 @@ def main():
enabled_value=dict(), enabled_value=dict(),
host_filter=dict(), host_filter=dict(),
credential=dict(), credential=dict(),
execution_environment=dict(),
organization=dict(), organization=dict(),
overwrite=dict(type='bool'), overwrite=dict(type='bool'),
overwrite_vars=dict(type='bool'), overwrite_vars=dict(type='bool'),
@@ -203,6 +204,7 @@ def main():
organization = module.params.get('organization') organization = module.params.get('organization')
source_script = module.params.get('source_script') source_script = module.params.get('source_script')
credential = module.params.get('credential') credential = module.params.get('credential')
ee = module.params.get('execution_environment')
source_project = module.params.get('source_project') source_project = module.params.get('source_project')
state = module.params.get('state') state = module.params.get('state')
@@ -254,6 +256,8 @@ def main():
# Attempt to look up the related items the user specified (these will fail the module if not found) # Attempt to look up the related items the user specified (these will fail the module if not found)
if credential is not None: if credential is not None:
inventory_source_fields['credential'] = module.resolve_name_to_id('credentials', credential) inventory_source_fields['credential'] = module.resolve_name_to_id('credentials', credential)
if ee is not None:
inventory_source_fields['execution_environment'] = module.resolve_name_to_id('execution_environments', ee)
if source_project is not None: if source_project is not None:
inventory_source_fields['source_project'] = module.resolve_name_to_id('projects', source_project) inventory_source_fields['source_project'] = module.resolve_name_to_id('projects', source_project)
if source_script is not None: if source_script is not None:

View File

@@ -60,10 +60,6 @@ options:
description: description:
- Path to the playbook to use for the job template within the project provided. - Path to the playbook to use for the job template within the project provided.
type: str type: str
execution_environment:
description:
- Execution Environment to use for the JT.
type: str
credential: credential:
description: description:
- Name of the credential to use for the job template. - Name of the credential to use for the job template.
@@ -79,6 +75,10 @@ options:
- Name of the vault credential to use for the job template. - Name of the vault credential to use for the job template.
- Deprecated, use 'credentials'. - Deprecated, use 'credentials'.
type: str type: str
execution_environment:
description:
- Execution Environment to use for the JT.
type: 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.
@@ -354,6 +354,7 @@ def main():
vault_credential=dict(), vault_credential=dict(),
custom_virtualenv=dict(), custom_virtualenv=dict(),
credentials=dict(type='list', elements='str'), credentials=dict(type='list', elements='str'),
execution_environment=dict(),
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),
@@ -420,7 +421,11 @@ def main():
organization = module.params.get('organization') organization = module.params.get('organization')
if organization: if organization:
organization_id = module.resolve_name_to_id('organizations', organization) organization_id = module.resolve_name_to_id('organizations', organization)
search_fields['organization'] = new_fields['organization'] = organization_id search_fields['organization'] = new_fields['organization'] = organization_id
ee = module.params.get('execution_environment')
if ee:
new_fields['execution_environment'] = module.resolve_name_to_id('execution_environments', ee)
# Attempt to look up an existing item based on the provided data # Attempt to look up an existing item based on the provided data
existing_item = module.get_one('job_templates', name_or_id=name, **{'data': search_fields}) existing_item = module.get_one('job_templates', name_or_id=name, **{'data': search_fields})

View File

@@ -38,7 +38,7 @@ options:
default: '' default: ''
default_environment: default_environment:
description: description:
- Default Execution Environment to use for the Organization. - Default Execution Environment to use for jobs owned by the Organization.
type: str type: str
max_hosts: max_hosts:
description: description:
@@ -114,6 +114,7 @@ def main():
name=dict(required=True), name=dict(required=True),
description=dict(), description=dict(),
custom_virtualenv=dict(), custom_virtualenv=dict(),
default_environment=dict(),
max_hosts=dict(type='int', default="0"), max_hosts=dict(type='int', default="0"),
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'),
@@ -130,6 +131,7 @@ def main():
name = module.params.get('name') name = module.params.get('name')
description = module.params.get('description') description = module.params.get('description')
custom_virtualenv = module.params.get('custom_virtualenv') custom_virtualenv = module.params.get('custom_virtualenv')
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') # instance_group_names = module.params.get('instance_groups')
state = module.params.get('state') state = module.params.get('state')
@@ -179,6 +181,8 @@ def main():
org_fields['description'] = description org_fields['description'] = description
if custom_virtualenv is not None: if custom_virtualenv is not None:
org_fields['custom_virtualenv'] = custom_virtualenv org_fields['custom_virtualenv'] = custom_virtualenv
if default_ee is not None:
org_fields['default_environment'] = module.resolve_name_to_id('execution_environments', default_ee)
if max_hosts is not None: if max_hosts is not None:
org_fields['max_hosts'] = max_hosts org_fields['max_hosts'] = max_hosts

View File

@@ -31,10 +31,6 @@ options:
description: description:
- Description to use for the project. - Description to use for the project.
type: str type: str
execution_environment:
description:
- Execution Environment to use for the project.
type: str
scm_type: scm_type:
description: description:
- Type of SCM resource. - Type of SCM resource.
@@ -106,6 +102,14 @@ options:
- Local absolute file path containing a custom Python virtualenv to use - Local absolute file path containing a custom Python virtualenv to use
type: str type: str
default: '' default: ''
default_environment:
description:
- Default Execution Environment to use for jobs relating to the project.
type: str
execution_environment:
description:
- Execution Environment to use for project updates.
type: str
organization: organization:
description: description:
- Name of organization for project. - Name of organization for project.
@@ -243,6 +247,8 @@ def main():
allow_override=dict(type='bool', aliases=['scm_allow_override']), allow_override=dict(type='bool', aliases=['scm_allow_override']),
timeout=dict(type='int', default=0, aliases=['job_timeout']), timeout=dict(type='int', default=0, aliases=['job_timeout']),
custom_virtualenv=dict(), custom_virtualenv=dict(),
default_environment=dict(),
execution_environment=dict(),
organization=dict(), organization=dict(),
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'),
@@ -274,6 +280,8 @@ def main():
allow_override = module.params.get('allow_override') allow_override = module.params.get('allow_override')
timeout = module.params.get('timeout') timeout = module.params.get('timeout')
custom_virtualenv = module.params.get('custom_virtualenv') custom_virtualenv = module.params.get('custom_virtualenv')
default_ee = module.params.get('default_environment')
ee = module.params.get('execution_environment')
organization = module.params.get('organization') organization = module.params.get('organization')
state = module.params.get('state') state = module.params.get('state')
wait = module.params.get('wait') wait = module.params.get('wait')
@@ -337,6 +345,10 @@ def main():
project_fields['description'] = description project_fields['description'] = description
if credential is not None: if credential is not None:
project_fields['credential'] = credential project_fields['credential'] = credential
if default_ee is not None:
project_fields['default_environment'] = module.resolve_name_to_id('execution_environments', default_ee)
if ee is not None:
project_fields['execution_environment'] = module.resolve_name_to_id('execution_environments', ee)
if allow_override is not None: if allow_override is not None:
project_fields['allow_override'] = allow_override project_fields['allow_override'] = allow_override
if scm_type == '': if scm_type == '':

View File

@@ -175,6 +175,7 @@ def main():
description=dict(), description=dict(),
extra_vars=dict(type='dict'), extra_vars=dict(type='dict'),
organization=dict(), organization=dict(),
execution_environment=dict(),
survey_spec=dict(type='dict', aliases=['survey']), survey_spec=dict(type='dict', aliases=['survey']),
survey_enabled=dict(type='bool'), survey_enabled=dict(type='bool'),
allow_simultaneous=dict(type='bool'), allow_simultaneous=dict(type='bool'),
@@ -212,6 +213,10 @@ def main():
organization_id = module.resolve_name_to_id('organizations', organization) organization_id = module.resolve_name_to_id('organizations', organization)
search_fields['organization'] = new_fields['organization'] = organization_id search_fields['organization'] = new_fields['organization'] = organization_id
ee = module.params.get('execution_environment')
if ee:
new_fields['execution_environment'] = module.resolve_name_to_id('execution_environments', ee)
# Attempt to look up an existing item based on the provided data # Attempt to look up an existing item based on the provided data
existing_item = module.get_one('workflow_job_templates', name_or_id=name, **{'data': search_fields}) existing_item = module.get_one('workflow_job_templates', name_or_id=name, **{'data': search_fields})