-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
42 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,49 @@ | ||
--- | ||
- name: LB | DO | Set defaults | ||
- name: DO | Set defaults | ||
ansible.builtin.set_fact: | ||
vpc_uuid: "{{ lb.vpc_uuid | d('') }}" | ||
lb_name: '' | ||
lb_ip: '' | ||
lb_spec: "{{ lb.spec | d({}) }}" | ||
|
||
# API does not return when member=true name=vpc_name | ||
- name: LB | DO | Lookup for vpc_uuid | ||
community.digitalocean.digital_ocean_vpc_info: | ||
register: do_vpc | ||
when: vpc_uuid | length > 0 | ||
|
||
- name: LB | DO | Set vpc_uuid | ||
ansible.builtin.set_fact: | ||
vpc_uuid: "{{ do_vpc.data | json_query(filter_vpc) | join(' ') }}" | ||
- name: DO | Lookup for vpc_uuid | ||
when: | ||
- vpc_uuid | length > 0 | ||
- not(do_vpc.failed) | ||
vars: | ||
filter_vpc: "[?name=='{{ lb.vpc_name }}'].id" | ||
|
||
- name: LB | DO | Gather load balancers | ||
- lb_spec.vpc_uuid is not defined | ||
- lb_spec.vpc_uuid | d('') | length == 0 | ||
block: | ||
- name: DO | Lookup for vpc_uuid | ||
community.digitalocean.digital_ocean_vpc_info: | ||
register: do_vpc | ||
|
||
- name: DO | Set vpc_uuid | ||
ansible.builtin.set_fact: | ||
lb_spec: "{{ lb_spec | combine({ | ||
'vpc_uuid': do_vpc.data | json_query(filter_vpc) | join(' ') | ||
}) }}" | ||
when: not(do_vpc.failed) | ||
vars: | ||
filter_vpc: "[?name=='{{ lb.vpc_name }}'].id" | ||
|
||
- name: DO | Gather load balancers | ||
community.digitalocean.digital_ocean_load_balancer_info: | ||
register: do_lbs | ||
|
||
- name: LB | DO | Set LB Name when eixsts | ||
ansible.builtin.set_fact: | ||
lb_name: "{{ do_lbs.data | community.general.json_query(filter_lb) | join(' ') }}" | ||
vars: | ||
filter_lb: "[?name=='{{ lb.name }}'].name" | ||
|
||
- name: LB | DO | Set LB ID when eixsts | ||
ansible.builtin.set_fact: | ||
lb_id: "{{ do_lbs.data | community.general.json_query(filter_lb) | join(' ') }}" | ||
vars: | ||
filter_lb: "[?name=='{{ lb.name }}'].id" | ||
|
||
- name: LB | DO | Set LB IP when eixsts | ||
ansible.builtin.set_fact: | ||
lb_ip: "{{ do_lbs.data | community.general.json_query(filter_lb) | join(' ') }}" | ||
vars: | ||
filter_lb: "[?name=='{{ lb.name }}'].ip" | ||
|
||
- name: LB | DO | Create | ||
- name: DO | Create | ||
community.digitalocean.digital_ocean_load_balancer: | ||
state: present | ||
name: "{{ lb.name | d(omit) }}" | ||
project: "{{ lb.project_name | d(omit) }}" | ||
region: "{{ lb.region | d(omit) }}" | ||
vpc_uuid: "{{ vpc_uuid | d(omit) }}" | ||
size: "{{ lb.size | d(omit) }}" | ||
droplet_ids: "{{ lb.droplet_ids | d([]) }}" | ||
forwarding_rules: "{{ lb.forwarding_rules | d(omit) }}" | ||
health_check: "{{ lb.health_check | d(omit) }}" | ||
redirect_http_to_https: "{{ lb.redirect_http_to_https | d(omit) }}" | ||
enable_backend_keepalive: "{{ lb.enable_backend_keepalive | d(omit) }}" | ||
enable_proxy_protocol: "{{ lb.enable_proxy_protocol | d(omit) }}" | ||
algorithm: "{{ lb.algorithm | d(omit) }}" | ||
wait: true | ||
when: lb_name | length > 0 | ||
args: "{{ lb_spec }}" | ||
register: lb_out | ||
|
||
# Gather info again (maybe sleep a bit?) | ||
- name: LB | DO | Gather load balancers to register | ||
- name: DO | Gather load balancers to register | ||
community.digitalocean.digital_ocean_load_balancer_info: | ||
register: do_lbs | ||
when: lb_ip | length > 0 | ||
|
||
- name: LB | DO | Set LB IP when eixsts | ||
- name: DO | Set LB IP when eixsts | ||
ansible.builtin.set_fact: | ||
lb_ip: "{{ do_lbs.data | community.general.json_query(filter_lb) | join(' ') }}" | ||
vars: | ||
filter_lb: "[?name=='{{ lb.name }}'].ip" | ||
when: lb_ip | length > 0 | ||
filter_lb: "[?name=='{{ lb_spec.name }}'].ip" | ||
|
||
- name: LB | DO | Callback register resources | ||
ansible.builtin.include_tasks: "do-lb-register-{{ res.service }}.yaml" | ||
with_items: "{{ lb.register_resources | d([]) }}" | ||
- name: DO | Callback register resources | ||
ansible.builtin.include_tasks: "do-lb-register-{{ cb.service }}.yaml" | ||
with_items: "{{ lb.callbacks | d([]) }}" | ||
loop_control: | ||
loop_var: res | ||
loop_var: cb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters