- name: Install Wondershaper systemd unit file from template
  template:
    backup: yes
    src: roles/network/templates/wondershaper/wondershaper.service
    dest: /etc/systemd/system/wondershaper.service
    # mode: '0644'

- name: Install /usr/bin/wondershaper from template
  template:
    backup: yes
    src: roles/network/templates/wondershaper/wondershaper.j2
    dest: /usr/bin/wondershaper
    # owner: root
    # group: root
    mode: '0744'

- name: Create conf.d directory
  file:
    path: /etc/conf.d
    # owner: root
    # group: root
    # mode: '0755'
    state: directory

- name: Install /etc/conf.d/wondershaper.conf from template
  template:
    src: roles/network/templates/wondershaper/wondershaper.conf
    dest: /etc/conf.d/wondershaper.conf
    # owner: root
    # group: root
    mode: '0600'

- name: Create fact (symlink) /etc/ansible/facts.d/wondershaper.fact -> /etc/conf.d/wondershaper.conf
  file:
    src: /etc/conf.d/wondershaper.conf
    dest: /etc/ansible/facts.d/wondershaper.fact
    # owner: root
    # group: root
    state: link


# RECORD Wondershaper AS INSTALLED

- name: "Set 'wondershaper_installed: True'"
  set_fact:
    wondershaper_installed: True

- name: "Add 'wondershaper_installed: True' to {{ iiab_state_file }}"
  lineinfile:
    path: "{{ iiab_state_file }}"    # /etc/iiab/iiab_state.yml
    regexp: '^wondershaper_installed'
    line: 'wondershaper_installed: True'


- name: Add 'wondershaper' variable values to {{ iiab_ini_file }}
  ini_file:
    dest: "{{ iiab_ini_file }}"
    section: wondershaper
    option: "{{ item.option }}"
    value: "{{ item.value | string }}"
  with_items:
    - option: name
      value: wondershaper
    - option: description
      value: '"Wondershaper is a command line tool to set maximum transfer rates for network adapters."'
    - option: wondershaper_install
      value: "{{ wondershaper_install }}"
    - option: wondershaper_enabled
      value: "{{ wondershaper_enabled }}"