From e0410661fa5711ce5e36d6b3e86c241aa55e022f Mon Sep 17 00:00:00 2001
From: Gustavo Muniz do Carmo <gustavo@esign.com.br>
Date: Mon, 15 Jul 2019 09:27:06 +0100
Subject: [PATCH] azure loadbalancer vars generation (#4892)

---
 .../roles/generate-inventory_2/tasks/main.yml        | 12 +++++++++++-
 .../templates/loadbalancer_vars.j2                   |  8 ++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)
 create mode 100644 contrib/azurerm/roles/generate-inventory_2/templates/loadbalancer_vars.j2

diff --git a/contrib/azurerm/roles/generate-inventory_2/tasks/main.yml b/contrib/azurerm/roles/generate-inventory_2/tasks/main.yml
index f639e64c7..e53912cfc 100644
--- a/contrib/azurerm/roles/generate-inventory_2/tasks/main.yml
+++ b/contrib/azurerm/roles/generate-inventory_2/tasks/main.yml
@@ -8,12 +8,22 @@
   command: az vm list -o json --resource-group {{ azure_resource_group }}
   register: vm_list_cmd
 
-- name: Set VM IP and roles lists
+- name: Query Azure Load Balancer Public IP
+  command: az network public-ip show -o json -g {{ azure_resource_group }} -n kubernetes-api-pubip
+  register: lb_pubip_cmd
+
+- name: Set VM IP, roles lists and load balancer public IP
   set_fact:
     vm_ip_list: "{{ vm_ip_list_cmd.stdout }}"
     vm_roles_list: "{{ vm_list_cmd.stdout }}"
+    lb_pubip: "{{ lb_pubip_cmd.stdout }}"
 
 - name: Generate inventory
   template:
     src: inventory.j2
     dest: "{{ playbook_dir }}/inventory"
+
+- name: Generate Load Balancer variables
+  template:
+    src: loadbalancer_vars.j2
+    dest: "{{ playbook_dir }}/loadbalancer_vars.yml"
diff --git a/contrib/azurerm/roles/generate-inventory_2/templates/loadbalancer_vars.j2 b/contrib/azurerm/roles/generate-inventory_2/templates/loadbalancer_vars.j2
new file mode 100644
index 000000000..95a62f327
--- /dev/null
+++ b/contrib/azurerm/roles/generate-inventory_2/templates/loadbalancer_vars.j2
@@ -0,0 +1,8 @@
+## External LB example config
+apiserver_loadbalancer_domain_name: {{ lb_pubip.dnsSettings.fqdn }}
+loadbalancer_apiserver:
+  address: {{ lb_pubip.ipAddress }}
+  port: 6443
+
+## Internal loadbalancers for apiservers
+loadbalancer_apiserver_localhost: false
-- 
GitLab