Merge pull request #2126 from nfelsen/access_logs
Adding support for access logs in ELB
This commit is contained in:
commit
f4ed4b37a9
1 changed files with 44 additions and 4 deletions
|
@ -70,6 +70,11 @@ options:
|
||||||
- An associative array of health check configuration settings (see example)
|
- An associative array of health check configuration settings (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
|
||||||
subnets:
|
subnets:
|
||||||
description:
|
description:
|
||||||
- A list of VPC subnets to use when creating ELB. Zones should be empty if using this.
|
- A list of VPC subnets to use when creating ELB. Zones should be empty if using this.
|
||||||
|
@ -161,7 +166,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"
|
||||||
|
@ -180,6 +185,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:
|
||||||
|
@ -306,7 +315,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
|
||||||
|
@ -322,6 +331,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
|
||||||
|
@ -350,6 +360,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()
|
||||||
|
|
||||||
|
@ -696,6 +708,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:
|
||||||
|
@ -831,7 +869,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'}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -856,6 +895,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']
|
||||||
|
@ -888,7 +928,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…
Reference in a new issue