-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.yml
60 lines (52 loc) · 2.27 KB
/
build.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
---
- name: Build infrastructure
hosts: localhost
connection: local
vars_files:
- vars/main.yml
tasks:
- name: Check if Hetzner API token is provided
assert: # noqa fqcn[action-core]
that: terraform_var_hcloud_token != ""
fail_msg: "No Hetzner Cloud API token provided"
- name: Check if Hetzner SSH key name is provided
assert: # noqa fqcn[action-core]
that: terraform_var_ssh_key_name != ""
fail_msg: "No Hetzner Cloud SSH key name provided"
- name: Check if Cloudflare API token is provided
assert: # noqa fqcn[action-core]
that: terraform_var_cf_api_token != ""
fail_msg: "No Cloudflare API token provided"
- name: Check if domain name is provided
assert: # noqa fqcn[action-core]
that: terraform_var_cf_zone_name != ""
fail_msg: "No domain name provided"
# create the tfvars file for future use directly through terraform
- name: Create tfvars file
ansible.builtin.copy:
dest: "{{ terraform_project_dir }}/terraform.tfvars"
content: |
hcloud_token = "{{ terraform_var_hcloud_token }}"
cloudflare_api_token = "{{ terraform_var_cf_api_token }}"
cloudflare_zone_name = "{{ terraform_var_cf_zone_name }}"
bastion_username = "{{ terraform_var_bastion_username }}"
ssh_key_name = "{{ terraform_var_ssh_key_name }}"
network_ip_range = "{{ terraform_var_network_ip_range }}"
subnet_ip_range = "{{ terraform_var_subnet_ip_range }}"
loadbalancer_count = {{ terraform_var_loadbalancer_count }}
server_node_count = {{ terraform_var_server_node_count }}
client_node_count = {{ terraform_var_client_node_count }}
# Terraform apply
- name: Deploy infrastructure with terraform
community.general.terraform:
overwrite_init: false
force_init: true
project_path: "{{ terraform_project_dir }}"
state: present
- name: Update inventory with inventory created by terraform
ansible.builtin.meta: refresh_inventory
- name: Wait a while for the instances to finish initializing
ansible.builtin.pause:
seconds: 15
- name: Provision all the instances
import_playbook: provision.yml