Skip to content

Commit 1bc5733

Browse files
committed
Update smartmon playbook for smartmon.py
1 parent 4b1fc1f commit 1bc5733

File tree

1 file changed

+55
-8
lines changed

1 file changed

+55
-8
lines changed

etc/kayobe/ansible/smartmon-tools.yml

Lines changed: 55 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,46 @@
1313
state: present
1414
become: true
1515

16+
- name: Ensure Python 3, venv, and pip are installed
17+
ansible.builtin.package:
18+
name:
19+
- python3
20+
- python3-venv
21+
- python3-pip
22+
state: present
23+
become: true
24+
25+
- name: Create smartmon Python virtual environment
26+
ansible.builtin.command:
27+
cmd: python3 -m venv /opt/smartmon-venv
28+
creates: /opt/smartmon-venv/bin/activate
29+
become: true
30+
31+
- name: Install prometheus_client and pySMART in venv
32+
ansible.builtin.pip:
33+
name:
34+
- prometheus_client
35+
- pySMART
36+
virtualenv: /opt/smartmon-venv
37+
virtualenv_python: python3
38+
become: true
39+
1640
- name: Ensure the cron/crond service is running
1741
ansible.builtin.service:
1842
name: "{{ 'cron' if ansible_facts['distribution'] == 'Ubuntu' else 'crond' }}"
1943
state: started
2044
enabled: true
2145
become: true
2246

23-
- name: Copy smartmon.sh and nvmemon.sh from scripts folder
47+
- name: Copy smartmon.py and nvmemon.sh from scripts folder
2448
ansible.builtin.copy:
2549
src: scripts/{{ item }}
26-
dest: /usr/local/bin/
50+
dest: /usr/local/bin/{{ item }}
2751
owner: root
2852
group: root
2953
mode: "0700"
3054
loop:
31-
- smartmon.sh
55+
- smartmon.py
3256
- nvmemon.sh
3357
become: true
3458

@@ -40,16 +64,39 @@
4064
job: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
4165
become: true
4266

43-
- name: Schedule cronjob to run both scripts every 5 minutes and save output to file
67+
- name: Schedule cronjob to run smartmon.py every 5 minutes and save output to file
4468
ansible.builtin.cron:
45-
name: SMART metrics for drive monitoring using {{ item }}
69+
name: SMART metrics for drive monitoring using smartmon.py
70+
user: root
71+
minute: "*/5"
72+
job: >-
73+
umask 0022 && /opt/smartmon-venv/bin/python /usr/local/bin/smartmon.py --output /var/lib/docker/volumes/textfile/_data/smartmon.prom.temp &&
74+
mv -f /var/lib/docker/volumes/textfile/_data/smartmon.prom.temp /var/lib/docker/volumes/textfile/_data/smartmon.prom
75+
become: true
76+
77+
- name: Schedule cronjob to run nvmemon.sh every 5 minutes and save output to file
78+
ansible.builtin.cron:
79+
name: SMART metrics for drive monitoring using nvmemon.sh
4680
user: root
4781
minute: "*/5"
4882
job: >-
49-
umask 0022 && /usr/local/bin/{{ item }}.sh >
50-
/var/lib/docker/volumes/textfile/_data/{{ item }}.prom.temp &&
51-
mv -f /var/lib/docker/volumes/textfile/_data/{{ item }}.prom.temp /var/lib/docker/volumes/textfile/_data/{{ item }}.prom
83+
umask 0022 && /usr/local/bin/nvmemon.sh >
84+
/var/lib/docker/volumes/textfile/_data/nvmemon.prom.temp &&
85+
mv -f /var/lib/docker/volumes/textfile/_data/nvmemon.prom.temp /var/lib/docker/volumes/textfile/_data/nvmemon.prom
86+
become: true
87+
88+
- name: Remove old cronjobs if present
89+
ansible.builtin.cron:
90+
name: SMART metrics for drive monitoring using {{ item }}
91+
user: root
92+
state: absent
93+
become: true
5294
loop:
5395
- smartmon
5496
- nvmemon
97+
98+
- name: Remove old smartmon.sh if present
99+
ansible.builtin.file:
100+
path: /usr/local/bin/smartmon.sh
101+
state: absent
55102
become: true

0 commit comments

Comments
 (0)