Verified Commit 109f2259 authored by Hugo's avatar Hugo
Browse files

ansible basics + extra workers

parent 38af0403
......@@ -2,4 +2,5 @@
terraform.tfstate
terraform.tfstate.backup
terraform.tfstate.d
values.auto.tfvars
\ No newline at end of file
values.auto.tfvars
inventory.yaml
\ No newline at end of file
[defaults]
interpreter_python = /usr/bin/python3
host_key_checking = False
\ No newline at end of file
wireguard
snd-aloop
\ No newline at end of file
- name: upgrades nodes
hosts: all
remote_user: root
handlers:
- name: reboot
reboot: {}
tasks:
- name: update packages
ansible.builtin.apt:
update_cache: yes
upgrade: safe
notify: reboot
- name: update kernel
ansible.builtin.apt:
default_release: buster-backports
state: latest
name:
- linux-headers-amd64
- linux-image-amd64
notify: reboot
- name: prepare workers
hosts: workers
remote_user: root
handlers:
- name: reboot
reboot: {}
tasks:
- name: install wireguard
ansible.builtin.package:
name: wireguard
- name: copy modules.conf
ansible.builtin.copy:
src: modules.conf
dest: /etc/modules-load.d/modules.conf
notify: reboot
resource "local_file" "ansible_inventory" {
content = yamlencode({
all = {
children = {
controllers = {
hosts = { for ip in hcloud_server.controller.*.ipv4_address : ip => {} }
}
workers = {
hosts = { for ip in hcloud_server.worker.*.ipv4_address : ip => {} }
}
}
vars = {
control_plane_lb = hcloud_load_balancer.control_plane_load_balancer.ipv4
ingress_lb = hcloud_load_balancer.ingress_load_balancer.ipv4
}
}
})
filename = "${path.module}/../inventory.yaml"
}
......@@ -3,7 +3,7 @@ output "controller_ipv4" {
}
output "worker_ipv4" {
value = hcloud_server.worker.*.ipv4_address
value = concat(hcloud_server.worker.*.ipv4_address,var.extra_workers)
}
output "control_plane_ipv4" {
......
......@@ -72,3 +72,9 @@ variable "ingress_lb_type" {
description = "Ingress load balancer type"
type = string
}
variable "extra_workers" {
description = "Ip list of extra workers"
type = list(string)
default = []
}
......@@ -43,3 +43,10 @@ resource "hcloud_load_balancer_service" "ingress_load_balancer_service" {
listen_port = each.value
destination_port = each.value
}
resource "hcloud_load_balancer_target" "ingress_load_balancer_target" {
for_each = toset(var.extra_workers)
type = "ip"
load_balancer_id = hcloud_load_balancer.ingress_load_balancer.id
ip = each.value
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment