forked from kubealex/libvirt-k8s-provisioner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path05_provisioning_loadbalancer.yml
67 lines (61 loc) · 2.53 KB
/
05_provisioning_loadbalancer.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
- name: This play provisions loadbalancer VM for control plane
hosts: vm_host
vars_files:
- vars/k8s_cluster.yml
tasks:
- name: Provision loadbalancer vm
block:
- name: Ensure Load Balancer VM is in place
community.general.terraform:
project_path: "{{ workspace_directory.base_path }}/clusters/{{ k8s.cluster_name }}/loadbalancer"
force_init: true
variables:
hostname: "{{ k8s.cluster_name }}-loadbalancer"
domain: "{{ k8s.network.domain }}"
os: "{{ 'ubuntu' if k8s.cluster_os == 'Ubuntu' else 'centos' }}"
libvirt_network: "{{ k8s.cluster_name }}"
libvirt_pool: "{{ k8s.cluster_name }}"
os_image_name: "{{ image_name }}.qcow2"
sshKey: "{{ k8s_key_pub }}"
state: present
become: true
register: output_loadbalancer
- name: Add loadbalancer to inventory
ansible.builtin.add_host:
hostname: '{{ k8s.cluster_name }}-loadbalancer.{{ k8s.network.domain }}'
ansible_ssh_private_key_file: "{{ playbook_dir }}//id_rsa_{{ k8s.cluster_name }}"
ansible_user: kube
ansible_ssh_common_args: '-o StrictHostKeyChecking=no'
groups:
- "loadbalancer"
delegate_to: localhost
- name: Ensure to clean known_hosts
ansible.builtin.known_hosts:
host: "{{ item }}"
path: ~/.ssh/known_hosts
state: absent
loop: "{{ groups['loadbalancer'] }}"
delegate_to: localhost
- name: Check connection to loadbalancer
hosts: loadbalancer
gather_facts: false
vars_files:
- vars/k8s_cluster.yml
tasks:
- name: Test newly created host and set facts
block:
- name: Wait 600 seconds for target connection to become reachable/usable
ansible.builtin.wait_for_connection:
timeout: 600
delay: 0
- name: Verify host is up and running
ansible.builtin.ping:
- name: Extract facts from setup
ansible.builtin.setup:
register: lb_facts
- name: Set facts based on new gathering
ansible.builtin.set_fact:
host_ip: "{{ lb_facts.ansible_facts.ansible_default_ipv4.address }}"
host_interface: "{{ lb_facts.ansible_facts.ansible_default_ipv4.interface }}"
host_mac: "{{ lb_facts.ansible_facts.ansible_default_ipv4.macaddress }}"
host_fqdn: "{{ lb_facts.ansible_facts.ansible_fqdn }}"