summaryrefslogtreecommitdiffstats
path: root/roles/lib_openshift
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2018-01-02 16:08:15 -0800
committerGitHub <noreply@github.com>2018-01-02 16:08:15 -0800
commitb1be9cd5d7573dc9d18ca27915bb383f8591117b (patch)
treefa76d72a4ecf648056dfedc6c68cb5f315341409 /roles/lib_openshift
parent8119a5c87a1560c2f607c06f30383133cc7137e5 (diff)
parent8cb27ae800df71ee816852df56cd2c861a0f0a0a (diff)
downloadopenshift-b1be9cd5d7573dc9d18ca27915bb383f8591117b.tar.gz
openshift-b1be9cd5d7573dc9d18ca27915bb383f8591117b.tar.bz2
openshift-b1be9cd5d7573dc9d18ca27915bb383f8591117b.tar.xz
openshift-b1be9cd5d7573dc9d18ca27915bb383f8591117b.zip
Merge pull request #5894 from ewolinetz/logging_defaults_from_existing
Automatic merge from submit-queue. Update logging to use existing cluster deployment for defaults This will allow us to use logging facts to set defaults of specific configurations such as ES index replicas and shard count. The update to logging facts yields us output like: ```json "elasticsearch": { "clusterrolebindings": {}, "configmaps": { "logging-elasticsearch": { "elasticsearch.yml": { "cloud": { "kubernetes": { "namespace": "${NAMESPACE}", "pod_label": "${POD_LABEL}", "pod_port": 9300 } }, "cluster": { "name": "${CLUSTER_NAME}" }, "discovery": { "type": "kubernetes", "zen.minimum_master_nodes": "${NODE_QUORUM}", "zen.ping.multicast.enabled": false }, "gateway": { "expected_nodes": "${RECOVER_EXPECTED_NODES}", "recover_after_nodes": "${NODE_QUORUM}", "recover_after_time": "${RECOVER_AFTER_TIME}" }, "index": { "number_of_replicas": 0, "number_of_shards": 1, "translog": { "flush_threshold_period": "5m", "flush_threshold_size": "256mb" }, "unassigned.node_left.delayed_timeout": "2m" }, "io.fabric8.elasticsearch.authentication.users": [ "system.logging.kibana", "system.logging.fluentd", "system.logging.curator", "system.admin" ], ``` TODO: - [x] Update logging facts to pull out settings from config maps - [x] Move `openshift_sanitize_inventory/library/conditional_set_fact.py` up to repo level - [x] Generate diffs against currently deployed configs and correctly patch in custom changes from customers - [x] Use `conditional_set_fact` to easily set defaults for logging based on logging facts, or falling back to role defaults when not specified in the inventory - [x] Update all components to follow patching configmaps
Diffstat (limited to 'roles/lib_openshift')
-rw-r--r--roles/lib_openshift/library/conditional_set_fact.py74
1 files changed, 74 insertions, 0 deletions
diff --git a/roles/lib_openshift/library/conditional_set_fact.py b/roles/lib_openshift/library/conditional_set_fact.py
new file mode 100644
index 000000000..363399f33
--- /dev/null
+++ b/roles/lib_openshift/library/conditional_set_fact.py
@@ -0,0 +1,74 @@
+#!/usr/bin/python
+
+""" Ansible module to help with setting facts conditionally based on other facts """
+
+from ansible.module_utils.basic import AnsibleModule
+
+
+DOCUMENTATION = '''
+---
+module: conditional_set_fact
+
+short_description: This will set a fact if the value is defined
+
+description:
+ - "To avoid constant set_fact & when conditions for each var we can use this"
+
+author:
+ - Eric Wolinetz ewolinet@redhat.com
+'''
+
+
+EXAMPLES = '''
+- name: Conditionally set fact
+ conditional_set_fact:
+ fact1: not_defined_variable
+
+- name: Conditionally set fact
+ conditional_set_fact:
+ fact1: not_defined_variable
+ fact2: defined_variable
+
+- name: Conditionally set fact falling back on default
+ conditional_set_fact:
+ fact1: not_defined_var | defined_variable
+
+'''
+
+
+def run_module():
+ """ The body of the module, we check if the variable name specified as the value
+ for the key is defined. If it is then we use that value as for the original key """
+
+ module = AnsibleModule(
+ argument_spec=dict(
+ facts=dict(type='dict', required=True),
+ vars=dict(required=False, type='dict', default=[])
+ ),
+ supports_check_mode=True
+ )
+
+ local_facts = dict()
+ is_changed = False
+
+ for param in module.params['vars']:
+ other_vars = module.params['vars'][param].replace(" ", "")
+
+ for other_var in other_vars.split('|'):
+ if other_var in module.params['facts']:
+ local_facts[param] = module.params['facts'][other_var]
+ if not is_changed:
+ is_changed = True
+ break
+
+ return module.exit_json(changed=is_changed, # noqa: F405
+ ansible_facts=local_facts)
+
+
+def main():
+ """ main """
+ run_module()
+
+
+if __name__ == '__main__':
+ main()