Skip to content

Commit 80fe22c

Browse files
Merge pull request #238 from stfc/ssh_key_volume
Add ssh key and mount volume
2 parents b61b4d3 + 087018a commit 80fe22c

File tree

9 files changed

+78
-24
lines changed

9 files changed

+78
-24
lines changed

chatops_deployment/ansible/configure.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
---
2+
- name: Add SSH key to agent
3+
hosts: localhost
4+
tags:
5+
- key
6+
tasks:
7+
- name: Add SSH key
8+
ansible.builtin.include_role:
9+
name: add_ssh_key
10+
211
- name: Configure load balancer
312
hosts: stack
413
roles:
@@ -35,6 +44,14 @@
3544
tags:
3645
- grafana
3746

47+
- name: Attach volume
48+
hosts: stack
49+
gather_facts: true
50+
roles:
51+
- volume
52+
tags:
53+
- volume
54+
3855
- name: Configure Prometheus
3956
hosts: stack
4057
roles:

chatops_deployment/ansible/deploy.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,14 @@
77
name: terraform
88
tasks_from: deploy
99

10-
- name: Add known hosts of bastion host and private VMs
10+
- name: Add SSH key to agent
11+
hosts: localhost
12+
tasks:
13+
- name: Add SSH key
14+
ansible.builtin.include_role:
15+
name: add_ssh_key
16+
17+
- name: Add known host of stack VM
1118
hosts: localhost
1219
gather_facts: false
1320
roles:
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
- name: Install expect
3+
become: true
4+
ansible.builtin.apt:
5+
name: expect
6+
update_cache: true
7+
8+
- name: Start ssh-agent
9+
# noqa: command-instead-of-shell
10+
# interpolation is not supported by the command module
11+
ansible.builtin.shell: 'eval $("ssh-agent -s")'
12+
register: add_ssh_key_start_agent
13+
changed_when: add_ssh_key_start_agent.rc == 0
14+
15+
- name: Add key to ssh-agent
16+
# noqa: command-instead-of-shell
17+
# We must use shell here as here-docs don't work with command
18+
ansible.builtin.shell: |
19+
expect << EOF
20+
spawn ssh-add {{ env }}-bastion-key
21+
expect "Enter passphrase for {{ env }}-bastion-key:"
22+
send "{{ bastion_key_passphrase }}\r"
23+
expect eof
24+
EOF
25+
register: add_ssh_key_add_key
26+
changed_when: add_ssh_key_add_key.rc == 0

chatops_deployment/ansible/roles/elastic/files/elasticsearch.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
path:
3-
data: /var/elasticsearch/data
3+
data: /var/stack/elasticsearch/data
44
logs: /var/log/elasticsearch
55
cluster.name: chatops-elasticsearch
66
xpack.security.enabled: true

chatops_deployment/ansible/roles/elastic/tasks/elasticsearch.yml

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,10 @@
3636
state: latest # noqa: package-latest
3737
update_cache: true
3838

39-
- name: Attach data volume to Elasticsearch data directory
40-
become: true
41-
ansible.posix.mount:
42-
boot: true
43-
path: /var/elasticsearch/data
44-
src: "{{ elasticsearch_device }}"
45-
state: mounted
46-
fstype: ext4
47-
4839
- name: Set permissions on volume
4940
become: true
5041
ansible.builtin.file:
51-
path: /var/elasticsearch/data
42+
path: /var/stack/elasticsearch/data
5243
state: directory
5344
owner: root
5445
group: elasticsearch

chatops_deployment/ansible/roles/prometheus/files/prometheus.service

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Group=prometheus
99
Restart=on-failure
1010
ExecStart=/opt/prometheus/prometheus \
1111
--config.file=/opt/prometheus/prometheus.yml \
12-
--storage.tsdb.path=/opt/prometheus/data \
12+
--storage.tsdb.path=/var/stack/prometheus/data \
1313
--storage.tsdb.retention.time=30d \
1414
--web.config.file=/opt/prometheus/web.yml
1515
StandardOutput=append:/var/log/prometheus/prometheus.log

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,18 @@
3434
- Move Prometheus binaries
3535
- Start Prometheus
3636

37-
- name: Attach volume to Prometheus data directory
38-
become: true
39-
ansible.posix.mount:
40-
boot: true
41-
path: /var/prometheus/data
42-
src: "{{ prometheus_device }}"
43-
state: mounted
44-
fstype: ext4
37+
- name: Flush handlers to move binaries
38+
ansible.builtin.meta: flush_handlers
4539

4640
- name: Set permissions on volume
4741
become: true
4842
ansible.builtin.file:
49-
path: /var/prometheus/data
43+
path: /var/stack/prometheus/data
5044
state: directory
5145
owner: prometheus
5246
group: prometheus
5347
mode: "0774"
48+
recurse: true
5449

5550
- name: Copy prometheus service file
5651
become: true

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
- name: Download and extract systemd-exporter
2727
become: true
2828
ansible.builtin.unarchive:
29-
src: "https://github.com/prometheus-community/systemd_exporter/releases/download/v{{ systemd_exporter_version }}/systemd_exporter-{{ systemd_exporter_version
30-
}}.linux-amd64.tar.gz"
29+
src: "https://github.com/prometheus-community/systemd_exporter/releases/download/v{{ systemd_exporter_version }}/
30+
systemd_exporter-{{ systemd_exporter_version}}.linux-amd64.tar.gz"
3131
dest: /tmp
3232
remote_src: true
3333
creates: "/tmp/systemd_exporter-{{ systemd_exporter_version }}.linux-amd64"
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
- name: Attach volume to stack host
3+
become: true
4+
ansible.posix.mount:
5+
boot: true
6+
path: /var/stack
7+
src: "{{ ansible_local.terraform.vars.stack_device }}"
8+
state: mounted
9+
fstype: ext4
10+
11+
- name: Set permissions
12+
become: true
13+
ansible.builtin.file:
14+
state: directory
15+
path: /var/stack
16+
owner: ubuntu
17+
group: ubuntu
18+
mode: "0775"

0 commit comments

Comments
 (0)