- 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
    # owner: root
    # group: root
    mode: '0744'

- 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

- 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'
