system/ansible/deployment_poc/tasks/netbox_evaluate_cluster.yml

51 lines
1.7 KiB
YAML
Raw Normal View History

---
- 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
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 }}"
when: host_status == 'active'
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'