Skip to content

Commit 04edbb0

Browse files
committed
MAINT: Reduce terraform provisioning to a single VM
We do not need a VM for each service when we can run all services on a single VM. This reduces the scale and complexity of the deployment. There is not enough traffic to justify having this much compute resource.
1 parent 0b5fe5e commit 04edbb0

File tree

14 files changed

+61
-375
lines changed

14 files changed

+61
-375
lines changed

chatops_deployment/ansible/configure.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,56 @@
11
---
22
- name: Configure load balancer
3-
hosts: haproxy
3+
hosts: stack
44
roles:
55
- role: haproxy
66
tags:
77
- haproxy
88

99
- name: Configure ChatOps
10-
hosts: chatops
10+
hosts: stack
1111
roles:
1212
- role: chatops
1313
tags:
1414
- chatops
1515

1616
- name: Configure CAdvisor
17-
hosts: chatops
17+
hosts: stack
1818
remote_user: ubuntu
1919
roles:
2020
- role: cadvisor
2121
tags:
2222
- cadvisor
2323

2424
- name: Set up systemd exporters
25-
hosts: all
25+
hosts: stack
2626
roles:
2727
- role: systemd_exporter
2828
tags:
2929
- systemd_exporter
3030

3131
- name: Configure Grafana
32-
hosts: grafana
32+
hosts: stack
3333
roles:
3434
- grafana
3535
tags:
3636
- grafana
3737

3838
- name: Configure Prometheus
39-
hosts: prometheus
39+
hosts: stack
4040
roles:
4141
- prometheus
4242
tags:
4343
- prometheus
4444

4545
- name: Configure Alert Manager
46-
hosts: prometheus
46+
hosts: stack
4747
roles:
4848
- alertmanager
4949
tags:
5050
- alertmanager
5151

5252
- name: Configure Elastic Stack
53-
hosts: elastic
53+
hosts: stack
5454
remote_user: ubuntu
5555
force_handlers: true
5656
roles:

chatops_deployment/ansible/roles/elastic/templates/kibana.yml.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
server.host: {{ inventory_hostname }}
1+
server.host: localhost
22
server.port: 5601
33
server.publicBaseUrl: https://kibana.{{ domain }}:443
44
elasticsearch.hosts: ["https://localhost:9200"]

chatops_deployment/ansible/roles/grafana/templates/grafana.ini.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Configure server settings
33
domain = grafana.{{ domain }}
44
root_url = https://grafana.{{ domain }}:443/
5-
http_addr = {{ inventory_hostname }}
5+
http_addr = 127.0.0.1
66
protocol = http
77
http_port = 3000
88

chatops_deployment/ansible/roles/ssh_known_hosts/tasks/main.yml

Lines changed: 17 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -2,66 +2,23 @@
22
- name: Refresh inventory to grab latest changes
33
ansible.builtin.meta: refresh_inventory
44

5-
- name: Add ssh key to agent
6-
block:
7-
- name: Install expect
8-
become: true
9-
ansible.builtin.apt:
10-
name: expect
11-
update_cache: true
12-
13-
- name: Add key to ssh-agent
14-
ansible.builtin.command: |
15-
expect << EOF
16-
spawn ssh-add bastion-key
17-
expect "Enter passphrase for bastion-key:"
18-
send "{{ bastion_key_passphrase }}\r"
19-
expect eof
20-
EOF
21-
register: ssh_known_hosts_
22-
changed_when: ssh_known_hosts_.rc != 0
23-
24-
- name: Remove FIP known hosts
25-
ansible.builtin.command: 'ssh-keygen -R "{{ terraform_floating_ip }}"'
26-
register: ssh_known_hosts_
27-
changed_when: ssh_known_hosts_.rc != 0
5+
- name: Remove FIP from known hosts
6+
ansible.builtin.known_hosts:
7+
name: "{{ item }}"
8+
state: absent
9+
loop:
10+
- "{{ terraform_floating_ip }}"
11+
- "{{ domain }}"
2812

29-
- name: Remove private VM known host entries
30-
ansible.builtin.command: "ssh-keygen -R {{ item }}"
31-
loop: "{{ groups['private'] }}"
32-
register: ssh_known_hosts_
33-
changed_when: ssh_known_hosts_.rc != 0
13+
- name: Wait for VMs to be ready
14+
ansible.builtin.wait_for:
15+
timeout: 10
3416

