'Create AWS SSM AnsibelePlaybook Provide using CDK

I am trying to create an AnsibelePlaybook Provide using CDK and AWS SSM. The Association would need to sets:

  • S3 bucket
  • ansible-playbook file
  • ansible extra-vars
  • target selection
  • output options

Does anyone have (or direct me to) "template" so i could easily convert it with my values ​​achieve above requirements.

I am newbie in AWS. :) Thank you



Solution 1:[1]

I figure it out. This is what I was looking for:

ssm_association = ssm.CfnAssociation(
            self, "SSMAssociation",
            name="AWS-ApplyAnsiblePlaybooks",
            output_location=None,
            parameters={
                "SourceType": [
                    "S3"
                ],
                "SourceInfo": [
                    "{\"path\":\"https://PATH_TO_S3_BUCKET"}"
                ],
                "InstallDependencies": [
                    "True"
                ],
                "PlaybookFile": [
                    "main.yml"
                ],
            # where PARAM1 and PARAM2 are declerd before like:
            #  PARAM1 = cdk.CfnParameter( self,
            #  PARAM2 = cdk.CfnParameter( self,
                "ExtraVariables": [
                    f"PARAM_1={ PARAM1.value_as_string } PARAM_2={PARAM2.value_as_string}"
                ],
                "Check": [
                    "False"
                ],
                "Verbose": [
                    "-v"
                ]
            },
             # where instance and targer_two id  aredeclerd before like:
             # instance = aws_ec2.Instance(se,...
             # target_two = ssm.CfnAssociation.TargetProperty(key="InstanceIds", values=[instance.instance_id])
            targets=[target_two]
        )

    ssm_association.node.add_dependency(instance)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 tadejcek