amazon.aws.ec2_elb_lb – Creates, updates or destroys an Amazon ELB.

Note

This plugin is part of the amazon.aws collection (version 1.4.1).

To install it use: ansible-galaxy collection install amazon.aws.

To use it in a playbook, specify: amazon.aws.ec2_elb_lb.

New in version 1.0.0: of amazon.aws

Synopsis

  • Returns information about the load balancer.

  • Will be marked changed when called only if state is changed.

Requirements

The below requirements are needed on the host that executes this module.

  • python >= 2.6

  • boto

Parameters

Parameter Choices/Defaults Comments
access_logs
dictionary
An associative array of access logs configuration settings (see examples).
aws_access_key
string
AWS access key. If not set then the value of the AWS_ACCESS_KEY_ID, AWS_ACCESS_KEY or EC2_ACCESS_KEY environment variable is used.
If profile is set this parameter is ignored.
Passing the aws_access_key and profile options at the same time has been deprecated and the options will be made mutually exclusive after 2022-06-01.

aliases: ec2_access_key, access_key
aws_ca_bundle
path
The location of a CA Bundle to use when validating SSL certificates.
Only used for boto3 based modules.
Note: The CA Bundle is read 'module' side and may need to be explicitly copied from the controller if not run locally.
aws_config
dictionary
A dictionary to modify the botocore configuration.
Only the 'user_agent' key is used for boto modules. See http://boto.cloudhackers.com/en/latest/boto_config_tut.html#boto for more boto configuration.
aws_secret_key
string
AWS secret key. If not set then the value of the AWS_SECRET_ACCESS_KEY, AWS_SECRET_KEY, or EC2_SECRET_KEY environment variable is used.
If profile is set this parameter is ignored.
Passing the aws_secret_key and profile options at the same time has been deprecated and the options will be made mutually exclusive after 2022-06-01.

aliases: ec2_secret_key, secret_key
connection_draining_timeout
integer
Wait a specified timeout allowing connections to drain before terminating an instance.
cross_az_load_balancing
boolean
    Choices:
  • no
  • yes
Distribute load across all configured Availability Zones.
Defaults to false.
debug_botocore_endpoint_logs
boolean
    Choices:
  • no ←
  • yes
Use a botocore.endpoint logger to parse the unique (rather than total) "resource:action" API calls made during a task, outputing the set to the resource_actions key in the task results. Use the aws_resource_action callback to output to total list made during a playbook. The ANSIBLE_DEBUG_BOTOCORE_LOGS environment variable may also be used.
ec2_url
string
Url to use to connect to EC2 or your Eucalyptus cloud (by default the module will use EC2 endpoints). Ignored for modules where region is required. Must be specified for all other modules if region is not used. If not set then the value of the EC2_URL environment variable, if any, is used.

aliases: aws_endpoint_url, endpoint_url
health_check
dictionary
An associative array of health check configuration settings (see examples).
idle_timeout
integer
ELB connections from clients and to servers are timed out after this amount of time.
instance_ids
list / elements=string
List of instance ids to attach to this ELB.
listeners
list / elements=dictionary
List of ports/protocols for this ELB to listen on (see examples).
name
string / required
The name of the ELB.
profile
string
Uses a boto profile. Only works with boto >= 2.24.0.
Using profile will override aws_access_key, aws_secret_key and security_token and support for passing them at the same time as profile has been deprecated.
aws_access_key, aws_secret_key and security_token will be made mutually exclusive with profile after 2022-06-01.

aliases: aws_profile
purge_instance_ids
boolean
    Choices:
  • no ←
  • yes
Purge existing instance ids on ELB that are not found in instance_ids.
purge_listeners
boolean
    Choices:
  • no
  • yes ←
Purge existing listeners on ELB that are not found in listeners.
purge_subnets
boolean
    Choices:
  • no ←
  • yes
Purge existing subnet on ELB that are not found in subnets.
purge_zones
boolean
    Choices:
  • no ←
  • yes
Purge existing availability zones on ELB that are not found in zones.
region
string
The AWS region to use. If not specified then the value of the AWS_REGION or EC2_REGION environment variable, if any, is used. See http://docs.aws.amazon.com/general/latest/gr/rande.html#ec2_region

