Skip to content

Instantly share code, notes, and snippets.

@anryko
Last active February 21, 2018 18:56
Show Gist options
  • Save anryko/c854ec431a1b25667da4f1c24a1a23e4 to your computer and use it in GitHub Desktop.
Save anryko/c854ec431a1b25667da4f1c24a1a23e4 to your computer and use it in GitHub Desktop.
Ansible AWS ALB Listeners
---
- name: test
hosts: localhost
connection: local
gather_facts: False
vars:
listeners:
- Protocol: HTTP
# Port: 80
DefaultActions:
- Type: forward # Required. Only 'forward' is accepted at this time
TargetGroupName: se1-stg-webapp-all-alb-http # Required. The name of the target group
- Protocol: HTTPS
# Port: 443
# SslPolicy: ELBSecurityPolicy-2016-08
Certificates:
- CertificateArn: aaa
- CertificateArn: bbb
listener_http_default:
Port: 80
listener_https_default:
Port: 443
SslPolicy: ELBSecurityPolicy-2016-08
Certificates: []
new_listeners: []
pre_tasks:
- include_tasks: listeners_loop.yml
loop_control:
loop_var: listener
with_items: "{{ listeners }}"
- debug:
var: new_listeners
- set_fact:
new_listeners: "{{ new_listeners + [ listener_http_default | combine(listener) ] }}"
when: listener.Protocol == 'HTTP'
- block:
- set_fact:
old_certificates: "{{ listener.Certificates }}"
- set_fact:
first_certificate:
Certificates:
- "{{ old_certificates[0] }}"
- set_fact:
new_listeners: "{{ new_listeners + [ listener_https_default | combine(listener) | combine(first_certificate) ] }}"
when: listener.Protocol == 'HTTPS'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment