2023-06-10 13:10:47 +00:00
- name : Record (initial) disk space used
shell : df -B1 --output=used / | tail -1
2023-05-27 07:26:04 +00:00
register : df1
2023-05-01 15:21:39 +00:00
- name : Install 'vnstat' package
package :
name : vnstat
state : present
# Similar code block in roles/network/tasks/detected_network.yml (line ~35) and roles/network/tasks/computed_network.yml (lines ~74 and ~110)
2022-06-30 06:31:56 +00:00
- name : "Setting iiab_wan_iface to '{{ ansible_default_ipv4.alias }}' -- using ansible_default_ipv4.alias if detected"
2022-06-30 00:01:03 +00:00
set_fact :
2022-06-30 03:25:57 +00:00
iiab_wan_iface : "{{ ansible_default_ipv4.alias }}"
2022-06-30 00:01:03 +00:00
when : ansible_default_ipv4.gateway is defined
2023-05-01 15:41:04 +00:00
# 2023-05-01: Probably no longer nec, as line 'Interface ""' in /etc/vnstat.conf (as installed by apt) automatically selects the default interface
2023-05-01 15:21:39 +00:00
- name : Insert 'Interface "{{ iiab_wan_iface }}"' into /etc/vnstat.conf
lineinfile :
path : /etc/vnstat.conf
regexp : '^Interface '
line : 'Interface "{{ iiab_wan_iface }}"'
2022-06-30 00:01:03 +00:00
2023-05-01 15:21:39 +00:00
# - name: Install /etc/vnstat.conf from template
# template:
# src: vnstat.conf.j2
# dest: /etc/vnstat.conf
# mode: '0744'
2020-09-22 05:04:06 +00:00
2023-05-01 15:21:39 +00:00
# 2023-05-01: https://github.com/vergoh/vnstat/issues/134#issuecomment-663836557
- name : 'Precautionary Start & Enable of vnstat.service, to mitigate intermittent #3539 (' 'Failed to open database "/var/lib/vnstat/vnstat.db" in read-only mode' ') during WAN db creation just below'
systemd :
name : vnstat
daemon_reload : true
state : started
enabled : true
2022-06-30 00:01:03 +00:00
2020-09-22 05:04:06 +00:00
- name : Create database for WAN to collect vnStat data
shell : /usr/bin/vnstat -i {{ iiab_wan_iface }}
- name : Create database for LAN to collect vnStat data if not appliance config
shell : /usr/bin/vnstat -i {{ iiab_lan_iface }}
when : iiab_lan_iface is defined and iiab_lan_iface != "none"
# RECORD vnStat AS INSTALLED
2023-06-10 13:10:47 +00:00
- name : Record (final) disk space used
shell : df -B1 --output=used / | tail -1
2023-05-27 07:26:04 +00:00
register : df2
2023-06-10 13:10:47 +00:00
- name : Add 'vnstat_disk_usage = {{ df2.stdout|int - df1.stdout|int }}' to {{ iiab_ini_file }}
2023-05-27 07:26:04 +00:00
ini_file :
path : "{{ iiab_ini_file }}" # /etc/iiab/iiab.ini
section : vnstat
option : vnstat_disk_usage
2023-06-10 13:10:47 +00:00
value : "{{ df2.stdout|int - df1.stdout|int }}"
2023-05-27 07:26:04 +00:00
2020-09-22 05:04:06 +00:00
- name : "Set 'vnstat_installed: True'"
set_fact :
vnstat_installed : True
- name : "Add 'vnstat_installed: True' to {{ iiab_state_file }}"
lineinfile :
path : "{{ iiab_state_file }}" # /etc/iiab/iiab_state.yml
regexp : '^vnstat_installed'
line: 'vnstat_installed : True '