- name: Install sugar-stats required packages
  package: name={{ item }}
           state=present
  with_items:
    - sugar-stats-server
    - active-document
    - restful-document
    - python-xappy

- name: Create sugar-stats directory tree
  file: path={{ item }}
        owner=sugar-stats
        group=sugar-stats
        mode=0755
        state=directory
  with_items:
    - /library/sugar-stats/
    - /library/sugar-stats/rrd
    - /library/sugar-stats/users

- name: Copy sugar-stats config file
  template: backup=yes
            src=sugar-stats.conf.j2
            dest=/etc/sugar-stats.conf
            owner=sugar-stats
            group=sugar-stats
            mode=0644

- name: Enable sugar-stats service
  service: name=sugar-stats-server
           enabled=yes
  when: sugar_stats_enabled

- name: Disable sugar-stats service
  service: name=sugar-stats-server
           enabled=no
  when: not sugar_stats_enabled

- include_tasks: statistics-consolidation.yml

- name: Add 'sugar-stats' variable values to {{ iiab_ini_file }}
  ini_file:
    path: "{{ iiab_ini_file }}"
    section: sugar_stats
    option: "{{ item.option }}"
    value: "{{ item.value | string }}"
  with_items:
    - option: name
      value: sugar_stats
    - option: description
      value: '"Collect Sugar statistics, originally written by Alexy Lim, see: http://wiki.sugarlabs.org/go/Platform_Team/Usage_Statistics"'
    - option: installed
      value: "{{ sugar_stats_install }}"
    - option: enabled
      value: "{{ sugar_stats_enabled }}"
