This commit is contained in:
sean-m-ssullivan
2021-03-08 10:18:34 -06:00
319 changed files with 5031 additions and 9733 deletions

View File

@@ -28,6 +28,11 @@ options:
- Job_type to use for the ad hoc command.
type: str
choices: [ 'run', 'check' ]
execution_environment:
description:
- Execution Environment to use for the ad hoc command.
required: False
type: str
inventory:
description:
- Inventory to use for the ad hoc command.
@@ -127,6 +132,7 @@ def main():
wait=dict(default=False, type='bool'),
interval=dict(default=1.0, type='float'),
timeout=dict(default=None, type='int'),
execution_environment=dict(),
)
# Create a module for ourselves

View File

@@ -0,0 +1,129 @@
#!/usr/bin/python
# coding: utf-8 -*-
# (c) 2020, Shane McDonald <shanemcd@redhat.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'}
DOCUMENTATION = '''
---
module: tower_execution_environment
author: "Shane McDonald (@shanemcd)"
short_description: create, update, or destroy Execution Environments in Ansible Tower.
description:
- Create, update, or destroy Execution Environments in Ansible Tower. See
U(https://www.ansible.com/tower) for an overview.
options:
name:
description:
- Name to use for the execution environment.
required: True
type: str
image:
description:
- The fully qualified url of the container image.
required: True
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:
description:
- Desired state of the resource.
choices: ["present", "absent"]
default: "present"
type: str
pull:
description:
- determine image pull behavior
choices: ["always", "missing", "never"]
default: 'missing'
type: str
extends_documentation_fragment: awx.awx.auth
'''
EXAMPLES = '''
- name: Add EE to Tower
tower_execution_environment:
name: "My EE"
image: quay.io/ansible/awx-ee
'''
from ..module_utils.tower_api import TowerAPIModule
import json
def main():
# Any additional arguments that are not fields of the item can be added here
argument_spec = dict(
name=dict(required=True),
image=dict(required=True),
description=dict(default=''),
organization=dict(),
credential=dict(default=''),
state=dict(choices=['present', 'absent'], default='present'),
pull=dict(choices=['always', 'missing', 'never'], default='missing')
)
# Create a module for ourselves
module = TowerAPIModule(argument_spec=argument_spec)
# Extract our parameters
name = module.params.get('name')
image = module.params.get('image')
description = module.params.get('description')
state = module.params.get('state')
pull = module.params.get('pull')
existing_item = module.get_one('execution_environments', name_or_id=name)
if state == 'absent':
module.delete_if_needed(existing_item)
new_fields = {
'name': name,
'image': image,
}
if description:
new_fields['description'] = description
if pull:
new_fields['pull'] = pull
# 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__':
main()

View File

@@ -47,6 +47,10 @@ options:
description:
- credential name to export
type: str
execution_environments:
description:
- execution environment name to export
type: str
notification_templates:
description:
- notification template name to export

View File

@@ -73,6 +73,10 @@ options:
description:
- Credential to use for the source.
type: str
execution_environment:
description:
- Execution Environment to use for the source.
type: str
overwrite:
description:
- Delete child groups and hosts not found in source.
@@ -81,10 +85,6 @@ options:
description:
- Override vars in child groups and hosts with those from external source.
type: bool
custom_virtualenv:
description:
- Local absolute file path containing a custom Python virtualenv to use.
type: str
timeout:
description: The amount of time (in seconds) to run before the task is canceled.
type: int
@@ -173,10 +173,10 @@ def main():
enabled_value=dict(),
host_filter=dict(),
credential=dict(),
execution_environment=dict(),
organization=dict(),
overwrite=dict(type='bool'),
overwrite_vars=dict(type='bool'),
custom_virtualenv=dict(),
timeout=dict(type='int'),
verbosity=dict(type='int', choices=[0, 1, 2]),
update_on_launch=dict(type='bool'),
@@ -199,6 +199,7 @@ def main():
organization = module.params.get('organization')
source_script = module.params.get('source_script')
credential = module.params.get('credential')
ee = module.params.get('execution_environment')
source_project = module.params.get('source_project')
state = module.params.get('state')
@@ -250,6 +251,8 @@ def main():
# Attempt to look up the related items the user specified (these will fail the module if not found)
if credential is not None:
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:
inventory_source_fields['source_project'] = module.resolve_name_to_id('projects', source_project)
if source_script is not None:
@@ -257,7 +260,7 @@ def main():
OPTIONAL_VARS = (
'description', 'source', 'source_path', 'source_vars',
'overwrite', 'overwrite_vars', 'custom_virtualenv',
'overwrite', 'overwrite_vars',
'timeout', 'verbosity', 'update_on_launch', 'update_cache_timeout',
'update_on_project_update', 'enabled_var', 'enabled_value', 'host_filter',
)

View File

@@ -83,6 +83,10 @@ options:
- Name of the vault credential to use for the job template.
- Deprecated, use 'credentials'.
type: str
execution_environment:
description:
- Execution Environment to use for the JT.
type: str
forks:
description:
- The number of parallel or simultaneous processes to use while executing the playbook.
@@ -231,10 +235,6 @@ options:
description:
- Maximum time in seconds to wait for a job to finish (server-side).
type: int
custom_virtualenv:
description:
- Local absolute file path containing a custom Python virtualenv to use.
type: str
job_slice_count:
description:
- The number of jobs to slice into at runtime. Will cause the Job Template to launch a workflow if value is greater than 1.
@@ -308,7 +308,6 @@ EXAMPLES = '''
tower_config_file: "~/tower_cli.cfg"
survey_enabled: yes
survey_spec: "{{ lookup('file', 'my_survey.json') }}"
custom_virtualenv: "/var/lib/awx/venv/custom-venv/"
- name: Add start notification to Job Template
tower_job_template:
@@ -366,8 +365,8 @@ def main():
playbook=dict(),
credential=dict(),
vault_credential=dict(),
custom_virtualenv=dict(),
credentials=dict(type='list', elements='str'),
execution_environment=dict(),
forks=dict(type='int'),
limit=dict(),
verbosity=dict(type='int', choices=[0, 1, 2, 3, 4], default=0),
@@ -437,6 +436,10 @@ def main():
organization_id = module.resolve_name_to_id('organizations', organization)
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
existing_item = module.get_one('job_templates', name_or_id=name, **{'data': search_fields})
@@ -460,7 +463,7 @@ def main():
'host_config_key', 'ask_scm_branch_on_launch', 'ask_diff_mode_on_launch', 'ask_variables_on_launch',
'ask_limit_on_launch', 'ask_tags_on_launch', 'ask_skip_tags_on_launch', 'ask_job_type_on_launch',
'ask_verbosity_on_launch', 'ask_inventory_on_launch', 'ask_credential_on_launch', 'survey_enabled',
'become_enabled', 'diff_mode', 'allow_simultaneous', 'custom_virtualenv', 'job_slice_count', 'webhook_service',
'become_enabled', 'diff_mode', 'allow_simultaneous', 'job_slice_count', 'webhook_service',
):
field_val = module.params.get(field_name)
if field_val is not None:

View File

@@ -31,11 +31,10 @@ options:
description:
- The description to use for the organization.
type: str
custom_virtualenv:
default_environment:
description:
- Local absolute file path containing a custom Python virtualenv to use.
- Default Execution Environment to use for jobs owned by the Organization.
type: str
default: ''
max_hosts:
description:
- The max hosts allowed in this organizations
@@ -88,7 +87,6 @@ EXAMPLES = '''
tower_organization:
name: "Foo"
description: "Foo bar organization using foo-venv"
custom_virtualenv: "/var/lib/awx/venv/foo-venv/"
state: present
tower_config_file: "~/tower_cli.cfg"
@@ -109,7 +107,7 @@ def main():
argument_spec = dict(
name=dict(required=True),
description=dict(),
custom_virtualenv=dict(),
default_environment=dict(),
max_hosts=dict(type='int', default="0"),
notification_templates_started=dict(type="list", elements='str'),
notification_templates_success=dict(type="list", elements='str'),
@@ -125,7 +123,7 @@ def main():
# Extract our parameters
name = module.params.get('name')
description = module.params.get('description')
custom_virtualenv = module.params.get('custom_virtualenv')
default_ee = module.params.get('default_environment')
max_hosts = module.params.get('max_hosts')
# instance_group_names = module.params.get('instance_groups')
state = module.params.get('state')
@@ -173,8 +171,8 @@ def main():
org_fields = {'name': module.get_item_name(organization) if organization else name}
if description is not None:
org_fields['description'] = description
if custom_virtualenv is not None:
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:
org_fields['max_hosts'] = max_hosts

View File

@@ -105,11 +105,10 @@ options:
type: int
aliases:
- job_timeout
custom_virtualenv:
default_environment:
description:
- Local absolute file path containing a custom Python virtualenv to use
- Default Execution Environment to use for jobs relating to the project.
type: str
default: ''
organization:
description:
- Name of organization for project.
@@ -169,14 +168,13 @@ EXAMPLES = '''
state: present
tower_config_file: "~/tower_cli.cfg"
- name: Add Tower Project with cache timeout and custom virtualenv
- name: Add Tower Project with cache timeout
tower_project:
name: "Foo"
description: "Foo bar project"
organization: "test"
scm_update_on_launch: True
scm_update_cache_timeout: 60
custom_virtualenv: "/var/lib/awx/var/lib/awx/venv/ansible-2.2"
state: present
tower_config_file: "~/tower_cli.cfg"
@@ -255,7 +253,7 @@ def main():
scm_update_cache_timeout=dict(type='int', default=0),
allow_override=dict(type='bool', aliases=['scm_allow_override']),
timeout=dict(type='int', default=0, aliases=['job_timeout']),
custom_virtualenv=dict(),
default_environment=dict(),
organization=dict(),
notification_templates_started=dict(type="list", elements='str'),
notification_templates_success=dict(type="list", elements='str'),
@@ -279,6 +277,7 @@ def main():
credential = module.params.get('credential')
scm_update_on_launch = module.params.get('scm_update_on_launch')
scm_update_cache_timeout = module.params.get('scm_update_cache_timeout')
default_ee = module.params.get('default_environment')
organization = module.params.get('organization')
state = module.params.get('state')
wait = module.params.get('wait')
@@ -336,6 +335,8 @@ def main():
'name': module.get_item_name(project) if project else name,
'scm_type': scm_type,
'organization': org_id,
'scm_update_on_launch': scm_update_on_launch,
'scm_update_cache_timeout': scm_update_cache_timeout,
}
for field_name in (
@@ -349,6 +350,8 @@ def main():
if credential is not None:
project_fields['credential'] = credential
if default_ee is not None:
project_fields['default_environment'] = module.resolve_name_to_id('execution_environments', default_ee)
if scm_type == '':
if local_path is not None:
project_fields['local_path'] = local_path

View File

@@ -48,6 +48,10 @@ options:
description:
- Variables which will be made available to jobs ran inside the workflow.
type: dict
execution_environment:
description:
- Execution Environment to use for the WFJT.
type: str
organization:
description:
- Organization the workflow job template exists in.
@@ -186,6 +190,7 @@ def main():
description=dict(),
extra_vars=dict(type='dict'),
organization=dict(),
execution_environment=dict(),
survey_spec=dict(type='dict', aliases=['survey']),
survey_enabled=dict(type='bool'),
allow_simultaneous=dict(type='bool'),
@@ -224,6 +229,10 @@ def main():
organization_id = module.resolve_name_to_id('organizations', organization)
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
existing_item = module.get_one('workflow_job_templates', name_or_id=name, **{'data': search_fields})