system/ansible/deployment_poc/tasks/netbox_evaluate_cluster.yml
Georg Pfuetzenreuter 2ce8450b89
Bulk update
Signed-off-by: Georg Pfuetzenreuter <georg@lysergic.dev>
2022-02-13 16:56:12 +01:00

62 lines
2.0 KiB
YAML

---
- name: Evaluate cluster
block:
- name: Increment counters
set_fact:
retry_count: "{{ 0 if retry_count is undefined else retry_count | int +1 }}"
host_count: "{{ 0 if retry_count is undefined else host_count | int +1 }}"
- name: Pick cluster host
set_fact:
#host_choice: "{{ nb_hosts.json.results[nb_hosts.json.count | random | int] }}" #PICK RANDOM
#host_choice: "{{ nb_hosts.json.results[1] }}" #FAIL TEST
host_choice: "{{ nb_hosts.json.results[host_count | int] }}" #INCREMENT
no_log: true
- name: Evaluate cluster host status
set_fact:
host_status: "{{ host_choice.status.value }}"
#register: host_status
- name: Evaluate cluster host name
set_fact:
host: "{{ host_choice.name }}"
- name: Evaluate cluster host status
fail:
msg: Host is not ready.
when: host_status != 'active'
- name: Evaluate cluster host configuration
block:
- name: Cluster derived variables 1/2
set_fact:
storage: "{{ host_choice.config_context.storage[0] }}"
deployment_servers: "{{ host_choice.config_context.deployment_servers }}"
dhcp_servers: "{{ host_choice.config_context.dhcp_servers }}"
dns_servers: "{{ host_choice.config_context.dns_servers }}"
namespace: "{{ host_choice.config_context.namespace }}"
gateway: "{{ host_choice.config_context.gateway }}"
- name: Cluster derived variables 2/2
set_fact:
namespace_short: "{{ namespace.split('.')[0] }}"
when: host_status == 'active'
tags:
- init_dp
- init_ssh
rescue:
- name: Check retry counter
fail:
msg: "Too many retries - no host is ready"
when: retry_count | int == 3 and host_status != 'active'
- debug:
msg: "{{ host if host is defined }} - {{ host_status if host_status is defined }}"
- name: Re-evaluate cluster
include_tasks: "../tasks/netbox_evaluate_cluster.yml"
when: host_status != 'active'