/home/zuul/src/opendev.org/openstack/openstack-ansible-os_gnocchi/tasks/main.yml
---
# Copyright 2015, Rackspace US, Inc.
#
# Licensed 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: Gather variables for each operating system
  include_vars: "{{ item }}"
  with_first_found:
    - "{{ ansible_distribution | lower }}-{{ ansible_distribution_version | lower }}.yml"
    - "{{ ansible_distribution | lower }}-{{ ansible_distribution_major_version | lower }}.yml"
    - "{{ ansible_os_family | lower }}-{{ ansible_distribution_major_version | lower }}.yml"
    - "{{ ansible_distribution | lower }}.yml"
    - "{{ ansible_os_family | lower }}-{{ ansible_distribution_version.split('.')[0] }}.yml"
    - "{{ ansible_os_family | lower }}.yml"
  tags:
    - always

- import_tasks: db_setup.yml
  when:
    - inventory_hostname == groups['gnocchi_all'][0]
  vars:
    _oslodb_setup_host: "{{ gnocchi_db_setup_host }}"
    _oslodb_databases:
      - name: "{{ gnocchi_galera_database }}"
        users:
          - username: "{{ gnocchi_galera_user }}"
            password: "{{ gnocchi_container_mysql_password }}"
  tags:
    - common-db
    - gnocchi-config

- import_tasks: gnocchi_pre_install.yml
  tags:
    - gnocchi-install

- name: Install the python venv
  import_role:
    name: "python_venv_build"
  vars:
    venv_python_executable: "{{ gnocchi_venv_python_executable }}"
    venv_build_constraints: "{{ gnocchi_git_constraints }}"
    venv_install_destination_path: "{{ gnocchi_bin | dirname }}"
    venv_install_distro_package_list: "{{ gnocchi_distro_packages }}"
    venv_pip_install_args: "{{ gnocchi_pip_install_args }}"
    venv_pip_packages: "{{ gnocchi_pip_packages }}"
    venv_facts_when_changed:
      - section: "gnocchi"
        option: "venv_tag"
        value: "{{ gnocchi_venv_tag }}"
  tags:
    - gnocchi-install

- import_tasks: gnocchi_post_install.yml
  when: not gnocchi_identity_only | bool
  tags:
    - gnocchi-config

- name: Run the systemd service role
  import_role:
    name: systemd_service
  vars:
    systemd_user_name: "{{ gnocchi_system_user_name }}"
    systemd_group_name: "{{ gnocchi_system_group_name }}"
    systemd_tempd_prefix: openstack
    systemd_slice_name: gnocchi
    systemd_lock_path: /var/lock/gnocchi
    systemd_CPUAccounting: true
    systemd_BlockIOAccounting: true
    systemd_MemoryAccounting: true
    systemd_TasksAccounting: true
    systemd_services: "{{ filtered_gnocchi_services }}"
  when: not gnocchi_identity_only | bool
  tags:
    - gnocchi-config
    - systemd-service

- name: Import uwsgi role
  import_role:
    name: uwsgi
  vars:
    uwsgi_services: "{{ uwsgi_gnocchi_services }}"
    uwsgi_install_method: "source"
  tags:
    - gnocchi-config
    - uwsgi

- import_tasks: service_setup.yml
  vars:
    _service_adminuri_insecure: "{{ keystone_service_adminuri_insecure }}"
    _service_setup_host: "{{ gnocchi_service_setup_host }}"
    _service_setup_host_python_interpreter: "{{ gnocchi_service_setup_host_python_interpreter }}"
    _service_region: "{{ gnocchi_service_region }}"
    _service_endpoints:
      - service: "{{ gnocchi_service_name }}"
        interface: "public"
        url: "{{ gnocchi_service_publicurl }}"
      - service: "{{ gnocchi_service_name }}"
        interface: "internal"
        url: "{{ gnocchi_service_internalurl }}"
      - service: "{{ gnocchi_service_name }}"
        interface: "admin"
        url: "{{ gnocchi_service_adminurl }}"
    _service_catalog:
      - name: "{{ gnocchi_service_name }}"
        type: "{{ gnocchi_service_type }}"
        description: "{{ gnocchi_service_description }}"
  when:
    - inventory_hostname == groups['gnocchi_all'][0]
    - not gnocchi_identity_only | bool
  tags:
    - gnocchi-config

- import_tasks: gnocchi_identity_setup.yml
  when: inventory_hostname == groups['gnocchi_all'][0]
  tags:
    - gnocchi-config

- import_tasks: gnocchi_ceph_python_libs.yml
  when:
    - gnocchi_storage_driver == 'ceph'
  tags:
    - gnocchi-install

# N.B. Must occur after identity setup, as this may perform calls to Swift.
#      Similarly, when using Ceph, must occur after Ceph setup.
- import_tasks: gnocchi_db_sync.yml
  when:
    - inventory_hostname == groups['gnocchi_all'][0]
    - not gnocchi_identity_only | bool
  tags:
    - gnocchi-config