/home/zuul/src/opendev.org/openstack/openstack-ansible-os_ceilometer/tasks/ceilometer_pre_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: Create the system group
  group:
    name: "{{ ceilometer_system_group_name }}"
    state: "present"
    system: "yes"

- name: Create the ceilometer system user
  user:
    name: "{{ ceilometer_system_user_name }}"
    group: "{{ ceilometer_system_group_name }}"
    comment: "{{ ceilometer_system_comment }}"
    shell: "{{ ceilometer_system_shell }}"
    system: "yes"
    createhome: "yes"
    home: "{{ ceilometer_system_user_home }}"

- name: Create the swift system user and add to ceilometer group
  user:
    name: "{{ swift_system_user_name }}"
    group: "{{ ceilometer_system_group_name }}"
    comment: "{{ swift_system_comment }}"
    shell: "{{ swift_system_shell }}"
    system: "yes"
    createhome: "yes"
    home: "{{ swift_system_home_folder }}"
  when: swift_ceilometer_enabled | bool


# NOTE(cloudnull): During an upgrade the local directory may exist on a source
#                  install. If the directory does exist it will need to be
#                  removed. This is required on source installs because the
#                  config directory is a link.
- name: Source config block
  block:
    - name: Stat config directory
      stat:
        path: "/etc/ceilometer"
      register: ceilometer_conf_dir_stat

    - name: Remove the config directory
      file:
        path: "/etc/cinder"
        state: absent
      when:
        - ceilometer_conf_dir_stat.stat.isdir is defined and
          ceilometer_conf_dir_stat.stat.isdir
  when:
    - ceilometer_install_method == 'source'

- name: Create ceilometer dir
  file:
    path: "{{ item.path | default(omit) }}"
    src: "{{ item.src | default(omit) }}"
    dest: "{{ item.dest | default(omit) }}"
    state: "{{ item.state | default('directory') }}"
    owner: "{{ item.owner|default(ceilometer_system_user_name) }}"
    group: "{{ item.group|default(ceilometer_system_group_name) }}"
    mode: "{{ item.mode | default(omit) }}"
    force: "{{ item.force | default(omit) }}"
  when:
    - (item.condition | default(true)) | bool
  with_items:
    - path: "/openstack"
      owner: "root"
      group: "root"
      mode: "0755"
    - path: "/var/cache/ceilometer"
      mode: "0700"
    - path: "{{ (ceilometer_install_method == 'distro') | ternary('/etc/ceilometer', (ceilometer_bin | dirname) + '/etc/ceilometer') }}"
      mode: "0755"
    - path: "/etc/ceilometer"
      src: "{{ ceilometer_bin | dirname | regex_replace('^/', '../') }}/etc/ceilometer"
      state: link
      force: true
      condition: "{{ ceilometer_install_method == 'source' }}"
    - path: "/etc/ceilometer/rootwrap.d"
      owner: "root"
      group: "root"
    - path: "{{ ceilometer_system_user_home }}"
    - path: "{{ ceilometer_system_user_home }}/.ssh"
      mode: "0700"