- name: Create influxdb group
  group:
    name: influxdb
    system: yes

- name: Create influxdb user
  user:
    name: influxdb
    system: yes
    home: /var/lib/influxdb
    shell: /sbin/nologin

- name: Install tar
  package:
    name: tar

- name: Install influxdb
  unarchive:
    src: https://download.influxdata.com/influxdb/releases/influxdb2-{{ influxdb_version }}_linux_amd64.tar.gz
    dest: /
    remote_src: yes
    extra_opts:
      - '--strip-components=1'
  notify: restart influxdb

- name: Install influxdb initscript
  copy:
    dest: /etc/init.d/influxdb
    src: influxdb.initd
    mode: 0755
  notify: restart influxdb

- name: Configure influxdb
  copy:
    dest: /var/lib/influxdb/
    src: config.toml

- name: Set up nginx site
  template:
    dest: '/etc/nginx/http.d/influxdb.conf'
    src: 'nginx.conf.j2'
  notify: reload nginx

- name: Enable influxdb
  service:
    name: influxdb
    enabled: yes
    state: started