3517
- name: Add FIP fingerprint to known hosts
36-
ansible.builtin.command: 'ssh-keyscan "{{ terraform_floating_ip }}" >> ~/.ssh/known_hosts'
37-
register: ssh_known_hosts_
38-
changed_when: ssh_known_hosts_.rc != 0
39-
40-
- name: Get private VM fingerprints and retrieve to local host
41-
delegate_to: "{{ terraform_floating_ip }}"
42-
block:
43-
- name: Add private VM fingerprints to known hosts on LB
44-
ansible.builtin.command: 'ssh-keyscan "{{ item }}" >> ~/.ssh/known_hosts'
45-
loop: "{{ groups['private'] }}"
46-
register: ssh_known_hosts_
47-
changed_when: ssh_known_hosts_.rc != 0
48-
49-
- name: Retrieve known hosts from LB
50-
ansible.builtin.fetch:
51-
src: "~/.ssh/known_hosts"
52-
dest: "private_known_hosts.tmp"
53-
flat: true
54-
register: ssh_known_hosts_
55-
changed_when: ssh_known_hosts_.rc != 0
56-
57-
- name: Append fetched known hosts to localhost
58-
ansible.builtin.command: "cat private_known_hosts.tmp >> ~/.ssh/known_hosts"
59-
register: ssh_known_hosts_
60-
changed_when: ssh_known_hosts_.rc != 0
61-
62-
- name: Remove private_known_hosts.tmp
63-
ansible.builtin.file:
64-
path: "private_known_hosts.tmp"
65-
state: absent
66-
register: ssh_known_hosts_
67-
changed_when: ssh_known_hosts_.rc != 0
18+
ansible.builtin.known_hosts:
19+
name: "{{ item }}"
20+
state: present
21+
key: "{{ lookup('ansible.builtin.pipe', 'ssh-keyscan {{ item }}') }}"
22+
loop:
23+
- "{{ terraform_floating_ip }}"
24+
- "{{ domain }}"

chatops_deployment/ansible/roles/terraform/tasks/destroy.yml

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,6 @@
1919

2020
- name: Remove generated files
2121
block:
22-
- name: Delete hosts.ini file
23-
ansible.builtin.file:
24-
path: hosts.ini
25-
state: absent
26-
27-
- name: Touch hosts.ini file
28-
ansible.builtin.file:
29-
path: hosts.ini
30-
state: touch
31-
owner: "{{ ansible_env.USER }}"
32-
group: "{{ ansible_env.USER }}"
33-
mode: "0774"
34-
3522
- name: Delete terraform.tfvars file
3623
ansible.builtin.file:
3724
path: "../terraform/terraform.tfvars"
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
deployment="{{ terraform_deployment }}"
22
external_network_id="{{ terraform_external_network_id }}"
33
floating_ip="{{ terraform_floating_ip }}"
4-
elasticsearch_volume_id="{{ terraform_elasticsearch_volume_id }}"
4+
stack_volume_id="{{ terraform_stack_volume_id }}"
5+
environment="{{ env }}"

chatops_deployment/terraform/main.tf

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,10 @@ module "networking" {
2121

2222
module "compute" {
2323
source = "./modules/compute"
24-
grafana_secgroup = module.networking.grafana_secgroup
25-
chatops_secgroup = module.networking.chatops_secgroup
26-
prometheus_secgroup = module.networking.prometheus_secgroup
27-
elasticsearch_secgroup = module.networking.elasticsearch_secgroup
28-
loadbalancer_secgroup = module.networking.loadbalancer_secgroup
24+
stack_secgroup = module.networking.stack_secgroup
2925
private_network = module.networking.private_network
3026
private_subnet = module.networking.private_subnet
3127
floating_ip = var.floating_ip
3228
deployment = var.deployment
33-
elasticsearch_volume_id = var.elasticsearch_volume_id
29+
stack_volume_id = var.stack_volume_id
3430
}

chatops_deployment/terraform/modules/compute/main.tf

Lines changed: 13 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -17,85 +17,33 @@ resource "openstack_compute_keypair_v2" "bastion_keypair" {
1717
public_key = file("bastion-key.pub")
1818
}
1919

20-
resource "openstack_compute_instance_v2" "grafana" {
21-
name = "grafana-host-${var.deployment}"
20+
resource "openstack_compute_instance_v2" "stack" {
21+
name = "chatops-stack-${var.deployment}"
2222
image_name = "ubuntu-jammy-22.04-nogui"
23-
flavor_name = "l3.nano"
23+
flavor_name = "l3.micro"
2424
key_pair = openstack_compute_keypair_v2.bastion_keypair.name
25-
security_groups = ["default", var.grafana_secgroup.name]
26-
count = 2
25+
security_groups = ["default", var.stack_secgroup.name]
2726

2827
network {
2928
name = var.private_network.name
29+
fixed_ip_v4 = "192.168.100.100"
3030
}
31-
depends_on = [var.private_subnet]
32-
}
33-
34-
resource "openstack_compute_instance_v2" "prometheus" {
35-
name = "prometheus-host-${var.deployment}"
36-
image_name = "ubuntu-jammy-22.04-nogui"
37-
flavor_name = "l3.nano"
38-
key_pair = openstack_compute_keypair_v2.bastion_keypair.name
39-
security_groups = ["default", var.prometheus_secgroup.name]
40-
41-
network {
42-
name = var.private_network.name
43-
}
44-
depends_on = [var.private_subnet]
45-
}
46-
47-
resource "openstack_compute_instance_v2" "elastic" {
48-
name = "elasticsearch-host-${var.deployment}"
49-
image_name = "ubuntu-jammy-22.04-nogui"
50-
flavor_name = "l3.tiny"
51-
key_pair = openstack_compute_keypair_v2.bastion_keypair.name
52-
security_groups = ["default", var.elasticsearch_secgroup.name]
5331

54-
network {
55-
name = var.private_network.name
56-
}
5732
depends_on = [var.private_subnet]
5833
}
5934

60-
resource "openstack_compute_volume_attach_v2" "elasticsearch_volume" {
61-
instance_id = openstack_compute_instance_v2.elastic.id
62-
volume_id = var.elasticsearch_volume_id
63-
}
64-
65-
resource "openstack_compute_instance_v2" "chatops" {
66-
name = "chatops-host-${var.deployment}"
67-
image_name = "ubuntu-jammy-22.04-nogui"
68-
flavor_name = "l3.nano"
69-
key_pair = openstack_compute_keypair_v2.bastion_keypair.name
70-
security_groups = ["default", var.chatops_secgroup.name]
71-
count = 3
72-
73-
network {
74-
name = var.private_network.name
75-
}
76-
depends_on = [var.private_subnet]
77-
}
78-
79-
resource "openstack_compute_instance_v2" "loadbalancer" {
80-
name = "loadbalancer-host-${var.deployment}"
81-
image_name = "ubuntu-jammy-22.04-nogui"
82-
flavor_name = "l3.nano"
83-
key_pair = openstack_compute_keypair_v2.bastion_keypair.name
84-
security_groups = ["default", var.loadbalancer_secgroup.name]
85-
86-
network {
87-
name = var.private_network.name
88-
}
89-
depends_on = [var.private_subnet]
35+
resource "openstack_compute_volume_attach_v2" "stack_volume" {
36+
instance_id = openstack_compute_instance_v2.stack.id
37+
volume_id = var.stack_volume_id
9038
}
9139

92-
data "openstack_networking_port_v2" "loadbalancer_port" {
93-
fixed_ip = openstack_compute_instance_v2.loadbalancer.network[0].fixed_ip_v4
94-
network_id = openstack_compute_instance_v2.loadbalancer.network[0].uuid
40+
data "openstack_networking_port_v2" "stack_port" {
41+
fixed_ip = openstack_compute_instance_v2.stack.network[0].fixed_ip_v4
42+
network_id = openstack_compute_instance_v2.stack.network[0].uuid
9543
}
9644

9745
resource "openstack_networking_floatingip_associate_v2" "floating_ip" {
9846
floating_ip = var.floating_ip
99-
port_id = data.openstack_networking_port_v2.loadbalancer_port.id
100-
depends_on = [openstack_compute_instance_v2.loadbalancer]
47+
port_id = data.openstack_networking_port_v2.stack_port.id
48+
depends_on = [openstack_compute_instance_v2.stack]
10149
}
Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,3 @@
1-
output "grafana_host_ips" {
2-
value = openstack_compute_instance_v2.grafana.*.access_ip_v4
1+
output "stack_volume_device" {
2+
value = openstack_compute_volume_attach_v2.stack_volume.device
33
}
4-
5-
output "chatops_host_ips" {
6-
value = openstack_compute_instance_v2.chatops.*.access_ip_v4
7-
}
8-
9-
output "prometheus_host_ips" {
10-
value = openstack_compute_instance_v2.prometheus.*.access_ip_v4
11-
}
12-
13-
output "elastic_host_ips" {
14-
value = openstack_compute_instance_v2.elastic.*.access_ip_v4
15-
}
16-
17-
output "loadbalancer_host_ip" {
18-
value = openstack_compute_instance_v2.loadbalancer.access_ip_v4
19-
}
20-
21-
output "elasticsearch_device" {
22-
value = openstack_compute_volume_attach_v2.elasticsearch_volume.device
23-
}
Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
variable "deployment" {}
2-
variable "grafana_secgroup" {}
3-
variable "chatops_secgroup" {}
4-
variable "prometheus_secgroup" {}
5-
variable "elasticsearch_secgroup" {}
6-
variable "loadbalancer_secgroup" {}
72
variable "private_network" {}
83
variable "floating_ip" {}
94
variable "private_subnet" {}
10-
variable "elasticsearch_volume_id" {}
5+
variable "stack_volume_id" {}
6+
variable "stack_secgroup" {}

0 commit comments

Comments
 (0)