Skip to content

Commit

Permalink
Merge pull request #1 from falsedlah/launch_template
Browse files Browse the repository at this point in the history
add launch template to batch compute environment
  • Loading branch information
falsedlah authored Sep 20, 2021
2 parents 807bf51 + 9b177c1 commit 3d74527
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion plugins/modules/aws_batch_compute_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@
description:
- The Amazon Resource Name (ARN) of the Amazon EC2 Spot Fleet IAM role applied to a SPOT compute environment.
type: str
launch_template:
description:
- The Name/id and version of the launch template to use for the compute resources.
type: dict
requirements:
- boto3
Expand Down Expand Up @@ -152,6 +156,9 @@
tag1: value1
tag2: value2
service_role: arn:aws:iam::<account>:role/service-role/<role>
launch_template:
launch_template_name: batch_launch_template_example
version: 1
register: aws_batch_compute_environment_action
- name: show results
Expand Down Expand Up @@ -198,6 +205,9 @@
Environment: <name>
Name: <name>
type: MANAGED
launch_template:
launch_template_name: batch_launch_template_example
version: 1
validate_certs: true
response:
computeEnvironmentArn: "arn:aws:batch:...."
Expand All @@ -223,6 +233,9 @@
status: VALID
statusReason: "ComputeEnvironment Healthy"
type: MANAGED
launcTemplate:
launchTemplateTame: batch_launch_template_example
version: 1
type: dict
'''

Expand Down Expand Up @@ -318,7 +331,7 @@ def create_compute_environment(module, client):

compute_resources_param_list = ('minv_cpus', 'maxv_cpus', 'desiredv_cpus', 'instance_types', 'image_id', 'subnets',
'security_group_ids', 'ec2_key_pair', 'instance_role', 'tags', 'bid_percentage',
'spot_iam_fleet_role')
'spot_iam_fleet_role','launch_template')
compute_resources_params = set_api_params(module, compute_resources_param_list)

if module.params['compute_resource_type'] is not None:
Expand Down Expand Up @@ -372,6 +385,7 @@ def manage_state(module, client):
minv_cpus = module.params['minv_cpus']
maxv_cpus = module.params['maxv_cpus']
desiredv_cpus = module.params['desiredv_cpus']
launch_template = snake_dict_to_camel_dict(module.params['launch_template'])
action_taken = 'none'
update_env_response = ''

Expand All @@ -391,6 +405,9 @@ def manage_state(module, client):

# Update configuration if needed
compute_resources = {}
if current_compute_environment['computeResources']['launchTemplate'] != launch_template:
module.fail_json(msg="""Batch doesn't support updating a compute environment with a new launch template version.
If you update your launch template, you must create a new compute environment with the new template""")
if compute_environment_state and current_compute_environment['state'] != compute_environment_state:
compute_kwargs.update({'state': compute_environment_state})
updates = True
Expand Down Expand Up @@ -465,6 +482,7 @@ def main():
tags=dict(type='dict'),
bid_percentage=dict(type='int'),
spot_iam_fleet_role=dict(),
launch_template=dict(type='dict'),
)

module = AnsibleAWSModule(
Expand Down

0 comments on commit 3d74527

Please sign in to comment.