summaryrefslogtreecommitdiffstats
path: root/ansible/deployment_poc/tasks/netbox_evaluate_cluster.yml
diff options
context:
space:
mode:
Diffstat (limited to 'ansible/deployment_poc/tasks/netbox_evaluate_cluster.yml')
-rw-r--r--ansible/deployment_poc/tasks/netbox_evaluate_cluster.yml50
1 files changed, 50 insertions, 0 deletions
diff --git a/ansible/deployment_poc/tasks/netbox_evaluate_cluster.yml b/ansible/deployment_poc/tasks/netbox_evaluate_cluster.yml
new file mode 100644
index 0000000..1e8b07f
--- /dev/null
+++ b/ansible/deployment_poc/tasks/netbox_evaluate_cluster.yml
@@ -0,0 +1,50 @@
+---
+- 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'
+