Connect an EC2 instance to the target group using Ansible

I worked with EC2 instances before ELB for a while using Ansible . But now I'm starting to use ALB , and I need to connect my instances to the Target Groups , which in turn are connected to ALB . Is there an Ansible plugin that allows me to register an instance with the AWS Target Group ?

+5
source share
3 answers

Since Ansible does not support instance registration for target groups, I had to use the AWS-CLI tool. Using the following command, you can register an instance in the target group:

aws elbv2 register-targets --target-group-arn arn:aws:elasticloadbalancing:us-east-1:your-target-group --targets Id=i-your-instance 

So, I just call this command from Ansible and it is done.

+5
source

Use elb_target:

  • name: collect facts for all new proxy instances
    ec2_instance_facts:
    filters:
    "tag: Name": "{{ec2_tag_proxy}}"
    register: ec2_proxy

  • elb_target_group:
    name: uat-target-proxy
    protocol: http
    port: 80
    vpc_id: vpc-4e6e8112
    deregistration_delay_timeout: 60
    stickiness_enabled: True
    stickiness_lb_cookie_duration: 86400
    health_check_path: /
    success_response_codes: "200"
    health_check_interval: "20"
    state: present

  • elb_target:
    target group name: uat-target-proxy
    target_id: "{{item.instance_id}}"
    target_port: 80
    state: present
    with_items: "{{ec2_proxy.instances}}"
    when: ec2_proxy.instances | length> 0

0
source

Try the following settings:

 - name: creating target group local_action: module: elb_target_group region: us-east-2 vpc_id: yourvpcid name: create-targetgrp-delete protocol: https port: 443 health_check_path: / successful_response_codes: "200,250-260" state: present targets: - Id: ec2isntanceid Port: 443 wait_timeout: 200 register: tgp 
-1
source

Source: https://habr.com/ru/post/1258020/


All Articles