Ansible - Create an Amazon Web Services (AWS) Elastic Load Balancer (ELB) Target Group
by
Jeremy Canfield |
Updated: September 10 2023
| Ansible articles
An Elastic Load Balancer (ELB) is typically used to load balance requests across two (or more) different EC2 instances.
If you are not familiar with modules, check out Ansible - Getting Started with Modules.
Prerequisites
- Before you can use the Ansible Amazon Web Services (AWS) modules, you will need to install the AWS CLI tool on the hosts that will be using the Ansible Amazon Web Services (AWS) modules. Check out my article on Getting Started with the Ansible Amazon Web Services (AWS) modules.
- You will also need to set your Amazon Web Services (AWS) Profile Configurations. Check out my article Set Amazon Web Services (AWS) Profile Configurations.
- The aws_s3_bucket_info requires the following packages. Check out my article Resolve "boto3 required for this module".
- botocore version 1.25.0 or higher
- boto3 version 1.22.0 or higher
- Python 3.6 or higher must be used. The ansible --version command can be used to list the version of Python being used with Ansible. If your Ansible installation is used a version lower than Python 3.6, one solution would be to install Ansible in a Python virtual environment using Python 3.6 or higher.
- The community.aws collection will need to be installed. Check out my article on Install a collection using the ansible-galaxy collection install command.
elb_target_group can be used to create or delete your Amazon Web Services (AWS) Elastic Load Balancer (ELB) Target Groups.
---
- name: main play
hosts: localhost
tasks:
- name: Create a Target Group listening on HTTP port 80
community.aws.elb_target_group:
name: mytargetgroup
protocol: http
port: 80
vpc_id: vpc-014d21234335abcd
state: present
register: out
- debug:
var: out
...
Something like this should be returned.
ok: [localhost] => {
"out": {
"changed": true,
"deregistration_delay_timeout_seconds": "300",
"failed": false,
"health_check_enabled": true,
"health_check_interval_seconds": 30,
"health_check_path": "/",
"health_check_port": "traffic-port",
"health_check_protocol": "HTTP",
"health_check_timeout_seconds": 5,
"healthy_threshold_count": 5,
"ip_address_type": "ipv4",
"load_balancer_arns": [],
"load_balancing_algorithm_type": "round_robin",
"load_balancing_cross_zone_enabled": "use_load_balancer_configuration",
"matcher": {
"http_code": "200"
},
"port": 80,
"protocol": "HTTP",
"protocol_version": "HTTP1",
"slow_start_duration_seconds": "0",
"stickiness_app_cookie_cookie_name": "",
"stickiness_app_cookie_duration_seconds": "86400",
"stickiness_enabled": "false",
"stickiness_lb_cookie_duration_seconds": "86400",
"stickiness_type": "lb_cookie",
"tags": {},
"target_group_arn": "arn:aws:elasticloadbalancing:us-east-1:713542074252:targetgroup/my-target-group/756218c1d7813c2a",
"target_group_health_dns_failover_minimum_healthy_targets_count": "1",
"target_group_health_dns_failover_minimum_healthy_targets_percentage": "off",
"target_group_health_unhealthy_state_routing_minimum_healthy_targets_count": "1",
"target_group_health_unhealthy_state_routing_minimum_healthy_targets_percentage": "off",
"target_group_name": "mytargetgroup",
"target_type": "instance",
"unhealthy_threshold_count": 2,
"vpc_id": "vpc-014d2fcfa335d3c01"
}
}
Did you find this article helpful?
If so, consider buying me a coffee over at