388
388
- Wether the instance tags are availble (V(enabled)) via metadata endpoint or not (V(disabled)).
389
389
choices: [enabled, disabled]
390
390
default: 'disabled'
391
- notes:
392
- - Support for O(purge_tags) was added in release 8.1.0.
391
+ template_tags:
392
+ description:
393
+ - A dictionary representing the tags to be applied to the launch template.
394
+ - If the O(template_tags) parameter is not set then tags will not be modified.
395
+ type: dict
396
+ required: false
397
+ purge_template_tags:
398
+ description:
399
+ - If O(purge_template_tags=true) and O(template_tags) is set, existing tags will be purged
400
+ from the resource to match exactly what is defined by O(template_tags) parameter.
401
+ - If the O(template_tags) parameter is not set then tags will not be modified, even
402
+ if O(purge_template_tags=True).
403
+ - Tag keys beginning with V(aws:) are reserved by Amazon and can not be
404
+ modified. As such they will be ignored for the purposes of the
405
+ O(purge_template_tags) parameter. See the Amazon documentation for more information
406
+ U(https://docs.aws.amazon.com/general/latest/gr/aws_tagging.html#tag-conventions).
407
+ type: bool
408
+ default: true
409
+ required: false
393
410
extends_documentation_fragment:
394
411
- amazon.aws.common.modules
395
412
- amazon.aws.region.modules
396
413
- amazon.aws.boto3
397
- - amazon.aws.tags
398
414
"""
399
415
400
416
EXAMPLES = r"""
701
717
from ansible_collections .amazon .aws .plugins .module_utils .ec2 import determine_iam_arn_from_name
702
718
from ansible_collections .amazon .aws .plugins .module_utils .ec2 import ensure_ec2_tags
703
719
from ansible_collections .amazon .aws .plugins .module_utils .ec2 import modify_launch_template
704
- from ansible_collections .amazon .aws .plugins .module_utils .exceptions import is_ansible_aws_error_code
705
720
from ansible_collections .amazon .aws .plugins .module_utils .exceptions import AnsibleAWSError
721
+ from ansible_collections .amazon .aws .plugins .module_utils .exceptions import is_ansible_aws_error_code
722
+ from ansible_collections .amazon .aws .plugins .module_utils .tagging import ansible_dict_to_boto3_tag_list
706
723
from ansible_collections .amazon .aws .plugins .module_utils .tagging import boto3_tag_list_to_ansible_dict
707
724
from ansible_collections .amazon .aws .plugins .module_utils .transformation import scrub_none_parameters
708
725
@@ -742,6 +759,12 @@ def find_existing(client, module: AnsibleAWSModule) -> Tuple[Optional[Dict[str,
742
759
def params_to_launch_data (
743
760
template_params : Dict [str , Any ], iam_instance_profile_arn : Optional [str ] = None
744
761
) -> Dict [str , Any ]:
762
+ if template_params .get ("tags" ):
763
+ tag_list = ansible_dict_to_boto3_tag_list (template_params .get ("tags" ))
764
+ template_params ["tag_specifications" ] = [
765
+ {"resource_type" : r_type , "tags" : tag_list } for r_type in ("instance" , "volume" )
766
+ ]
767
+ del template_params ["tags" ]
745
768
if iam_instance_profile_arn :
746
769
template_params ["iam_instance_profile" ] = {"arn" : iam_instance_profile_arn }
747
770
for interface in template_params .get ("network_interfaces" ) or []:
@@ -801,7 +824,7 @@ def validate_version_deletion(
801
824
802
825
if default_version_to_set and default_version_to_set not in remaining_versions :
803
826
module .fail_json (
804
- msg = f"Could not set version '{ default_version_to_set } ' as default,"
827
+ msg = f"Could not set version '{ default_version_to_set } ' as default, "
805
828
"the launch template version was not found for the specified launch template id '{launch_template_id}'."
806
829
)
807
830
else :
@@ -967,8 +990,8 @@ def ensure_present(
967
990
existing_versions : List [Dict [str , Any ]],
968
991
) -> None :
969
992
template_name = module .params ["template_name" ]
970
- tags = module .params ["tags " ]
971
- purge_tags = module .params ["purge_tags " ]
993
+ template_tags = module .params ["template_tags " ]
994
+ purge_template_tags = module .params ["purge_template_tags " ]
972
995
version_description = module .params .get ("version_description" )
973
996
iam_instance_profile = module .params .get ("iam_instance_profile" )
974
997
if iam_instance_profile :
@@ -988,7 +1011,7 @@ def ensure_present(
988
1011
client ,
989
1012
launch_template_name = template_name ,
990
1013
launch_template_data = launch_template_data ,
991
- tags = tags ,
1014
+ tags = template_tags ,
992
1015
ClientToken = uuid4 ().hex ,
993
1016
VersionDescription = version_description ,
994
1017
)
@@ -1020,7 +1043,12 @@ def ensure_present(
1020
1043
)
1021
1044
# Ensure tags
1022
1045
changed |= ensure_ec2_tags (
1023
- client , module , launch_template_id , resource_type = "launch-template" , tags = tags , purge_tags = purge_tags
1046
+ client ,
1047
+ module ,
1048
+ launch_template_id ,
1049
+ resource_type = "launch-template" ,
1050
+ tags = template_tags ,
1051
+ purge_tags = purge_template_tags ,
1024
1052
)
1025
1053
1026
1054
module .exit_json (changed = changed , ** format_module_output (client , module ))
@@ -1132,6 +1160,7 @@ def main():
1132
1160
ram_disk_id = dict (),
1133
1161
security_group_ids = dict (type = "list" , elements = "str" ),
1134
1162
security_groups = dict (type = "list" , elements = "str" ),
1163
+ tags = dict (type = "dict" , aliases = ["resource_tags" ]),
1135
1164
user_data = dict (),
1136
1165
)
1137
1166
@@ -1143,8 +1172,8 @@ def main():
1143
1172
source_version = dict (default = "latest" ),
1144
1173
version_description = dict (default = "" ),
1145
1174
iam_instance_profile = dict (),
1146
- tags = dict (type = "dict" , aliases = [ "resource_tags" ] ),
1147
- purge_tags = dict (type = "bool" , default = True ),
1175
+ template_tags = dict (type = "dict" ),
1176
+ purge_template_tags = dict (type = "bool" , default = True ),
1148
1177
versions_to_delete = dict (type = "list" , elements = "int" ),
1149
1178
)
1150
1179
0 commit comments