diff --git a/tasks/do-lb-register-dns.yaml b/tasks/do-lb-register-dns.yaml index 5002757..e8c3c1c 100644 --- a/tasks/do-lb-register-dns.yaml +++ b/tasks/do-lb-register-dns.yaml @@ -1,46 +1,46 @@ --- -- name: LB | DO | Register DNS | Set IP +- name: DO | CB DNS | Register DNS | Set IP ansible.builtin.set_fact: res_value: "{{ lb_ip }}" - when: res.value is not defined + when: cb.value is not defined # Module does not provide a good lookup nor indepotency, so # let's load current records filter it and create only new ones. # It provides indepotency by name, and not value. Additional # checks should be done to achieve that. -- name: LB | DO | Register DNS | Get RR +- name: DO | CB DNS | Register DNS | Get RR community.digitalocean.digital_ocean_domain_record_info: state: present - domain: "{{ res.domain }}" + domain: "{{ cb.domain }}" register: reg_dns_zone_records -- name: LB | DO | Register DNS | Show RRs +- name: DO | CB DNS | Register DNS | Show RRs ansible.builtin.debug: var: reg_dns_zone_records -- name: LB | DO | Register DNS | Set list to add +- name: DO | CB DNS | Register DNS | Set list to add ansible.builtin.set_fact: rr_to_add: [] -- name: LB | DO | Register DNS | Discover value +- name: DO | CB DNS | Register DNS | Discover value ansible.builtin.set_fact: rr_to_add: "{{ rr_to_add + [record] }}" when: reg_dns_zone_records.data.records | community.general.json_query(q_rr) | length <= 0 - with_items: "{{ res.records }}" + with_items: "{{ cb.records }}" loop_control: loop_var: record vars: q_rr: "[?name=='{{ record.name }}']" -- name: LB | DO | Register DNS | Show RRs to add +- name: DO | CB DNS | Register DNS | Show RRs to add ansible.builtin.debug: var: rr_to_add -- name: LB | DO | Register DNS | Create RR # noqa: args[module] +- name: DO | CB DNS | Register DNS | Create RR # noqa: args[module] community.digitalocean.digital_ocean_domain_record: state: present - domain: "{{ res.domain }}" + domain: "{{ cb.domain }}" type: "{{ record.type }}" name: "{{ record.name }}" data: "{{ record.value | d(res_value) }}" diff --git a/tasks/do-lb.yaml b/tasks/do-lb.yaml index 7b8054d..ae088fa 100644 --- a/tasks/do-lb.yaml +++ b/tasks/do-lb.yaml @@ -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 diff --git a/tasks/main.yaml b/tasks/main.yaml index 95fa3fb..08f9643 100644 --- a/tasks/main.yaml +++ b/tasks/main.yaml @@ -6,6 +6,8 @@ loop_control: loop_var: tg +- debug: var=cloud_loadbalancers + - name: Setup Load Balancers by provider ansible.builtin.include_tasks: "{{ lb.provider }}-lb.yaml" with_items: "{{ cloud_loadbalancers | d([]) }}"