-
Notifications
You must be signed in to change notification settings - Fork 40
/
05_vm_provisioning_infra.yml
93 lines (85 loc) · 4.52 KB
/
05_vm_provisioning_infra.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
- name: Provisioning infrastructure VMs
hosts: vm_host
vars_files:
- vars/cluster_vars.yml
- vars/infra_vars.yml
tasks:
- name: Set ocp_domain as fact
ansible.builtin.set_fact:
ocp_domain: "{{ cluster.name }}.{{ domain }}"
- name: Ensure to clean known_hosts
ansible.builtin.known_hosts:
host: "{{ item.value[0].ip }}"
path: ~/.ssh/known_hosts
state: absent
loop: "{{ infra_nodes.host_list | dict2items }}"
delegate_to: localhost
- name: Deploy bastion VM with terraform
community.general.terraform:
force_init: true
project_path: "{{ workspace_directory.base_path }}/{{ cluster.name }}/terraform/bastion"
variables:
libvirt_network: "{{ cluster.name }}"
libvirt_pool: "{{ cluster.name }}"
network_data: '{ hostIP = "{{ infra_nodes.host_list.bastion[0].ip }}", broadcast= "{{ infra_nodes.host_list.bastion[0].ip | ansible.utils.ipsubnet(24) | ansible.utils.ipaddr(''broadcast'') }}", dns = "{{ infra_nodes.host_list.bastion[0].ip | ansible.utils.ipsubnet(24) | ansible.utils.ipaddr(''network'') | ansible.utils.ipmath(1) }}", gateway = "{{ infra_nodes.host_list.bastion[0].ip | ansible.utils.ipsubnet(24) | ansible.utils.ipaddr(''network'') | ansible.utils.ipmath(1) }}", network = "{{ infra_nodes.host_list.bastion[0].ip | ansible.utils.ipsubnet(24) | ansible.utils.ipaddr(''network'') }}" }' # noqa yaml[line-length]
hostname: "bastion"
domain: "{{ domain }}"
cluster_name: "{{ cluster.name }}"
sshkey: "{{ ssh_service_key_pub }}"
state: present
become: true
register: output_ba
- name: Deploy loadbalancer VM
community.general.terraform:
force_init: true
project_path: "{{ workspace_directory.base_path }}/{{ cluster.name }}/terraform/loadbalancer"
variables:
libvirt_network: "{{ cluster.name }}"
libvirt_pool: "{{ cluster.name }}"
network_data: '{ hostIP = "{{ infra_nodes.host_list.loadbalancer[0].ip }}", broadcast= "{{ infra_nodes.host_list.loadbalancer[0].ip | ansible.utils.ipsubnet(24) | ansible.utils.ipaddr(''broadcast'') }}", dns = "{{ infra_nodes.host_list.loadbalancer[0].ip | ansible.utils.ipsubnet(24) | ansible.utils.ipaddr(''network'') | ansible.utils.ipmath(1) }}", gateway = "{{ infra_nodes.host_list.loadbalancer[0].ip | ansible.utils.ipsubnet(24) | ansible.utils.ipaddr(''network'') | ansible.utils.ipmath(1) }}", network = "{{ infra_nodes.host_list.loadbalancer[0].ip | ansible.utils.ipsubnet(24) | ansible.utils.ipaddr(''network'') }}" }' # noqa yaml[line-length]
hostname: "loadbalancer"
domain: "{{ domain }}"
cluster_name: "{{ cluster.name }}"
sshkey: "{{ ssh_service_key_pub }}"
state: present
become: true
register: output_lb
- name: Add bastion and loadbalancer to in-memory inventory
ansible.builtin.add_host:
hostname: "{{ item.key }}"
ansible_host: "{{ item.value[0].ip }}"
ansible_ssh_private_key_file: "{{ playbook_dir }}/id_rsa_ocp_setup"
ansible_user: ocpinstall
ansible_ssh_common_args: "-o StrictHostKeyChecking=no"
domain: "{{ domain }}"
cluster_name: "{{ cluster.name }}"
ocp_domain: "{{ ocp_domain }}"
timezone: "{{ dhcp.timezone }}"
ntp_server: "{{ dhcp.ntp }}"
loop: "{{ infra_nodes.host_list | dict2items }}"
delegate_to: localhost
- name: Check connection to infra VMs and set facts
hosts: bastion,loadbalancer
gather_facts: false
tasks:
- name: Wait 600 seconds for target connection to become reachable/usable
ansible.builtin.wait_for_connection:
timeout: 120
delay: 0
- name: Verify the host can be reached
ansible.builtin.ping:
- name: Save host facts
ansible.builtin.setup:
register: machine_facts
- name: Fetch specific facts for further use
ansible.builtin.set_fact:
host_ip: "{{ machine_facts.ansible_facts.ansible_default_ipv4.address }}"
host_interface: "{{ machine_facts.ansible_facts.ansible_default_ipv4.interface }}"
host_mac: "{{ machine_facts.ansible_facts.ansible_default_ipv4.macaddress }}"
host_fqdn: "{{ machine_facts.ansible_facts.ansible_fqdn }}"
- name: Fetch specific facts for further use
ansible.builtin.set_fact:
host_api_fqdn: "api.{{ ocp_domain }}"
host_api_int_fqdn: "api-int.{{ ocp_domain }}"
host_apps_fqdn: "apps.{{ ocp_domain }}"
when: inventory_hostname == 'loadbalancer'