/home/zuul/src/opendev.org/openstack/openstack-ansible-os_ceilometer/tasks/ceilometer_install.yml
---
# Copyright 2014, 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: Record the installation method
  ini_file:
    dest: "/etc/ansible/facts.d/openstack_ansible.fact"
    section: "ceilometer"
    option: "install_method"
    value: "{{ ceilometer_install_method }}"

- name: Refresh local facts to ensure the ceilometer section is present
  setup:
    filter: ansible_local
    gather_subset: "!all"

- name: Install distro packages
  package:
    name: "{{ ceilometer_package_list }}"
    state: "{{ ceilometer_package_state }}"
    update_cache: "{{ (ansible_pkg_mgr in ['apt', 'zypper']) | ternary('yes', omit) }}"
    cache_valid_time: "{{ (ansible_pkg_mgr == 'apt') | ternary(cache_timeout, omit) }}"
  register: install_packages
  until: install_packages is success
  retries: 5
  delay: 2

- name: Install the python venv
  include_role:
    name: "python_venv_build"
  vars:
    venv_python_executable: "{{ ceilometer_venv_python_executable }}"
    venv_build_constraints: "{{ ceilometer_git_constraints }}"
    venv_build_distro_package_list: "{{ ceilometer_devel_distro_packages }}"
    venv_install_destination_path: "{{ ceilometer_bin | dirname }}"
    venv_install_distro_package_list: "{{ ceilometer_distro_packages }}"
    venv_pip_install_args: "{{ ceilometer_pip_install_args }}"
    venv_pip_packages: "{{ (ceilometer_oslomsg_amqp1_enabled | bool) | ternary(ceilometer_pip_packages + ceilometer_optional_oslomsg_amqp1_pip_packages, ceilometer_pip_packages) }}"
    venv_packages_to_symlink: "{{ ceilometer_packages_to_symlink }}"
    venv_facts_when_changed:
      - section: "ceilometer"
        option: "venv_tag"
        value: "{{ ceilometer_venv_tag }}"
  when: ceilometer_install_method == 'source'

- name: Find the venv's python version
  find:
    paths: "{{ ceilometer_bin | dirname }}/lib/"
    patterns: "python*"
    file_type: directory
    recurse: no
  register: _ceilometer_python_venv_details
  when: ceilometer_install_method == 'source'

- name: Set python lib dir fact
  set_fact:
    ceilometer_lib_dir: "{{ _ceilometer_python_venv_details.files[0].path }}/site-packages"
  when: ceilometer_install_method == 'source'