|
13 | 13 | state: present
|
14 | 14 | become: true
|
15 | 15 |
|
| 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 | + |
16 | 40 | - name: Ensure the cron/crond service is running
|
17 | 41 | ansible.builtin.service:
|
18 | 42 | name: "{{ 'cron' if ansible_facts['distribution'] == 'Ubuntu' else 'crond' }}"
|
19 | 43 | state: started
|
20 | 44 | enabled: true
|
21 | 45 | become: true
|
22 | 46 |
|
23 |
| - - name: Copy smartmon.sh and nvmemon.sh from scripts folder |
| 47 | + - name: Copy smartmon.py and nvmemon.sh from scripts folder |
24 | 48 | ansible.builtin.copy:
|
25 | 49 | src: scripts/{{ item }}
|
26 |
| - dest: /usr/local/bin/ |
| 50 | + dest: /usr/local/bin/{{ item }} |
27 | 51 | owner: root
|
28 | 52 | group: root
|
29 | 53 | mode: "0700"
|
30 | 54 | loop:
|
31 |
| - - smartmon.sh |
| 55 | + - smartmon.py |
32 | 56 | - nvmemon.sh
|
33 | 57 | become: true
|
34 | 58 |
|
|
40 | 64 | job: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
41 | 65 | become: true
|
42 | 66 |
|
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 |
44 | 68 | 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 |
46 | 80 | user: root
|
47 | 81 | minute: "*/5"
|
48 | 82 | 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 |
52 | 94 | loop:
|
53 | 95 | - smartmon
|
54 | 96 | - nvmemon
|
| 97 | + |
| 98 | + - name: Remove old smartmon.sh if present |
| 99 | + ansible.builtin.file: |
| 100 | + path: /usr/local/bin/smartmon.sh |
| 101 | + state: absent |
55 | 102 | become: true
|
0 commit comments