summaryrefslogtreecommitdiffstats
path: root/roles
diff options
context:
space:
mode:
Diffstat (limited to 'roles')
-rw-r--r--roles/lib_utils/filter_plugins/oo_filters.py2
-rw-r--r--roles/openshift_etcd_facts/defaults/main.yml2
-rw-r--r--roles/openshift_etcd_facts/tasks/main.yml1
-rw-r--r--roles/openshift_etcd_facts/tasks/set_etcd_ca_host.yml44
4 files changed, 48 insertions, 1 deletions
diff --git a/roles/lib_utils/filter_plugins/oo_filters.py b/roles/lib_utils/filter_plugins/oo_filters.py
index 574743ff1..c355115b5 100644
--- a/roles/lib_utils/filter_plugins/oo_filters.py
+++ b/roles/lib_utils/filter_plugins/oo_filters.py
@@ -126,7 +126,7 @@ def lib_utils_oo_collect(data_list, attribute=None, filters=None):
raise errors.AnsibleFilterError(
"lib_utils_oo_collect expects filter to be a dict")
retval.extend([get_attr(d, attribute) for d in data if (
- all([d.get(key, None) == filters[key] for key in filters]))])
+ all([get_attr(d, key) == filters[key] for key in filters]))])
else:
retval.extend([get_attr(d, attribute) for d in data])
diff --git a/roles/openshift_etcd_facts/defaults/main.yml b/roles/openshift_etcd_facts/defaults/main.yml
new file mode 100644
index 000000000..d13e7c912
--- /dev/null
+++ b/roles/openshift_etcd_facts/defaults/main.yml
@@ -0,0 +1,2 @@
+---
+etcd_ca_host_group: "oo_etcd_to_config"
diff --git a/roles/openshift_etcd_facts/tasks/main.yml b/roles/openshift_etcd_facts/tasks/main.yml
index ed97d539c..86546f4e3 100644
--- a/roles/openshift_etcd_facts/tasks/main.yml
+++ b/roles/openshift_etcd_facts/tasks/main.yml
@@ -1 +1,2 @@
---
+- import_tasks: set_etcd_ca_host.yml
diff --git a/roles/openshift_etcd_facts/tasks/set_etcd_ca_host.yml b/roles/openshift_etcd_facts/tasks/set_etcd_ca_host.yml
new file mode 100644
index 000000000..bf8d28a9b
--- /dev/null
+++ b/roles/openshift_etcd_facts/tasks/set_etcd_ca_host.yml
@@ -0,0 +1,44 @@
+---
+- name: Check for CA indicator files
+ stat:
+ path: "{{ item.0 }}"
+ delegate_to: "{{ item.1 }}"
+ with_nested:
+ - - /etc/etcd/ca
+ - /etc/etcd/generated_certs
+ - "{{ groups[etcd_ca_host_group] }}"
+ register: __etcd_ca_host_stat
+ run_once: true
+
+# Collect ansible_host (inventory hostname) of hosts with /etc/etcd/ca
+# and /etc/etcd/generated_certs directories.
+- set_fact:
+ __etcd_ca_dir_hosts: "{{ __etcd_ca_host_stat.results
+ | lib_utils_oo_collect('_ansible_delegated_vars.ansible_host',
+ filters={'stat.path':'/etc/etcd/ca','stat.exists':True}) }}"
+ __etcd_generated_certs_dir_hosts: "{{ __etcd_ca_host_stat.results
+ | lib_utils_oo_collect('_ansible_delegated_vars.ansible_host',
+ filters={'stat.path':'/etc/etcd/generated_certs','stat.exists':True}) }}"
+ run_once: true
+
+# __etcd_ca_hosts is the intersection of hosts which have /etc/etcd/ca
+# and /etc/etcd/generated_certs directories.
+- set_fact:
+ __etcd_ca_hosts: "{{ __etcd_ca_dir_hosts | intersect(__etcd_generated_certs_dir_hosts) }}"
+ run_once: true
+
+# __etcd_ca_hosts should only contain one host. If more than one host
+# is able to be an etcd CA host then we will use the first.
+- set_fact:
+ etcd_ca_host: "{{ __etcd_ca_hosts[0] }}"
+ when:
+ - __etcd_ca_hosts | length > 0
+ - etcd_ca_host is not defined
+
+# No etcd_ca_host was found in __etcd_ca_hosts. This is probably a
+# fresh installation so we will default to the first member of the
+# etcd host group.
+- set_fact:
+ etcd_ca_host: "{{ groups[etcd_ca_host_group].0 }}"
+ when:
+ - etcd_ca_host is not defined