#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

- name: "download influxdb rpm"
  get_url:
  args:
    url: "{{ influxdb_rpm_url }}"
    dest: /tmp/influxdb.rpm
    checksum: "{{ influxdb_checksum }}"
    force: no
- name: "Import GPG key for CentOS 8.0 and later"
  become: true
  rpm_key:
    key: https://repos.influxdata.com/influxdb.key
    state: present
  when: ansible_facts['distribution_version'] is version('8.0', '>=')
- name: "ensure influxdb is installed"
  yum: name=/tmp/influxdb.rpm state=present
- name: "configure influxdb"
  template: src=influxdb-1.8.3.conf dest=/etc/influxdb/influxdb.conf
  notify:
    - restart influxdb
    - setup influxdb
- name: "download fluo setup"
  get_url: url=https://raw.githubusercontent.com/apache/fluo/main/contrib/influxdb/fluo_metrics_setup.txt dest=/etc/influxdb/fluo_metrics_setup.txt
- name: "create data dir"
  file: path={{ default_data_dirs[0] }}/influxdb state=directory owner=influxdb group=influxdb
- name: "ensure influxdb is running (and enable it at boot)"
  service: name=influxdb state=started enabled=yes
  notify:
    - setup influxdb