aliases: aws_region, ec2_region
scheme
string
    Choices:
  • internal
  • internet-facing ←
The scheme to use when creating the ELB. For a private VPC-visible ELB use internal.
If you choose to update your scheme with a different value the ELB will be destroyed and recreated. To update scheme you must use the option wait.
security_group_ids
list / elements=string
A list of security groups to apply to the ELB.
security_group_names
list / elements=string
A list of security group names to apply to the ELB.
security_token
string
AWS STS security token. If not set then the value of the AWS_SECURITY_TOKEN or EC2_SECURITY_TOKEN environment variable is used.
If profile is set this parameter is ignored.
Passing the security_token and profile options at the same time has been deprecated and the options will be made mutually exclusive after 2022-06-01.

aliases: aws_security_token, access_token
state
string / required
    Choices:
  • absent
  • present
Create or destroy the ELB.
stickiness
dictionary
An associative array of stickiness policy settings. Policy will be applied to all listeners (see examples).
subnets
list / elements=string
A list of VPC subnets to use when creating ELB. Zones should be empty if using this.
tags
dictionary
An associative array of tags. To delete all tags, supply an empty dict ({}).
validate_certs
boolean
    Choices:
  • no
  • yes ←
When set to no, SSL certificates will not be validated for boto versions >= 2.6.0.
wait
boolean
    Choices:
  • no ←
  • yes
When specified, Ansible will check the status of the load balancer to ensure it has been successfully removed from AWS.
wait_timeout
integer
Default:
60
Used in conjunction with wait. Number of seconds to wait for the ELB to be terminated.
A maximum of 600 seconds (10 minutes) is allowed.
zones
list / elements=string
List of availability zones to enable on this ELB.

Notes

Note

  • If parameters are not set within the module, the following environment variables can be used in decreasing order of precedence AWS_URL or EC2_URL, AWS_PROFILE or AWS_DEFAULT_PROFILE, AWS_ACCESS_KEY_ID or AWS_ACCESS_KEY or EC2_ACCESS_KEY, AWS_SECRET_ACCESS_KEY or AWS_SECRET_KEY or EC2_SECRET_KEY, AWS_SECURITY_TOKEN or EC2_SECURITY_TOKEN, AWS_REGION or EC2_REGION, AWS_CA_BUNDLE

  • Ansible uses the boto configuration file (typically ~/.boto) if no credentials are provided. See https://boto.readthedocs.io/en/latest/boto_config_tut.html

  • AWS_REGION or EC2_REGION can be typically be used to specify the AWS region, when required, but this can also be configured in the boto config file

Examples

# Note: None of these examples set aws_access_key, aws_secret_key, or region.
# It is assumed that their matching environment variables are set.

# Basic provisioning example (non-VPC)

- amazon.aws.ec2_elb_lb:
    name: "test-please-delete"
    state: present
    zones:
      - us-east-1a
      - us-east-1d
    listeners:
      - protocol: http # options are http, https, ssl, tcp
        load_balancer_port: 80
        instance_port: 80
        proxy_protocol: True
      - protocol: https
        load_balancer_port: 443
        instance_protocol: http # optional, defaults to value of protocol setting
        instance_port: 80
        # ssl certificate required for https or ssl
        ssl_certificate_id: "arn:aws:iam::123456789012:server-certificate/company/servercerts/ProdServerCert"

# Internal ELB example

- amazon.aws.ec2_elb_lb:
    name: "test-vpc"
    scheme: internal
    state: present
    instance_ids:
      - i-abcd1234
    purge_instance_ids: true
    subnets:
      - subnet-abcd1234
      - subnet-1a2b3c4d
    listeners:
      - protocol: http # options are http, https, ssl, tcp
        load_balancer_port: 80
        instance_port: 80

