summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrenton Leanhardt <bleanhar@redhat.com>2015-11-09 15:07:30 -0500
committerBrenton Leanhardt <bleanhar@redhat.com>2015-11-09 15:07:30 -0500
commitf5d81c39b80bdc3f48e5552bba0d52a42f54617c (patch)
treef8dc421ed4a90cdc9fb2ebdabc3b6066cf055893
parent7b0a657110316516a0c667063dbb63ca48ac2b16 (diff)
parentca8a5abf71bd885a80f15f3d743eddfc6371af13 (diff)
downloadopenshift-f5d81c39b80bdc3f48e5552bba0d52a42f54617c.tar.gz
openshift-f5d81c39b80bdc3f48e5552bba0d52a42f54617c.tar.bz2
openshift-f5d81c39b80bdc3f48e5552bba0d52a42f54617c.tar.xz
openshift-f5d81c39b80bdc3f48e5552bba0d52a42f54617c.zip
Merge pull request #850 from dgoodwin/etcd-dir
Read etcd data dir from appropriate config file.
-rw-r--r--playbooks/adhoc/upgrades/upgrade.yml2
-rwxr-xr-xroles/openshift_facts/library/openshift_facts.py51
-rw-r--r--roles/openshift_facts/tasks/main.yml7
3 files changed, 51 insertions, 9 deletions
diff --git a/playbooks/adhoc/upgrades/upgrade.yml b/playbooks/adhoc/upgrades/upgrade.yml
index 1b6b5757c..03b9193c0 100644
--- a/playbooks/adhoc/upgrades/upgrade.yml
+++ b/playbooks/adhoc/upgrades/upgrade.yml
@@ -150,7 +150,7 @@
- name: Ensure python-yaml present for config upgrade
yum:
- pkg: python-yaml
+ pkg: PyYAML
state: installed
- name: Upgrade master configuration
diff --git a/roles/openshift_facts/library/openshift_facts.py b/roles/openshift_facts/library/openshift_facts.py
index 6d6c99c97..932bfd441 100755
--- a/roles/openshift_facts/library/openshift_facts.py
+++ b/roles/openshift_facts/library/openshift_facts.py
@@ -20,6 +20,8 @@ EXAMPLES = '''
import ConfigParser
import copy
import os
+import StringIO
+import yaml
from distutils.util import strtobool
from distutils.version import LooseVersion
from netaddr import IPNetwork
@@ -526,18 +528,55 @@ def set_aggregate_facts(facts):
first_svc_ip = str(IPNetwork(facts['master']['portal_net'])[1])
all_hostnames.add(first_svc_ip)
internal_hostnames.add(first_svc_ip)
-
- if facts['master']['embedded_etcd']:
- facts['master']['etcd_data_dir'] = os.path.join(
- facts['common']['data_dir'], 'openshift.local.etcd')
- else:
- facts['master']['etcd_data_dir'] = '/var/lib/etcd'
+ _add_etcd_data_dir_fact(facts)
facts['common']['all_hostnames'] = list(all_hostnames)
facts['common']['internal_hostnames'] = list(internal_hostnames)
return facts
+
+def _add_etcd_data_dir_fact(facts):
+ """
+ If using embedded etcd, loads the data directory from master-config.yaml.
+
+ If using standalone etcd, loads ETCD_DATA_DIR from etcd.conf.
+
+ If anything goes wrong parsing these, the fact will not be set.
+ """
+ if facts['master']['embedded_etcd']:
+ try:
+ # Parse master config to find actual etcd data dir:
+ master_cfg_path = os.path.join(facts['common']['config_base'],
+ 'master/master-config.yaml')
+ master_cfg_f = open(master_cfg_path, 'r')
+ config = yaml.safe_load(master_cfg_f.read())
+ master_cfg_f.close()
+
+ facts['master']['etcd_data_dir'] = \
+ config['etcdConfig']['storageDirectory']
+ # We don't want exceptions bubbling up here:
+ # pylint: disable=broad-except
+ except Exception:
+ pass
+ else:
+ # Read ETCD_DATA_DIR from /etc/etcd/etcd.conf:
+ try:
+ # Add a fake section for parsing:
+ ini_str = '[root]\n' + open('/etc/etcd/etcd.conf', 'r').read()
+ ini_fp = StringIO.StringIO(ini_str)
+ config = ConfigParser.RawConfigParser()
+ config.readfp(ini_fp)
+ etcd_data_dir = config.get('root', 'ETCD_DATA_DIR')
+ if etcd_data_dir.startswith('"') and etcd_data_dir.endswith('"'):
+ etcd_data_dir = etcd_data_dir[1:-1]
+ facts['master']['etcd_data_dir'] = etcd_data_dir
+ # We don't want exceptions bubbling up here:
+ # pylint: disable=broad-except
+ except Exception:
+ pass
+
+
def set_deployment_facts_if_unset(facts):
""" Set Facts that vary based on deployment_type. This currently
includes common.service_type, common.config_base, master.registry_url,
diff --git a/roles/openshift_facts/tasks/main.yml b/roles/openshift_facts/tasks/main.yml
index a46b45b8c..a28aa7ba2 100644
--- a/roles/openshift_facts/tasks/main.yml
+++ b/roles/openshift_facts/tasks/main.yml
@@ -6,8 +6,11 @@
- ansible_version | version_compare('1.9.0', 'ne')
- ansible_version | version_compare('1.9.0.1', 'ne')
-- name: Ensure python-netaddr is installed
- yum: pkg=python-netaddr state=installed
+- name: Ensure python-netaddr and PyYaml are installed
+ yum: pkg={{ item }} state=installed
+ with_items:
+ - python-netaddr
+ - PyYAML
- name: Gather Cluster facts
openshift_facts: