From 5bcfb7114666efc0172132a4ebe0f5cff2be7931 Mon Sep 17 00:00:00 2001 From: Giulio Fidente Date: Mon, 22 Oct 2018 23:22:38 +0200 Subject: [PATCH] Skip hosts group in ceph-ansible inventory when all are blacklisted Ensures the hosts group is not created in the ceph-ansible inventory if all nodes of a given group are blacklisted. Closes-Bug: 1798044 Change-Id: Ibf25e28d02cee6308f3e9a2660e001ba73d756c0 --- docker/services/ceph-ansible/ceph-base.yaml | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/docker/services/ceph-ansible/ceph-base.yaml b/docker/services/ceph-ansible/ceph-base.yaml index 52893cca4f..7d7848a2a8 100644 --- a/docker/services/ceph-ansible/ceph-base.yaml +++ b/docker/services/ceph-ansible/ceph-base.yaml @@ -382,24 +382,23 @@ outputs: content: | {%- set ceph_groups = ['mgr', 'mon', 'osd', 'mds', 'rgw', 'nfs', 'rbdmirror', 'client'] -%} {%- for ceph_group in ceph_groups -%} - {%- if 'ceph_' ~ ceph_group in groups %} + {%- if 'ceph_' ~ ceph_group in groups -%} + {%- set ceph_group_hosts = groups['ceph_' ~ ceph_group] | difference(blacklisted_hostnames) -%} + {%- if ceph_group_hosts|length > 0 %} {{ ceph_group ~ 's:' }} hosts: - {% for host in groups['ceph_' ~ ceph_group] -%} - {%- if hostvars.raw_get(host)['ansible_hostname'] is defined -%} - {%- if hostvars.raw_get(host)['ansible_hostname'] not in blacklisted_hostnames -%} - {{ hostvars.raw_get(host)['ansible_hostname'] }}: + {% for host in ceph_group_hosts -%} + {{ host }}: ansible_user: {{ hostvars.raw_get(host)['ansible_ssh_user'] | default('root') }} ansible_host: {{ hostvars.raw_get(host)['ansible_host'] | default(host) }} ansible_become: true - {% if hostvars.raw_get(host)['ansible_connection'] | default('') == 'local' -%} + {% if hostvars.raw_get(host)['ansible_connection'] | default('') == 'local' -%} ansible_connection: local - {% endif -%} - {% endif -%} - {% endif -%} - {%- endfor -%} + {%- endif %} + {% endfor -%} + {%- endif -%} {%- endif -%} {%- endfor %} - name: set ceph-ansible group vars all