# Configure a health check and the access logs
- amazon.aws.ec2_elb_lb:
    name: "test-please-delete"
    state: present
    zones:
      - us-east-1d
    listeners:
      - protocol: http
        load_balancer_port: 80
        instance_port: 80
    health_check:
        ping_protocol: http # options are http, https, ssl, tcp
        ping_port: 80
        ping_path: "/index.html" # not required for tcp or ssl
        response_timeout: 5 # seconds
        interval: 30 # seconds
        unhealthy_threshold: 2
        healthy_threshold: 10
    access_logs:
        interval: 5 # minutes (defaults to 60)
        s3_location: "my-bucket" # This value is required if access_logs is set
        s3_prefix: "logs"

# Ensure ELB is gone
- amazon.aws.ec2_elb_lb:
    name: "test-please-delete"
    state: absent

# Ensure ELB is gone and wait for check (for default timeout)
- amazon.aws.ec2_elb_lb:
    name: "test-please-delete"
    state: absent
    wait: yes

# Ensure ELB is gone and wait for check with timeout value
- amazon.aws.ec2_elb_lb:
    name: "test-please-delete"
    state: absent
    wait: yes
    wait_timeout: 600

# Normally, this module will purge any listeners that exist on the ELB
# but aren't specified in the listeners parameter. If purge_listeners is
# false it leaves them alone
- amazon.aws.ec2_elb_lb:
    name: "test-please-delete"
    state: present
    zones:
      - us-east-1a
      - us-east-1d
    listeners:
      - protocol: http
        load_balancer_port: 80
        instance_port: 80
    purge_listeners: no

# Normally, this module will leave availability zones that are enabled
# on the ELB alone. If purge_zones is true, then any extraneous zones
# will be removed
- amazon.aws.ec2_elb_lb:
    name: "test-please-delete"
    state: present
    zones:
      - us-east-1a
      - us-east-1d
    listeners:
      - protocol: http
        load_balancer_port: 80
        instance_port: 80
    purge_zones: yes

# Creates a ELB and assigns a list of subnets to it.
- amazon.aws.ec2_elb_lb:
    state: present
    name: 'New ELB'
    security_group_ids: 'sg-123456, sg-67890'
    region: us-west-2
    subnets: 'subnet-123456,subnet-67890'
    purge_subnets: yes
    listeners:
      - protocol: http
        load_balancer_port: 80
        instance_port: 80

# Create an ELB with connection draining, increased idle timeout and cross availability
# zone load balancing
- amazon.aws.ec2_elb_lb:
    name: "New ELB"
    state: present
    connection_draining_timeout: 60
    idle_timeout: 300
    cross_az_load_balancing: "yes"
    region: us-east-1
    zones:
      - us-east-1a
      - us-east-1d
    listeners:
      - protocol: http
        load_balancer_port: 80
        instance_port: 80

# Create an ELB with load balancer stickiness enabled
- amazon.aws.ec2_elb_lb:
    name: "New ELB"
    state: present
    region: us-east-1
    zones:
      - us-east-1a
      - us-east-1d
    listeners:
      - protocol: http
        load_balancer_port: 80
        instance_port: 80
    stickiness:
      type: loadbalancer
      enabled: yes
      expiration: 300

# Create an ELB with application stickiness enabled
- amazon.aws.ec2_elb_lb:
    name: "New ELB"
    state: present
    region: us-east-1
    zones:
      - us-east-1a
      - us-east-1d
    listeners:
      - protocol: http
        load_balancer_port: 80
        instance_port: 80
    stickiness:
      type: application
      enabled: yes
      cookie: SESSIONID

# Create an ELB and add tags
- amazon.aws.ec2_elb_lb:
    name: "New ELB"
    state: present
    region: us-east-1
    zones:
      - us-east-1a
      - us-east-1d
    listeners:
      - protocol: http
        load_balancer_port: 80
        instance_port: 80
    tags:
      Name: "New ELB"
      stack: "production"
      client: "Bob"

# Delete all tags from an ELB
- amazon.aws.ec2_elb_lb:
    name: "New ELB"
    state: present
    region: us-east-1
    zones:
      - us-east-1a
      - us-east-1d
    listeners:
      - protocol: http
        load_balancer_port: 80
        instance_port: 80
    tags: {}

Authors

  • Jim Dalton (@jsdalton)