From 935963994086560fee021d283f6e4f7e2646522e Mon Sep 17 00:00:00 2001 From: Francesco Pantano Date: Wed, 14 Oct 2020 10:57:04 +0200 Subject: [PATCH] Introducing TripleO ceph client role The tripleo_ceph_client role is supposed to replace the ceph-ansible client and work for both cephadm and ceph-ansible based deployments. The purpose of this role is to work with both internal and external ceph, processing the input provided, generating the Ceph clients (Nova, Cinder, Glance, Manila) configuration (keys and ceph.conf) and push the generated files to the 'clients' group provided by the TripleO inventory. Implements: blueprint tripleo-ceph-client Change-Id: Ia60bc6d5d1a04bd560f2fcb05a4b64078015ae9d --- doc/source/roles/role-tripleo_ceph_client.rst | 6 ++ .../tripleo_ceph_client/defaults/main.yml | 34 +++++++ .../roles/tripleo_ceph_client/meta/main.yml | 42 ++++++++ .../molecule/default/Dockerfile | 36 +++++++ .../molecule/default/converge.yml | 82 ++++++++++++++++ .../molecule/default/molecule.yml | 50 ++++++++++ .../molecule/default/prepare.yml | 27 ++++++ .../tasks/ceph_ansible.yml | 38 ++++++++ .../tasks/create_ceph_conf.yml | 25 +++++ .../tripleo_ceph_client/tasks/create_keys.yml | 26 +++++ .../tripleo_ceph_client/tasks/fetch_dir.yml | 33 +++++++ .../roles/tripleo_ceph_client/tasks/main.yml | 95 +++++++++++++++++++ .../roles/tripleo_ceph_client/tasks/sync.yml | 32 +++++++ .../templates/ceph_conf.j2 | 42 ++++++++ .../tripleo_ceph_client/templates/ceph_key.j2 | 5 + zuul.d/molecule.yaml | 11 +++ 16 files changed, 584 insertions(+) create mode 100644 doc/source/roles/role-tripleo_ceph_client.rst create mode 100644 tripleo_ansible/roles/tripleo_ceph_client/defaults/main.yml create mode 100644 tripleo_ansible/roles/tripleo_ceph_client/meta/main.yml create mode 100644 tripleo_ansible/roles/tripleo_ceph_client/molecule/default/Dockerfile create mode 100644 tripleo_ansible/roles/tripleo_ceph_client/molecule/default/converge.yml create mode 100644 tripleo_ansible/roles/tripleo_ceph_client/molecule/default/molecule.yml create mode 100644 tripleo_ansible/roles/tripleo_ceph_client/molecule/default/prepare.yml create mode 100644 tripleo_ansible/roles/tripleo_ceph_client/tasks/ceph_ansible.yml create mode 100644 tripleo_ansible/roles/tripleo_ceph_client/tasks/create_ceph_conf.yml create mode 100644 tripleo_ansible/roles/tripleo_ceph_client/tasks/create_keys.yml create mode 100644 tripleo_ansible/roles/tripleo_ceph_client/tasks/fetch_dir.yml create mode 100644 tripleo_ansible/roles/tripleo_ceph_client/tasks/main.yml create mode 100644 tripleo_ansible/roles/tripleo_ceph_client/tasks/sync.yml create mode 100644 tripleo_ansible/roles/tripleo_ceph_client/templates/ceph_conf.j2 create mode 100644 tripleo_ansible/roles/tripleo_ceph_client/templates/ceph_key.j2 diff --git a/doc/source/roles/role-tripleo_ceph_client.rst b/doc/source/roles/role-tripleo_ceph_client.rst new file mode 100644 index 000000000..7d2eceb07 --- /dev/null +++ b/doc/source/roles/role-tripleo_ceph_client.rst @@ -0,0 +1,6 @@ +========================== +Role - tripleo_ceph_client +========================== + +.. ansibleautoplugin:: + :role: tripleo_ansible/roles/tripleo_ceph_client diff --git a/tripleo_ansible/roles/tripleo_ceph_client/defaults/main.yml b/tripleo_ansible/roles/tripleo_ceph_client/defaults/main.yml new file mode 100644 index 000000000..4682fc62b --- /dev/null +++ b/tripleo_ansible/roles/tripleo_ceph_client/defaults/main.yml @@ -0,0 +1,34 @@ +--- +# Copyright 2020 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. + + +# All variables intended for modification should be placed in this file. + +# All variables within this role should have a prefix of "tripleo_ceph_client" +tripleo_ceph_client_debug: "{{ (ansible_verbosity | int) >= 2 | bool }}" +tripleo_ceph_client_hide_sensitive_logs: true +tripleo_ceph_client_config_home: "/etc/ceph" +tripleo_ceph_client_fetch_dir: "{{ playbook_dir }}/ceph_client_fetch_dir" +tripleo_ceph_client_vars: "/home/stack/ceph_client.yaml" +tripleo_ceph_client_cluster: "ceph" +tripleo_ceph_client_fsid: '' +tripleo_ceph_client_mon_ips: [] +tripleo_ceph_client_keys: [] +tripleo_ceph_client_config_overrides: {} +tripleo_ceph_client_rbd_admin_socket_path: '/var/run/ceph' +tripleo_ceph_client_rbd_log_path: '/var/log/ceph' +tripleo_ceph_client_rbd_log_file: "{{ tripleo_ceph_client_rbd_log_path }}/qemu-guest-$pid.log" +external_cluster_mon_ips: '' diff --git a/tripleo_ansible/roles/tripleo_ceph_client/meta/main.yml b/tripleo_ansible/roles/tripleo_ceph_client/meta/main.yml new file mode 100644 index 000000000..f10411350 --- /dev/null +++ b/tripleo_ansible/roles/tripleo_ceph_client/meta/main.yml @@ -0,0 +1,42 @@ +--- +# Copyright 2020 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. + + +galaxy_info: + author: OpenStack + description: TripleO OpenStack Role -- tripleo_ceph_client + company: Red Hat + license: Apache-2.0 + min_ansible_version: 2.7 + # + # Provide a list of supported platforms, and for each platform a list of versions. + # If you don't wish to enumerate all versions for a particular platform, use 'all'. + # To view available platforms and versions (or releases), visit: + # https://galaxy.ansible.com/api/v1/platforms/ + # + platforms: + - name: CentOS + versions: + - 7 + - 8 + + galaxy_tags: + - tripleo + + +# List your role dependencies here, one per line. Be sure to remove the '[]' above, +# if you add dependencies to this list. +dependencies: [] diff --git a/tripleo_ansible/roles/tripleo_ceph_client/molecule/default/Dockerfile b/tripleo_ansible/roles/tripleo_ceph_client/molecule/default/Dockerfile new file mode 100644 index 000000000..30e9e7534 --- /dev/null +++ b/tripleo_ansible/roles/tripleo_ceph_client/molecule/default/Dockerfile @@ -0,0 +1,36 @@ +# Molecule managed +# Copyright 2020 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. + + +{% if item.registry is defined %} +FROM {{ item.registry.url }}/{{ item.image }} +{% else %} +FROM {{ item.image }} +{% endif %} + +RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y python sudo bash ca-certificates && apt-get clean; \ + elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install sudo python*-devel python*-dnf bash {{ item.pkg_extras | default('') }} && dnf clean all; \ + elif [ $(command -v yum) ]; then yum makecache fast && yum install -y python sudo yum-plugin-ovl python-setuptools bash {{ item.pkg_extras | default('') }} && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \ + elif [ $(command -v zypper) ]; then zypper refresh && zypper install -y python sudo bash python-xml {{ item.pkg_extras | default('') }} && zypper clean -a; \ + elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates {{ item.pkg_extras | default('') }}; \ + elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python sudo bash ca-certificates {{ item.pkg_extras | default('') }} && xbps-remove -O; fi + +{% for pkg in item.easy_install | default([]) %} +# install pip for centos where there is no python-pip rpm in default repos +RUN easy_install {{ pkg }} +{% endfor %} + +CMD ["sh", "-c", "while true; do sleep 10000; done"] diff --git a/tripleo_ansible/roles/tripleo_ceph_client/molecule/default/converge.yml b/tripleo_ansible/roles/tripleo_ceph_client/molecule/default/converge.yml new file mode 100644 index 000000000..312c596a3 --- /dev/null +++ b/tripleo_ansible/roles/tripleo_ceph_client/molecule/default/converge.yml @@ -0,0 +1,82 @@ +--- +# Copyright 2020 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: Converge + hosts: all + roles: + - role: "tripleo_ceph_client" + tripleo_ceph_client_config_home: "/etc/ceph" + tripleo_ceph_client_fsid: "1dee28aa-2eba-11eb-b30b-244200b898e6" + tripleo_ceph_client_mon_ips: + - 172.16.3.10 + - 172.16.3.11 + - 172.16.3.12 + tripleo_ceph_client_keys: + - caps: + mgr: allow * + mon: profile rbd + osd: profile rbd pool=vms, profile rbd pool=volumes, profile rbd pool=metrics, + profile rbd pool=backups, profile rbd pool=pool2, profile rbd pool=pool3, + profile rbd pool=altrbd + key: AQC+vYNXgDAgAhAAc8UoYt+OTz5uhV7ItLdwUw== + mode: '0600' + name: client.glance + - caps: + mgr: allow * + mon: profile rbd + osd: profile rbd pool=images + key: AQBRgQ9eAAAAABAAv84zEilJYZPNuJ0Iwn9Ndg== + mode: '0600' + name: client.manila + tripleo_ceph_client_config_overrides: + global: + osd_pool_default_pg_num: 16 + osd_pool_default_pgp_num: 16 + osd_pool_default_size: 1 + topkey: 'topvalue' + client: + rbd_cache: true + rbd_cache_writethrough_until_flush: true + rbd_concurrent_management_ops: 20 + osdkey: 'osdvalue' + + tasks: + - name: Check the tripleo_ceph_client_fetch_dir content + block: + - name: Check current file + stat: + path: "{{ tripleo_ceph_client_fetch_dir }}/{{ item }}" + register: st + loop: "{{ expected_files }}" + - fail: + msg: "The file {{ item }} doesn't exist" + when: not item.stat.exists + loop: "{{ st.results }}" + - name: Show the content of the generated Ceph config file + shell: "cat {{ tripleo_ceph_client_fetch_dir +'/'+ tripleo_ceph_client_cluster + '.conf' }}" + register: cat_ceph_conf + when: verbosity + - debug: + msg: "{{ cat_ceph_conf.stdout }}" + when: verbosity + vars: + tripleo_ceph_client_cluster: "ceph" + verbosity: false + expected_files: + - '{{ tripleo_ceph_client_cluster }}.client.glance.keyring' + - '{{ tripleo_ceph_client_cluster }}.client.manila.keyring' + - '{{ tripleo_ceph_client_cluster }}.conf' diff --git a/tripleo_ansible/roles/tripleo_ceph_client/molecule/default/molecule.yml b/tripleo_ansible/roles/tripleo_ceph_client/molecule/default/molecule.yml new file mode 100644 index 000000000..5ac01e418 --- /dev/null +++ b/tripleo_ansible/roles/tripleo_ceph_client/molecule/default/molecule.yml @@ -0,0 +1,50 @@ +--- +driver: + name: podman + +log: true + +platforms: + - name: ubi8 + hostname: ubi8 + image: ubi8/ubi-init + registry: + url: registry.access.redhat.com + dockerfile: Dockerfile + pkg_extras: python*setuptools + volumes: + - /etc/ci/mirror_info.sh:/etc/ci/mirror_info.sh:ro + - /etc/pki/rpm-gpg:/etc/pki/rpm-gpg + privileged: true + environment: &env + http_proxy: "{{ lookup('env', 'http_proxy') }}" + https_proxy: "{{ lookup('env', 'https_proxy') }}" + ulimits: &ulimit + - host + +provisioner: + inventory: + hosts: + all: + hosts: + ubi8: + ansible_python_interpreter: /usr/bin/python3 + vars: + ansible_user: root + name: ansible + log: true + env: + ANSIBLE_STDOUT_CALLBACK: yaml + +scenario: + test_sequence: + - destroy + - create + - prepare + - converge + - check + - verify + - destroy + +verifier: + name: testinfra diff --git a/tripleo_ansible/roles/tripleo_ceph_client/molecule/default/prepare.yml b/tripleo_ansible/roles/tripleo_ceph_client/molecule/default/prepare.yml new file mode 100644 index 000000000..04059d9a7 --- /dev/null +++ b/tripleo_ansible/roles/tripleo_ceph_client/molecule/default/prepare.yml @@ -0,0 +1,27 @@ +--- +# Copyright 2020 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: Prepare + hosts: all + roles: + - role: test_deps + post_tasks: + - name: Ensure tripleo_ceph_client_config_home exists on all clients + become: true + file: + path: "{{ tripleo_ceph_client_config_home | default('/etc/ceph') }}" + state: "directory" diff --git a/tripleo_ansible/roles/tripleo_ceph_client/tasks/ceph_ansible.yml b/tripleo_ansible/roles/tripleo_ceph_client/tasks/ceph_ansible.yml new file mode 100644 index 000000000..cab1ed936 --- /dev/null +++ b/tripleo_ansible/roles/tripleo_ceph_client/tasks/ceph_ansible.yml @@ -0,0 +1,38 @@ +--- +# Copyright 2020 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: Get values if ceph-ansible deployed + block: + - name: Get ceph_mon_ip addresses + set_fact: + tripleo_ceph_client_mon_ips: "{{ overcloud.get('ceph_mon_node_ips', []) }}" + vars: + overcloud: "{{ lookup('file', playbook_dir + '/group_vars/overcloud.json') }}" + when: + - (tripleo_enabled_services | intersect(['ceph_mon'])) and + (groups['ceph_mon'] | length > 0) + - name: Set external_cluster_mon_ips + set_fact: + external_cluster_mon_ips: "{{ ceph_ansible_group_vars_clients.external_cluster_mon_ips }}" + tripleo_ceph_client_mon_ips: [] + when: + - (ceph_ansible_group_vars_clients.external_cluster_mon_ips is defined) and + (not tripleo_enabled_services | intersect(['ceph_mon'])) + - name: Prepare ceph config variables + set_fact: + tripleo_ceph_client_fsid: "{{ ceph_ansible_group_vars_all.fsid }}" + tripleo_ceph_client_cluster_network: "{{ ceph_ansible_group_vars_all.cluster_network }}" + tripleo_ceph_client_cluster: "{{ ceph_ansible_group_vars_all.cluster }}" diff --git a/tripleo_ansible/roles/tripleo_ceph_client/tasks/create_ceph_conf.yml b/tripleo_ansible/roles/tripleo_ceph_client/tasks/create_ceph_conf.yml new file mode 100644 index 000000000..21630be95 --- /dev/null +++ b/tripleo_ansible/roles/tripleo_ceph_client/tasks/create_ceph_conf.yml @@ -0,0 +1,25 @@ +--- +# Copyright 2020 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: create ceph.conf + become: true + template: + src: templates/ceph_conf.j2 + dest: "{{ tripleo_ceph_client_fetch_dir }}/{{ tripleo_ceph_client_cluster | default('ceph') }}.conf" + group: root + owner: root + mode: 0644 + force: true diff --git a/tripleo_ansible/roles/tripleo_ceph_client/tasks/create_keys.yml b/tripleo_ansible/roles/tripleo_ceph_client/tasks/create_keys.yml new file mode 100644 index 000000000..e422d508b --- /dev/null +++ b/tripleo_ansible/roles/tripleo_ceph_client/tasks/create_keys.yml @@ -0,0 +1,26 @@ +--- +# Copyright 2020 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: create cephx key(s) + become: true + template: + src: templates/ceph_key.j2 + dest: "{{ tripleo_ceph_client_fetch_dir }}/{{ tripleo_ceph_client_cluster | default('ceph') }}.{{ item.name }}.keyring" + group: root + owner: root + mode: 0644 + force: true + loop: "{{ ceph_keys| default([]) }}" diff --git a/tripleo_ansible/roles/tripleo_ceph_client/tasks/fetch_dir.yml b/tripleo_ansible/roles/tripleo_ceph_client/tasks/fetch_dir.yml new file mode 100644 index 000000000..df8f80ef2 --- /dev/null +++ b/tripleo_ansible/roles/tripleo_ceph_client/tasks/fetch_dir.yml @@ -0,0 +1,33 @@ +--- +# Copyright 2020 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: Build fetch_dir + block: + - name: Clean any old fetch directory path + tags: 'clean_fetch_dir' + file: + state: absent + path: "{{ tripleo_ceph_client_fetch_dir }}/" + when: clean + - name: Create ceph_client_fetch_dir for the current execution + become: true + tags: 'build_fetch_dir' + file: + path: "{{ tripleo_ceph_client_fetch_dir }}" + state: directory + owner: "{{ ansible_user }}" + when: build diff --git a/tripleo_ansible/roles/tripleo_ceph_client/tasks/main.yml b/tripleo_ansible/roles/tripleo_ceph_client/tasks/main.yml new file mode 100644 index 000000000..ee2f2b128 --- /dev/null +++ b/tripleo_ansible/roles/tripleo_ceph_client/tasks/main.yml @@ -0,0 +1,95 @@ +--- +# Copyright 2020 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. + + +# "tripleo_ceph_client" will search for and load any operating system variable file + +# found within the "vars/" path. If no OS files are found the task will skip. +- name: Gather variables for each operating system + include_vars: "{{ item }}" + with_first_found: + - skip: true + files: + - "{{ 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 + +- name: get the list of enabled services on the overcloud + set_fact: + tripleo_enabled_services: "{{ enabled_services | default([]) }}" + +- include_tasks: fetch_dir.yml + name: Create ceph_client_fetch_dir + vars: + clean: true + build: true + +- name: Check if the input variables exist + stat: + path: '{{ tripleo_ceph_client_vars }}' + register: ceph_input_vars + +- name: Load variables produced by the cephadm provisioning process + include_vars: '{{ tripleo_ceph_client_vars }}' + when: ceph_input_vars.stat.exists == True + +- name: Get Ceph Cluster variables if ceph-ansible deployed + include_tasks: ceph_ansible.yml + when: + - ceph_input_vars.stat.exists == False + - ceph_ansible_group_vars_all is defined + +- include_tasks: create_keys.yml + name: Render keys provided for the Ceph cluster + vars: + ceph_keys: | + {% if tripleo_ceph_client_keys | length > 0 %} + {% set client_keys = tripleo_ceph_client_keys %} + {% elif keys is defined and keys is mapping %} + {% set client_keys = keys.get('keys', {}) %} + {% else %} + {% set client_keys = keys %} + {% endif %} + {{ client_keys }} + when: + - (tripleo_ceph_client_keys is defined) or (keys is defined) + +- include_tasks: create_ceph_conf.yml + name: Render ceph config for the Ceph Clients + vars: + config_overrides: | + {% if tripleo_ceph_client_config_overrides is defined and tripleo_ceph_client_config_overrides | length > 0 %} + {% set overrides = tripleo_ceph_client_config_overrides %} + {% elif ceph_overrides is defined %} + {% set overrides = ceph_overrides.get('ceph_conf_overrides', {}) %} + {% else %} + {% set overrides = {} %} + {% endif %} + {{ overrides }} + +- include_tasks: sync.yml + name: Configure Ceph Clients + +- include_tasks: fetch_dir.yml + name: Clean ceph_client_fetch_dir + vars: + clean: true + build: false diff --git a/tripleo_ansible/roles/tripleo_ceph_client/tasks/sync.yml b/tripleo_ansible/roles/tripleo_ceph_client/tasks/sync.yml new file mode 100644 index 000000000..51bf1c788 --- /dev/null +++ b/tripleo_ansible/roles/tripleo_ceph_client/tasks/sync.yml @@ -0,0 +1,32 @@ +--- +# Copyright 2020 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: copy keys around + tags: 'ceph_client_rsync' + block: + - name: Ensure /etc/ceph exists on all clients + become: true + file: + path: "{{ tripleo_ceph_client_config_home }}" + state: "directory" + + - name: push files to the other nodes of cluster + become: true + copy: + src: "{{ item[0] }}" + dest: "{{ tripleo_ceph_client_config_home }}/{{ item[0] | basename }}" + delegate_to: "{{ item[1] }}" + loop: "{{ lookup('fileglob', '{{ tripleo_ceph_client_fetch_dir }}/*', wantlist=True) |product(groups['ceph_client'])|list }}" diff --git a/tripleo_ansible/roles/tripleo_ceph_client/templates/ceph_conf.j2 b/tripleo_ansible/roles/tripleo_ceph_client/templates/ceph_conf.j2 new file mode 100644 index 000000000..7dc3e0867 --- /dev/null +++ b/tripleo_ansible/roles/tripleo_ceph_client/templates/ceph_conf.j2 @@ -0,0 +1,42 @@ +# {{ ansible_managed }} +{# MACRO AREA #} +{% macro render_map(root) -%} +{% for key, value in root.items() %} +{{ key}} = {{ value }} +{% endfor %} +{% endmacro %} + +[global] + +{% if tripleo_ceph_client_cluster_network is defined and tripleo_ceph_client_cluster_network | length > 0 %} +cluster network = {{ tripleo_ceph_client_cluster_network | regex_replace(' ', '') }} +{% endif %} +fsid = {{ tripleo_ceph_client_fsid }} +mon host = {% if tripleo_ceph_client_mon_ips is defined and tripleo_ceph_client_mon_ips | length > 0 %} +{% for ip in tripleo_ceph_client_mon_ips %}{{ip}}{% if not loop.last %},{% endif %}{% endfor %} +{% else %} +{{ external_cluster_mon_ips }} +{% endif %} + +{# Build CephConfigOverrides #} +{% for key, value in (config_overrides | default({})).items() %} +{% if not (['global', 'mon', 'mgr', 'osd', 'mds', 'client']) | intersect([key]) %} +{{ key }} = {{ value }} +{% elif (['global']) | intersect([key]) %} +{# Merge global defined values into this section #} +{{ render_map(value) }} +{% endif %} +{% endfor %} + +{# Build the remaining sections #} +{% for key, value in (config_overrides | default({})).items() %} +{% if (['mon', 'mgr', 'osd', 'mds', 'client']) | intersect([key]) %} +[{{ key }}] +{# Render the current section #} +{{ render_map(value) }} +{% endif %} +{% endfor %} + +[client.libvirt] +admin socket = {{ tripleo_ceph_client_rbd_admin_socket_path }}/$cluster-$type.$id.$pid.$cctid.asok +log file = {{ tripleo_ceph_client_rbd_log_file }} diff --git a/tripleo_ansible/roles/tripleo_ceph_client/templates/ceph_key.j2 b/tripleo_ansible/roles/tripleo_ceph_client/templates/ceph_key.j2 new file mode 100644 index 000000000..39b372f4b --- /dev/null +++ b/tripleo_ansible/roles/tripleo_ceph_client/templates/ceph_key.j2 @@ -0,0 +1,5 @@ +[{{ item.name }}] + key = "{{ item.key }}" +{% for key, value in item.caps.items() %} + caps {{ key }} = {{ value }} +{% endfor %} diff --git a/zuul.d/molecule.yaml b/zuul.d/molecule.yaml index 1eed1c9c9..e0554c813 100644 --- a/zuul.d/molecule.yaml +++ b/zuul.d/molecule.yaml @@ -12,6 +12,7 @@ - tripleo-ansible-centos-8-molecule-tripleo-modules - tripleo-ansible-centos-8-molecule-tripleo_bootstrap - tripleo-ansible-centos-8-molecule-tripleo_cellv2 + - tripleo-ansible-centos-8-molecule-tripleo_ceph_client - tripleo-ansible-centos-8-molecule-tripleo_ceph_run_ansible - tripleo-ansible-centos-8-molecule-tripleo_clients_install - tripleo-ansible-centos-8-molecule-tripleo_config @@ -66,6 +67,7 @@ - tripleo-ansible-centos-8-molecule-tripleo-modules - tripleo-ansible-centos-8-molecule-tripleo_bootstrap - tripleo-ansible-centos-8-molecule-tripleo_cellv2 + - tripleo-ansible-centos-8-molecule-tripleo_ceph_client - tripleo-ansible-centos-8-molecule-tripleo_ceph_run_ansible - tripleo-ansible-centos-8-molecule-tripleo_clients_install - tripleo-ansible-centos-8-molecule-tripleo_config @@ -122,6 +124,7 @@ - tripleo-ansible-centos-8-molecule-tripleo-modules - tripleo-ansible-centos-8-molecule-tripleo_bootstrap - tripleo-ansible-centos-8-molecule-tripleo_cellv2 + - tripleo-ansible-centos-8-molecule-tripleo_ceph_client - tripleo-ansible-centos-8-molecule-tripleo_ceph_run_ansible - tripleo-ansible-centos-8-molecule-tripleo_clients_install - tripleo-ansible-centos-8-molecule-tripleo_config @@ -219,6 +222,14 @@ parent: tripleo-ansible-centos-8-base vars: tripleo_role_name: tripleo_cellv2 +- job: + files: + - ^tripleo_ansible/roles/tripleo_ceph_client/.* + name: tripleo-ansible-centos-8-molecule-tripleo_ceph_client + parent: tripleo-ansible-centos-8-base + vars: + tripleo_job_ansible_args: --skip-tags=ceph_client_rsync,clean_fetch_dir + tripleo_role_name: tripleo_ceph_client - job: files: - ^tripleo_ansible/roles/tripleo_ceph_.*