From 21a7d70c7e625f51c6b6c7b5011781b6576137ec Mon Sep 17 00:00:00 2001 From: root Date: Mon, 1 May 2023 11:21:39 -0400 Subject: [PATCH 1/2] Toughen up vnStat: Mitigate #3539 db errors, stop using 2011's /etc/vnstat.conf, etc --- roles/vnstat/tasks/install.yml | 39 +++++++++++++------ .../{vnstat.conf.j2 => vnstat.conf.j2.unused} | 0 test.yml | 8 +++- 3 files changed, 33 insertions(+), 14 deletions(-) rename roles/vnstat/templates/{vnstat.conf.j2 => vnstat.conf.j2.unused} (100%) diff --git a/roles/vnstat/tasks/install.yml b/roles/vnstat/tasks/install.yml index 84bec243c..f1d65ada9 100644 --- a/roles/vnstat/tasks/install.yml +++ b/roles/vnstat/tasks/install.yml @@ -1,21 +1,36 @@ -# Similar code block in roles/network/tasks/detected_network.yml -- name: "Setting iiab_wan_iface to '{{ ansible_default_ipv4.alias }}' -- using ansible_default_ipv4.alias if detected" - set_fact: - iiab_wan_iface: "{{ ansible_default_ipv4.alias }}" - when: ansible_default_ipv4.gateway is defined - - - name: Install 'vnstat' package package: name: vnstat state: present -- name: Install /etc/vnstat.conf from template - template: - src: vnstat.conf.j2 - dest: /etc/vnstat.conf - mode: '0744' +# Similar code block in roles/network/tasks/detected_network.yml (line ~35) and roles/network/tasks/computed_network.yml (lines ~74 and ~110) +- name: "Setting iiab_wan_iface to '{{ ansible_default_ipv4.alias }}' -- using ansible_default_ipv4.alias if detected" + set_fact: + iiab_wan_iface: "{{ ansible_default_ipv4.alias }}" + when: ansible_default_ipv4.gateway is defined + +# 2023-05-01: Probably no longer nec, as line 'Interface ""' in /etc/vnstat.conf automatically selects the default interface +- name: Insert 'Interface "{{ iiab_wan_iface }}"' into /etc/vnstat.conf + lineinfile: + path: /etc/vnstat.conf + regexp: '^Interface ' + line: 'Interface "{{ iiab_wan_iface }}"' + +# - name: Install /etc/vnstat.conf from template +# template: +# src: vnstat.conf.j2 +# dest: /etc/vnstat.conf +# mode: '0744' + + +# 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 - name: Create database for WAN to collect vnStat data shell: /usr/bin/vnstat -i {{ iiab_wan_iface }} diff --git a/roles/vnstat/templates/vnstat.conf.j2 b/roles/vnstat/templates/vnstat.conf.j2.unused similarity index 100% rename from roles/vnstat/templates/vnstat.conf.j2 rename to roles/vnstat/templates/vnstat.conf.j2.unused diff --git a/test.yml b/test.yml index bfda3f92a..8eb2e9be0 100644 --- a/test.yml +++ b/test.yml @@ -27,11 +27,15 @@ - name: DOUBLE UP to escape single quotes... '"''"' e.g. iiab.ini descriptions for azuracast, captiveportal, mosquitto, munin, nodejs, osm-vector-maps, sshd debug: - msg: '"''"' # FAILS: '"\'"' + msg: '"''"' # OR: '''' FAILS: '"\'"' - name: BACKSLASH to escape double quotes... "'\"'" e.g. cups/tasks/install.yml debug: - msg: "'\"'" # FAILS: "'""'" + msg: "'\"'" # OR: "\"" FAILS: "'""'" + + - name: "Entire string must be enclosed in quotes if using ' #' Space-then-Pound/Hash sequence -- or right side will be a comment! e.g. roles/vnstat/install.yml" + debug: + msg: "Left side # Right side" - name: a shows "VARIABLE IS NOT DEFINED!" -- whereas b (w/o whitespace) AND c (with space) AND d (with tab, STRICTLY DISALLOWED IN YAML BY ansible-core 2.11.6) showed null (without quotes!) -- whereas e (singlequotes) and f (doublequotes) show "" empty string set_fact: From 423eecc29363a07dce8310d1396a614350212031 Mon Sep 17 00:00:00 2001 From: A Holt Date: Mon, 1 May 2023 11:41:04 -0400 Subject: [PATCH 2/2] CLARIF: Let's use apt version of /etc/vnstat.conf (not 2011-era template) --- roles/vnstat/tasks/install.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/vnstat/tasks/install.yml b/roles/vnstat/tasks/install.yml index f1d65ada9..70e4f56cc 100644 --- a/roles/vnstat/tasks/install.yml +++ b/roles/vnstat/tasks/install.yml @@ -10,7 +10,7 @@ iiab_wan_iface: "{{ ansible_default_ipv4.alias }}" when: ansible_default_ipv4.gateway is defined -# 2023-05-01: Probably no longer nec, as line 'Interface ""' in /etc/vnstat.conf automatically selects the default interface +# 2023-05-01: Probably no longer nec, as line 'Interface ""' in /etc/vnstat.conf (as installed by apt) automatically selects the default interface - name: Insert 'Interface "{{ iiab_wan_iface }}"' into /etc/vnstat.conf lineinfile: path: /etc/vnstat.conf