@ -121,6 +121,11 @@ options:
required : false
required : false
version_added : 2.7
version_added : 2.7
choices : [ " EC2 " , " FARGATE " ]
choices : [ " EC2 " , " FARGATE " ]
health_check_grace_period_seconds :
description :
- Seconds to wait before health checking the freshly added / updated services . This option requires botocore > = 1.8 .20 .
required : false
version_added : 2.8
extends_documentation_fragment :
extends_documentation_fragment :
- aws
- aws
- ec2
- ec2
@ -384,7 +389,7 @@ class EcsServiceManager:
def create_service ( self , service_name , cluster_name , task_definition , load_balancers ,
def create_service ( self , service_name , cluster_name , task_definition , load_balancers ,
desired_count , client_token , role , deployment_configuration ,
desired_count , client_token , role , deployment_configuration ,
placement_constraints , placement_strategy , network_configuration ,
placement_constraints , placement_strategy , network_configuration ,
launch_type ):
launch_type , health_check_grace_period_seconds ):
params = dict (
params = dict (
cluster = cluster_name ,
cluster = cluster_name ,
serviceName = service_name ,
serviceName = service_name ,
@ -401,19 +406,24 @@ class EcsServiceManager:
params [ ' networkConfiguration ' ] = network_configuration
params [ ' networkConfiguration ' ] = network_configuration
if launch_type :
if launch_type :
params [ ' launchType ' ] = launch_type
params [ ' launchType ' ] = launch_type
if self . health_check_setable ( params ) and health_check_grace_period_seconds is not None :
params [ ' healthCheckGracePeriodSeconds ' ] = health_check_grace_period_seconds
response = self . ecs . create_service ( * * params )
response = self . ecs . create_service ( * * params )
return self . jsonize ( response [ ' service ' ] )
return self . jsonize ( response [ ' service ' ] )
def update_service ( self , service_name , cluster_name , task_definition ,
def update_service ( self , service_name , cluster_name , task_definition ,
desired_count , deployment_configuration , network_configuration ):
desired_count , deployment_configuration , network_configuration , health_check_grace_period_seconds ):
params = dict (
params = dict (
cluster = cluster_name ,
cluster = cluster_name ,
service = service_name ,
service = service_name ,
taskDefinition = task_definition ,
taskDefinition = task_definition ,
desiredCount = desired_count ,
desiredCount = desired_count ,
deploymentConfiguration = deployment_configuration )
deploymentConfiguration = deployment_configuration
)
if network_configuration :
if network_configuration :
params [ ' networkConfiguration ' ] = network_configuration
params [ ' networkConfiguration ' ] = network_configuration
if self . health_check_setable ( params ) :
params [ ' healthCheckGracePeriodSeconds ' ] = health_check_grace_period_seconds
response = self . ecs . update_service ( * * params )
response = self . ecs . update_service ( * * params )
return self . jsonize ( response [ ' service ' ] )
return self . jsonize ( response [ ' service ' ] )
@ -438,11 +448,15 @@ class EcsServiceManager:
return self . ecs . delete_service ( cluster = cluster , service = service )
return self . ecs . delete_service ( cluster = cluster , service = service )
def ecs_api_handles_network_configuration ( self ) :
def ecs_api_handles_network_configuration ( self ) :
from distutils . version import LooseVersion
# There doesn't seem to be a nice way to inspect botocore to look
# There doesn't seem to be a nice way to inspect botocore to look
# for attributes (and networkConfiguration is not an explicit argument
# for attributes (and networkConfiguration is not an explicit argument
# to e.g. ecs.run_task, it's just passed as a keyword argument)
# to e.g. ecs.run_task, it's just passed as a keyword argument)
return LooseVersion ( botocore . __version__ ) > = LooseVersion ( ' 1.7.44 ' )
return self . module . botocore_at_least ( ' 1.7.44 ' )
def health_check_setable ( self , params ) :
load_balancers = params . get ( ' loadBalancers ' , [ ] )
# check if botocore (and thus boto3) is new enough for using the healthCheckGracePeriodSeconds parameter
return len ( load_balancers ) > 0 and self . module . botocore_at_least ( ' 1.8.20 ' )
def main ( ) :
def main ( ) :
@ -466,7 +480,8 @@ def main():
security_groups = dict ( type = ' list ' ) ,
security_groups = dict ( type = ' list ' ) ,
assign_public_ip = dict ( type = ' bool ' ) ,
assign_public_ip = dict ( type = ' bool ' ) ,
) ) ,
) ) ,
launch_type = dict ( required = False , choices = [ ' EC2 ' , ' FARGATE ' ] )
launch_type = dict ( required = False , choices = [ ' EC2 ' , ' FARGATE ' ] ) ,
health_check_grace_period_seconds = dict ( required = False , type = ' int ' )
) )
) )
module = AnsibleAWSModule ( argument_spec = argument_spec ,
module = AnsibleAWSModule ( argument_spec = argument_spec ,
@ -536,7 +551,9 @@ def main():
module . params [ ' task_definition ' ] ,
module . params [ ' task_definition ' ] ,
module . params [ ' desired_count ' ] ,
module . params [ ' desired_count ' ] ,
deploymentConfiguration ,
deploymentConfiguration ,
network_configuration )
network_configuration ,
module . params [ ' health_check_grace_period_seconds ' ]
)
else :
else :
try :
try :
response = service_mgr . create_service ( module . params [ ' name ' ] ,
response = service_mgr . create_service ( module . params [ ' name ' ] ,
@ -550,7 +567,9 @@ def main():
module . params [ ' placement_constraints ' ] ,
module . params [ ' placement_constraints ' ] ,
module . params [ ' placement_strategy ' ] ,
module . params [ ' placement_strategy ' ] ,
network_configuration ,
network_configuration ,
module . params [ ' launch_type ' ] )
module . params [ ' launch_type ' ] ,
module . params [ ' health_check_grace_period_seconds ' ]
)
except botocore . exceptions . ClientError as e :
except botocore . exceptions . ClientError as e :
module . fail_json_aws ( e , msg = " Couldn ' t create service " )
module . fail_json_aws ( e , msg = " Couldn ' t create service " )