tripleo-ansible/tripleo_ansible/roles/tripleo_cephadm/tasks/pre.yaml

114 lines
3.7 KiB
YAML

---
# Copyright 2021 Red Hat, Inc.
# All Rights Reserved.
#
# 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: Install cephadm package
become: true
package:
name: cephadm
state: latest
when:
- tripleo_cephadm_predeployed | bool
- name: Stat cephadm file
stat:
path: "{{ tripleo_cephadm_bin }}"
register: stat_cephadm
become: true
ignore_errors: true
- name: Fail if cephadm is not available
fail:
msg: "{{ tripleo_cephadm_bin }} does not exist"
when: not stat_cephadm.stat.exists
- name: List Ceph daemon instances on this host
shell: "{{ tripleo_cephadm_bin }} ls --no-detail"
register: cephadm_ls
become: true
- name: Ensure tripleo_cephadm_fsid variable is set if none was provided
block:
- name: Set list of found FSIDs
set_fact:
tripleo_cephadm_fsid_list: "{{ cephadm_ls.stdout | from_json | map(attribute='fsid') | sort | unique }}"
when:
- cephadm_ls.stdout is defined
- cephadm_ls.stdout != '[]'
- name: Fail if >1 FSID was discovered
fail:
msg: |
Multiple FSIDs were found. This Ansible role does not
support management of multiple Ceph clusters on one host.
when: tripleo_cephadm_fsid_list | length > 1
- name: Set FSID to the discovered value
set_fact:
tripleo_cephadm_fsid: "{{ tripleo_cephadm_fsid_list[0] }}"
when: tripleo_cephadm_fsid_list | length == 1
- name: Set random tripleo_cephadm_fsid if no running ceph containers were found
set_fact:
tripleo_cephadm_fsid: "{{ 99999999 | random | to_uuid | lower }}"
when: tripleo_cephadm_fsid_list | length == 0
when: tripleo_cephadm_fsid is not defined or (tripleo_cephadm_fsid is defined and tripleo_cephadm_fsid | length == 0)
- name: Set first monitor IP if it was not passed
set_fact:
tripleo_cephadm_first_mon_ip: "{{ ansible_host }}"
when: tripleo_cephadm_first_mon_ip is not defined or (tripleo_cephadm_first_mon_ip is defined and tripleo_cephadm_first_mon_ip | length == 0)
- name: Ensure tripleo_cephadm_config_home (e.g. /etc/ceph) exists
file:
path: "{{ tripleo_cephadm_config_home }}"
state: directory
become: true
- name: Ensure specs directory exists
file:
path: "/home/{{ tripleo_cephadm_ssh_user }}/specs"
owner: "{{ tripleo_cephadm_ssh_user }}"
group: "{{ tripleo_cephadm_ssh_user }}"
mode: '0755'
state: directory
become: true
- name: Stat spec file on ansible host
stat:
path: "{{ tripleo_cephadm_spec_ansible_host }}"
register: tripleo_cephadm_spec_stat_host
delegate_to: localhost
become: true
- name: push tripleo_cephadm_spec to bootstrap node if spec file exsits
copy:
src: "{{ tripleo_cephadm_spec_ansible_host }}"
dest: "{{ tripleo_cephadm_spec }}"
owner: "{{ tripleo_cephadm_ssh_user }}"
group: "{{ tripleo_cephadm_ssh_user }}"
mode: '0644'
become: true
when: tripleo_cephadm_spec_stat_host.stat.exists
- name: generate pre ceph.conf configuration file for initial bootstrap
action: config_template
args:
src: "ceph.conf.j2"
dest: "{{ tripleo_cephadm_bootstrap_conf }}"
owner: "{{ tripleo_cephadm_uid }}"
group: "{{ tripleo_cephadm_uid }}"
mode: "0644"
config_overrides: "{{ tripleo_cephadm_conf_overrides }}"
config_type: ini
become: true