--- # 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: Add spec to necessary file list when using spec to bootstrap ansible.builtin.set_fact: cifmw_cephadm_bootstrap_files: "{{ cifmw_cephadm_bootstrap_files + [ cifmw_cephadm_spec ] }}" when: cifmw_cephadm_spec_on_bootstrap | bool - name: Stat necessary files to bootstrap with cephadm ansible.builtin.stat: path: "{{ item }}" register: cifmw_cephadm_bootstrap_files_stat become: true loop: "{{ cifmw_cephadm_bootstrap_files }}" - name: Fail if necessary files are missing ansible.builtin.fail: msg: "{{ item.invocation.module_args.path }} does not exist" loop: "{{ cifmw_cephadm_bootstrap_files_stat.results | list }}" when: not item.stat.exists - name: Stat pre ceph conf file in case we should bootrap with it ansible.builtin.stat: path: "{{ cifmw_cephadm_assimilate_conf }}" register: cifmw_cephadm_assimilate_conf_stat become: true # cephadm_ls should be registered by pre.yml - name: Bootstrap Ceph if there are no running Ceph Daemons when: - cephadm_ls is defined - cephadm_ls.stdout == '[]' tags: - cephadm_bootstrap vars: cephadm_registry_file: "/tmp/cephadm_registry.json" block: - name: Prepare the registry credential file when: cephadm_container_registry_url|length > 0 vars: cephadm_container_registry_url: "{{ cifmw_cephadm_registry_url|default(cifmw_registry_token_registry_url|default(''), True) }}" cephadm_container_registry_username: "{{ cifmw_cephadm_registry_username|default(cifmw_registry_token.credentials.username|default(''), True) }}" cephadm_container_registry_password: "{{ cifmw_cephadm_registry_password|default(cifmw_registry_token.credentials.password|default(''), True) }}" ansible.builtin.template: src: templates/cephadm_registry_file.json.j2 dest: "{{ cephadm_registry_file }}" mode: '0644' force: true - name: Find out if the container registry configuration file exists ansible.builtin.stat: path: "{{ cephadm_registry_file }}" register: cephadm_container_registry_config_check - name: Run cephadm bootstrap become: true register: cephadm_bootstrap ansible.builtin.shell: | {{ cifmw_cephadm_bin }} \ {% if not cifmw_cephadm_default_container %}--image {{ cifmw_cephadm_container_ns + '/' + cifmw_cephadm_container_image + ':' + cifmw_cephadm_container_tag|string }} \{% endif %} bootstrap \ --skip-firewalld \ {% if not cifmw_cephadm_prepare_host %} --skip-prepare-host \ {% endif %} --ssh-private-key /home/{{ cifmw_cephadm_ssh_user }}/.ssh/id_rsa \ --ssh-public-key /home/{{ cifmw_cephadm_ssh_user }}/.ssh/id_rsa.pub \ --ssh-user {{ cifmw_cephadm_ssh_user }} \ --allow-fqdn-hostname \ --output-keyring {{ cifmw_cephadm_admin_keyring }} \ --output-config {{ cifmw_cephadm_conf }} \ --fsid {{ cifmw_cephadm_fsid }} \ {% if cephadm_container_registry_config_check.stat.exists %}--registry-json {{ cephadm_registry_file }} \{% endif %} {% if cifmw_cephadm_spec_on_bootstrap %}--apply-spec {{ cifmw_cephadm_spec }} \{% endif %} {% if cifmw_cephadm_assimilate_conf_stat.stat.exists %}--config {{ cifmw_cephadm_assimilate_conf }} \{% endif %} {% if cifmw_cephadm_single_host_defaults %}--single-host-defaults \{% endif %} --skip-monitoring-stack --skip-dashboard \ {% if cifmw_cephadm_extra_args|length > 0 %}{{ cifmw_cephadm_extra_args }} \{% endif %} --mon-ip {{ cifmw_cephadm_first_mon_ip }} - name: Show results of bootstrap when: cifmw_cephadm_verbose | bool ansible.builtin.debug: msg: "{{ cephadm_bootstrap }}" - name: Remove the container registry credentials file which is not needed anymore when: cephadm_container_registry_config_check.stat.exists ansible.builtin.file: path: "{{ cephadm_registry_file }}" state: absent - name: Ensure cifmw_cephadm_ceph_cli is set when: - cifmw_cephadm_ceph_cli is not defined ansible.builtin.include_tasks: ceph_cli.yml - name: Ensure cephadm uses image tags instead of digests become: true ansible.builtin.command: | {{ cifmw_cephadm_ceph_cli }} config set mgr mgr/cephadm/use_repo_digest false changed_when: false - name: Set the default container image in ceph configuration become: true when: - not (cifmw_cephadm_default_container | default(false) | bool) ansible.builtin.command: | {{ cifmw_cephadm_ceph_cli }} config set global container_image \ {{ cifmw_cephadm_container_ns + '/' + cifmw_cephadm_container_image + ':' + cifmw_cephadm_container_tag|string }} changed_when: false - name: If cephadm bootstrap was not run report the reason when: - cephadm_ls is defined - cephadm_ls.stdout != '[]' ansible.builtin.debug: msg: | 'cephadm bootstrap' was not run because 'cephadm ls' indicates that Ceph containers are already running.