Adding support for access logs in ELB

pull/18777/head
Nathaniel Felsen 9 years ago committed by Matt Clay
parent ec1c18e3d5
commit ec14a5c728

@ -69,6 +69,11 @@ options:
- An associative array of health check configuration settigs (see example) - An associative array of health check configuration settigs (see example)
require: false require: false
default: None default: None
access_logs:
description:
- An associative array of access logs configuration settings (see example)
require: false
default: None
region: region:
description: description:
- The AWS region to use. If not specified then the value of the EC2_REGION environment variable, if any, is used. - The AWS region to use. If not specified then the value of the EC2_REGION environment variable, if any, is used.
@ -163,7 +168,7 @@ EXAMPLES = """
load_balancer_port: 80 load_balancer_port: 80
instance_port: 80 instance_port: 80
# Configure a health check # Configure a health check and the access logs
- local_action: - local_action:
module: ec2_elb_lb module: ec2_elb_lb
name: "test-please-delete" name: "test-please-delete"
@ -182,6 +187,10 @@ EXAMPLES = """
interval: 30 # seconds interval: 30 # seconds
unhealthy_threshold: 2 unhealthy_threshold: 2
healthy_threshold: 10 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 # Ensure ELB is gone
- local_action: - local_action:
@ -308,7 +317,7 @@ class ElbManager(object):
zones=None, purge_zones=None, security_group_ids=None, zones=None, purge_zones=None, security_group_ids=None,
health_check=None, subnets=None, purge_subnets=None, health_check=None, subnets=None, purge_subnets=None,
scheme="internet-facing", connection_draining_timeout=None, scheme="internet-facing", connection_draining_timeout=None,
cross_az_load_balancing=None, cross_az_load_balancing=None, access_logs=None,
stickiness=None, region=None, **aws_connect_params): stickiness=None, region=None, **aws_connect_params):
self.module = module self.module = module
@ -324,6 +333,7 @@ class ElbManager(object):
self.scheme = scheme self.scheme = scheme
self.connection_draining_timeout = connection_draining_timeout self.connection_draining_timeout = connection_draining_timeout
self.cross_az_load_balancing = cross_az_load_balancing self.cross_az_load_balancing = cross_az_load_balancing
self.access_logs = access_logs
self.stickiness = stickiness self.stickiness = stickiness
self.aws_connect_params = aws_connect_params self.aws_connect_params = aws_connect_params
@ -352,6 +362,8 @@ class ElbManager(object):
self._set_connection_draining_timeout() self._set_connection_draining_timeout()
if self._check_attribute_support('cross_zone_load_balancing'): if self._check_attribute_support('cross_zone_load_balancing'):
self._set_cross_az_load_balancing() self._set_cross_az_load_balancing()
if self._check_attribute_support('access_log'):
self._set_access_log()
# add sitcky options # add sitcky options
self.select_stickiness_policy() self.select_stickiness_policy()
@ -698,6 +710,32 @@ class ElbManager(object):
self.elb_conn.modify_lb_attribute(self.name, 'CrossZoneLoadBalancing', self.elb_conn.modify_lb_attribute(self.name, 'CrossZoneLoadBalancing',
attributes.cross_zone_load_balancing.enabled) attributes.cross_zone_load_balancing.enabled)
def _set_access_log(self):
attributes = self.elb.get_attributes()
if self.access_logs:
if 's3_location' not in self.access_logs:
self.module.fail_json(msg='s3_location information required')
access_logs_config = {
"enabled": True,
"s3_bucket_name": self.access_logs['s3_location'],
"s3_bucket_prefix": self.access_logs.get('s3_prefix', ''),
"emit_interval": self.access_logs.get('interval', 60),
}
update_access_logs_config = False
for attr, desired_value in access_logs_config.iteritems():
if getattr(attributes.access_log, attr) != desired_value:
setattr(attributes.access_log, attr, desired_value)
update_access_logs_config = True
if update_access_logs_config:
self.elb_conn.modify_lb_attribute(self.name, 'AccessLog', attributes.access_log)
self.changed = True
elif attributes.access_log.enabled:
attributes.access_log.enabled = False
self.changed = True
self.elb_conn.modify_lb_attribute(self.name, 'AccessLog', attributes.access_log)
def _set_connection_draining_timeout(self): def _set_connection_draining_timeout(self):
attributes = self.elb.get_attributes() attributes = self.elb.get_attributes()
if self.connection_draining_timeout is not None: if self.connection_draining_timeout is not None:
@ -833,7 +871,8 @@ def main():
scheme={'default': 'internet-facing', 'required': False}, scheme={'default': 'internet-facing', 'required': False},
connection_draining_timeout={'default': None, 'required': False}, connection_draining_timeout={'default': None, 'required': False},
cross_az_load_balancing={'default': None, 'required': False}, cross_az_load_balancing={'default': None, 'required': False},
stickiness={'default': None, 'required': False, 'type': 'dict'} stickiness={'default': None, 'required': False, 'type': 'dict'},
access_logs={'default': None, 'required': False, 'type': 'dict'}
) )
) )
@ -858,6 +897,7 @@ def main():
security_group_ids = module.params['security_group_ids'] security_group_ids = module.params['security_group_ids']
security_group_names = module.params['security_group_names'] security_group_names = module.params['security_group_names']
health_check = module.params['health_check'] health_check = module.params['health_check']
access_logs = module.params['access_logs']
subnets = module.params['subnets'] subnets = module.params['subnets']
purge_subnets = module.params['purge_subnets'] purge_subnets = module.params['purge_subnets']
scheme = module.params['scheme'] scheme = module.params['scheme']
@ -890,7 +930,7 @@ def main():
purge_zones, security_group_ids, health_check, purge_zones, security_group_ids, health_check,
subnets, purge_subnets, scheme, subnets, purge_subnets, scheme,
connection_draining_timeout, cross_az_load_balancing, connection_draining_timeout, cross_az_load_balancing,
stickiness, access_logs, stickiness,
region=region, **aws_connect_params) region=region, **aws_connect_params)
# check for unsupported attributes for this version of boto # check for unsupported attributes for this version of boto

Loading…
Cancel
Save