diff options
-rw-r--r-- | playbooks/adhoc/upgrades/upgrade.yml | 7 | ||||
-rw-r--r-- | playbooks/common/openshift-node/config.yml | 11 | ||||
-rwxr-xr-x | roles/openshift_facts/library/openshift_facts.py | 51 | ||||
-rw-r--r-- | roles/openshift_facts/tasks/main.yml | 7 | ||||
-rw-r--r-- | utils/src/ooinstall/oo_config.py | 1 | ||||
-rw-r--r-- | utils/src/ooinstall/openshift_ansible.py | 2 | ||||
-rw-r--r-- | utils/test/cli_installer_tests.py | 9 | ||||
-rw-r--r-- | utils/test/oo_config_tests.py | 22 |
8 files changed, 82 insertions, 28 deletions
diff --git a/playbooks/adhoc/upgrades/upgrade.yml b/playbooks/adhoc/upgrades/upgrade.yml index 1b6b5757c..7ce2698db 100644 --- a/playbooks/adhoc/upgrades/upgrade.yml +++ b/playbooks/adhoc/upgrades/upgrade.yml @@ -120,10 +120,7 @@ msg: This playbook requires Origin 1.0.6 or later when: deployment_type == 'origin' and g_aos_versions.curr_version | version_compare('1.0.6','<') - - fail: - msg: This playbook requires Atomic OpenShift 3.0.2 or later - when: deployment_type in ['openshift-enterprise', 'atomic-openshift'] and g_aos_versions.curr_version | version_compare('3.0.2','<') - + # TODO: This should be specific to the 3.1 upgrade playbook (coming in future refactor), otherwise we are blocking 3.0.1 to 3.0.2 here. - fail: msg: Atomic OpenShift 3.1 packages not found when: deployment_type in ['openshift-enterprise', 'atomic-openshift'] and g_aos_versions.curr_version | version_compare('3.0.2.900','<') and (g_aos_versions.avail_version is none or g_aos_versions.avail_version | version_compare('3.0.2.900','<')) @@ -150,7 +147,7 @@ - name: Ensure python-yaml present for config upgrade yum: - pkg: python-yaml + pkg: PyYAML state: installed - name: Upgrade master configuration diff --git a/playbooks/common/openshift-node/config.yml b/playbooks/common/openshift-node/config.yml index ba96b4a78..8da9e231f 100644 --- a/playbooks/common/openshift-node/config.yml +++ b/playbooks/common/openshift-node/config.yml @@ -45,6 +45,7 @@ - node.etcd-client.crt - node.etcd-ca.crt register: g_external_etcd_flannel_cert_stat_result + when: groups.oo_etcd_to_config is defined and groups.oo_etcd_to_config and (openshift.common.use_flannel | bool) - set_fact: etcd_client_flannel_certs_missing: "{{ g_external_etcd_flannel_cert_stat_result.results | map(attribute='stat.exists') @@ -69,11 +70,13 @@ hosts: oo_first_etcd vars: etcd_generated_certs_dir: /etc/etcd/generated_certs - etcd_needing_client_certs: "{{ hostvars - | oo_select_keys(groups['oo_nodes_to_config']) - | oo_filter_list(filter_attr='etcd_client_flannel_certs_missing') }}" sync_tmpdir: "{{ hostvars.localhost.mktemp.stdout }}" pre_tasks: + - set_fact: + etcd_needing_client_certs: "{{ hostvars + | oo_select_keys(groups['oo_nodes_to_config']) + | oo_filter_list(filter_attr='etcd_client_flannel_certs_missing') | default([]) }}" + when: etcd_client_flannel_certs_missing is defined and etcd_client_flannel_certs_missing roles: - role: etcd_certificates post_tasks: @@ -84,6 +87,7 @@ args: creates: "{{ etcd_generated_certs_dir }}/{{ item.etcd_cert_subdir }}.tgz" with_items: etcd_needing_client_certs + when: etcd_client_flannel_certs_missing is defined and etcd_client_flannel_certs_missing - name: Retrieve the etcd cert tarballs fetch: src: "{{ etcd_generated_certs_dir }}/{{ item.etcd_cert_subdir }}.tgz" @@ -92,6 +96,7 @@ fail_on_missing: yes validate_checksum: yes with_items: etcd_needing_client_certs + when: etcd_client_flannel_certs_missing is defined and etcd_client_flannel_certs_missing - name: Copy the external etcd flannel certs to the nodes hosts: oo_nodes_to_config 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: diff --git a/utils/src/ooinstall/oo_config.py b/utils/src/ooinstall/oo_config.py index f35a8f51b..cf51bb404 100644 --- a/utils/src/ooinstall/oo_config.py +++ b/utils/src/ooinstall/oo_config.py @@ -118,6 +118,7 @@ class OOConfig(object): new_hosts = [] if 'validated_facts' in self.settings: for key, value in self.settings['validated_facts'].iteritems(): + value['connect_to'] = key if 'masters' in self.settings and key in self.settings['masters']: value['master'] = True if 'nodes' in self.settings and key in self.settings['nodes']: diff --git a/utils/src/ooinstall/openshift_ansible.py b/utils/src/ooinstall/openshift_ansible.py index bac4951d5..489a0f7c1 100644 --- a/utils/src/ooinstall/openshift_ansible.py +++ b/utils/src/ooinstall/openshift_ansible.py @@ -127,7 +127,7 @@ def default_facts(hosts, verbose=False): def run_main_playbook(hosts, hosts_to_run_on, verbose=False): global CFG - inventory_file = generate_inventory(hosts) + inventory_file = generate_inventory(hosts_to_run_on) if len(hosts_to_run_on) != len(hosts): main_playbook_path = os.path.join(CFG.ansible_playbook_directory, 'playbooks/common/openshift-cluster/scaleup.yml') diff --git a/utils/test/cli_installer_tests.py b/utils/test/cli_installer_tests.py index b183f0acb..fcefcdff3 100644 --- a/utils/test/cli_installer_tests.py +++ b/utils/test/cli_installer_tests.py @@ -46,18 +46,21 @@ SAMPLE_CONFIG = """ variant: %s ansible_ssh_user: root hosts: - - ip: 10.0.0.1 + - connect_to: master-private.example.com + ip: 10.0.0.1 hostname: master-private.example.com public_ip: 24.222.0.1 public_hostname: master.example.com master: true node: true - - ip: 10.0.0.2 + - connect_to: node1-private.example.com + ip: 10.0.0.2 hostname: node1-private.example.com public_ip: 24.222.0.2 public_hostname: node1.example.com node: true - - ip: 10.0.0.3 + - connect_to: node2-private.example.com + ip: 10.0.0.3 hostname: node2-private.example.com public_ip: 24.222.0.3 public_hostname: node2.example.com diff --git a/utils/test/oo_config_tests.py b/utils/test/oo_config_tests.py index 6dc335a0e..0dd4a30e9 100644 --- a/utils/test/oo_config_tests.py +++ b/utils/test/oo_config_tests.py @@ -14,18 +14,21 @@ SAMPLE_CONFIG = """ variant: openshift-enterprise ansible_ssh_user: root hosts: - - ip: 10.0.0.1 + - connect_to: master-private.example.com + ip: 10.0.0.1 hostname: master-private.example.com public_ip: 24.222.0.1 public_hostname: master.example.com master: true node: true - - ip: 10.0.0.2 + - connect_to: node1-private.example.com + ip: 10.0.0.2 hostname: node1-private.example.com public_ip: 24.222.0.2 public_hostname: node1.example.com node: true - - ip: 10.0.0.3 + - connect_to: node2-private.example.com + ip: 10.0.0.3 hostname: node2-private.example.com public_ip: 24.222.0.3 public_hostname: node2.example.com @@ -54,16 +57,19 @@ validated_facts: CONFIG_INCOMPLETE_FACTS = """ hosts: - - ip: 10.0.0.1 + - connect_to: 10.0.0.1 + ip: 10.0.0.1 hostname: master-private.example.com public_ip: 24.222.0.1 public_hostname: master.example.com master: true - - ip: 10.0.0.2 - hostname: node1-private.example.com + - connect_to: 10.0.0.2 + ip: 10.0.0.2 + hostname: 24.222.0.2 public_ip: 24.222.0.2 node: true - - ip: 10.0.0.3 + - connect_to: 10.0.0.3 + ip: 10.0.0.3 node: true """ @@ -145,7 +151,7 @@ class OOConfigTests(OOInstallFixture): ooconfig = OOConfig(cfg_path) self.assertEquals(3, len(ooconfig.hosts)) - self.assertEquals("10.0.0.1", ooconfig.hosts[0].name) + self.assertEquals("master-private.example.com", ooconfig.hosts[0].connect_to) self.assertEquals("10.0.0.1", ooconfig.hosts[0].ip) self.assertEquals("master-private.example.com", ooconfig.hosts[0].hostname) |