---
- name: Dependencies installed
  community.general.pkgng:
    name: gtar,py39-pillow,py39-pip,py39-configobj,py39-cheetah3,py39-ephem,py39-sqlite3
    state: latest

- name: Nginx conf file installed
  copy:
    src: nginx.conf
    dest: /usr/local/etc/nginx/locations/weewx.conf
    mode: 0644
  notify: Nginx restarted

- name: Python binary linked
  file: src=/usr/local/bin/python3.9 dest=/usr/local/bin/python state=link

- name: WeeWX src folder exists
  file:
    path: /usr/local/src/weewx
    owner: root
    mode: 0755
    state: directory

- name: WeeWX var folder exists
  file:
    path: /var/weewx
    owner: root
    mode: 0755
    state: directory

- name: WeeWX source unpacked
  unarchive:
    src: http://weewx.com/downloads/weewx-4.10.2.tar.gz
    dest: /usr/local/src/weewx
    remote_src: yes

- name: WeeWX GW1000 driver fetched
  get_url:
    url: https://github.com/gjr80/weewx-gw1000/releases/download/v0.5.0b5/gw1000-0.5.0b5.tar.gz
    dest: /usr/local/src/weewx/gw1000-0.5.0b5.tar.gz

- name: WeeWX GW1000 driver installed
  shell:
    chdir: /usr/local/src/weewx/weewx-4.10.2/bin
    cmd: python3.9 wee_extension --install=/usr/local/src/weewx/gw1000-0.5.0b5.tar.gz

- name: WeeWX built
  shell: python3.9 ./setup.py build
  args:
    chdir: /usr/local/src/weewx/weewx-4.10.2

- name: WeeWX skin files copied
  ansible.builtin.copy:
    src: /usr/local/src/weewx/weewx-4.10.2/skins
    dest: /var/weewx/
    remote_src: yes

- name: WeeWX config file installed
  ansible.builtin.copy:
    src: weewx.conf
    dest: /usr/local/etc/weewx.conf
    owner: root
    mode: 0644
  notify: WeeWX restarted

- name: WeeWX historygenerator installed
  ansible.builtin.copy:
    src: historygenerator.py
    dest: /usr/local/src/weewx/weewx-4.10.2/bin/user/

- name: WeeWX rc file installed
  ansible.builtin.copy:
    src: weewx.rc
    dest: /usr/local/etc/rc.d/weewx
    owner: root
    mode: a+x
  notify: WeeWX restarted

- name: WeeWX skin files copied
  ansible.builtin.copy:
    src: /usr/local/src/weewx/weewx-4.10.2/skins
    dest: /var/weewx/
    remote_src: yes

- name: WeeWX Sofaskin-CW9009 skin file emplaced
  ansible.builtin.copy:
    src: Sofaskin-CW9009-1.4.91.zip
    dest: /var/weewx/skins/sofaskin-cw9009-latest.zip
    owner: root

- name: WeeWX Sofaskin-CW9009 unpacked
  command: "unzip -o sofaskin-cw9009-latest.zip"
  args:
    chdir: /var/weewx/skins

- name: WeeWX first report generated
  shell:
    chdir: /usr/local/src/weewx/weewx-4.10.2/bin
    cmd: python3.9 wee_reports

- name: WeeWX started
  service:
    name: weewx
    state: started
