summaryrefslogtreecommitdiffstats
path: root/utils/src
diff options
context:
space:
mode:
Diffstat (limited to 'utils/src')
-rw-r--r--utils/src/ooinstall/__init__.py4
-rw-r--r--utils/src/ooinstall/ansible_plugins/facts_callback.py9
-rw-r--r--utils/src/ooinstall/cli_installer.py409
-rw-r--r--utils/src/ooinstall/oo_config.py150
-rw-r--r--utils/src/ooinstall/openshift_ansible.py58
-rw-r--r--utils/src/ooinstall/variants.py38
6 files changed, 406 insertions, 262 deletions
diff --git a/utils/src/ooinstall/__init__.py b/utils/src/ooinstall/__init__.py
index 944dea3b5..96e495e19 100644
--- a/utils/src/ooinstall/__init__.py
+++ b/utils/src/ooinstall/__init__.py
@@ -1,5 +1 @@
-# TODO: Temporarily disabled due to importing old code into openshift-ansible
-# repo. We will work on these over time.
# pylint: disable=missing-docstring
-
-from .oo_config import OOConfig
diff --git a/utils/src/ooinstall/ansible_plugins/facts_callback.py b/utils/src/ooinstall/ansible_plugins/facts_callback.py
index 2537a099f..e51890a22 100644
--- a/utils/src/ooinstall/ansible_plugins/facts_callback.py
+++ b/utils/src/ooinstall/ansible_plugins/facts_callback.py
@@ -6,6 +6,7 @@ import os
import yaml
from ansible.plugins.callback import CallbackBase
+
# pylint: disable=super-init-not-called
class CallbackModule(CallbackBase):
@@ -19,9 +20,9 @@ class CallbackModule(CallbackBase):
self.hosts_yaml_name = os.environ['OO_INSTALL_CALLBACK_FACTS_YAML']
except KeyError:
raise ValueError('The OO_INSTALL_CALLBACK_FACTS_YAML environment '
- 'variable must be set.')
+ 'variable must be set.')
self.hosts_yaml = os.open(self.hosts_yaml_name, os.O_CREAT |
- os.O_WRONLY)
+ os.O_WRONLY)
def v2_on_any(self, *args, **kwargs):
pass
@@ -72,9 +73,9 @@ class CallbackModule(CallbackBase):
def v2_playbook_on_task_start(self, name, is_conditional):
pass
- #pylint: disable=too-many-arguments
+ # pylint: disable=too-many-arguments
def v2_playbook_on_vars_prompt(self, varname, private=True, prompt=None,
- encrypt=None, confirm=False, salt_size=None, salt=None, default=None):
+ encrypt=None, confirm=False, salt_size=None, salt=None, default=None):
pass
def v2_playbook_on_setup(self):
diff --git a/utils/src/ooinstall/cli_installer.py b/utils/src/ooinstall/cli_installer.py
index e197c722d..dd17fbf89 100644
--- a/utils/src/ooinstall/cli_installer.py
+++ b/utils/src/ooinstall/cli_installer.py
@@ -1,41 +1,62 @@
+# TODO: Temporarily disabled due to importing old code into openshift-ansible
+# repo. We will work on these over time.
# pylint: disable=bad-continuation,missing-docstring,no-self-use,invalid-name,no-value-for-parameter,too-many-lines
import os
import re
import sys
-from distutils.version import LooseVersion
+import logging
import click
+from pkg_resources import parse_version
from ooinstall import openshift_ansible
-from ooinstall import OOConfig
+from ooinstall.oo_config import OOConfig
from ooinstall.oo_config import OOConfigInvalidHostError
from ooinstall.oo_config import Host, Role
from ooinstall.variants import find_variant, get_variant_version_combos
+installer_log = logging.getLogger('installer')
+installer_log.setLevel(logging.CRITICAL)
+installer_file_handler = logging.FileHandler('/tmp/installer.txt')
+installer_file_handler.setFormatter(
+ logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s'))
+# Example output:
+# 2016-08-23 07:34:58,480 - installer - DEBUG - Going to 'load_system_facts'
+installer_file_handler.setLevel(logging.DEBUG)
+installer_log.addHandler(installer_file_handler)
+
DEFAULT_ANSIBLE_CONFIG = '/usr/share/atomic-openshift-utils/ansible.cfg'
DEFAULT_PLAYBOOK_DIR = '/usr/share/ansible/openshift-ansible/'
UPGRADE_MAPPINGS = {
- '3.0':{
- 'minor_version' :'3.0',
- 'minor_playbook':'v3_0_minor/upgrade.yml',
- 'major_version' :'3.1',
- 'major_playbook':'v3_0_to_v3_1/upgrade.yml',
- },
- '3.1':{
- 'minor_version' :'3.1',
- 'minor_playbook':'v3_1_minor/upgrade.yml',
- 'major_playbook':'v3_1_to_v3_2/upgrade.yml',
- 'major_version' :'3.2',
- }
- }
+ '3.0': {
+ 'minor_version': '3.0',
+ 'minor_playbook': 'v3_0_minor/upgrade.yml',
+ 'major_version': '3.1',
+ 'major_playbook': 'v3_0_to_v3_1/upgrade.yml',
+ },
+ '3.1': {
+ 'minor_version': '3.1',
+ 'minor_playbook': 'v3_1_minor/upgrade.yml',
+ 'major_playbook': 'v3_1_to_v3_2/upgrade.yml',
+ 'major_version': '3.2',
+ },
+ '3.2': {
+ 'minor_version': '3.2',
+ 'minor_playbook': 'v3_2/upgrade.yml',
+ 'major_playbook': 'v3_2/upgrade.yml',
+ 'major_version': '3.3',
+ }
+}
+
def validate_ansible_dir(path):
if not path:
- raise click.BadParameter('An ansible path must be provided')
+ raise click.BadParameter('An Ansible path must be provided')
return path
# if not os.path.exists(path)):
# raise click.BadParameter("Path \"{}\" doesn't exist".format(path))
+
def is_valid_hostname(hostname):
if not hostname or len(hostname) > 255:
return False
@@ -44,59 +65,43 @@ def is_valid_hostname(hostname):
allowed = re.compile(r"(?!-)[A-Z\d-]{1,63}(?<!-)$", re.IGNORECASE)
return all(allowed.match(x) for x in hostname.split("."))
+
def validate_prompt_hostname(hostname):
if hostname == '' or is_valid_hostname(hostname):
return hostname
raise click.BadParameter('Invalid hostname. Please double-check this value and re-enter it.')
+
def get_ansible_ssh_user():
click.clear()
message = """
-This installation process will involve connecting to remote hosts via ssh. Any
-account may be used however if a non-root account is used it must have
+This installation process involves connecting to remote hosts via ssh. Any
+account may be used. However, if a non-root account is used, then it must have
passwordless sudo access.
"""
click.echo(message)
return click.prompt('User for ssh access', default='root')
+
def get_master_routingconfig_subdomain():
click.clear()
message = """
-You might want to override the default subdomain uses for exposed routes. If you don't know what
-this is, use the default value.
+You might want to override the default subdomain used for exposed routes. If you don't know what this is, use the default value.
"""
click.echo(message)
return click.prompt('New default subdomain (ENTER for none)', default='')
+
def list_hosts(hosts):
hosts_idx = range(len(hosts))
for idx in hosts_idx:
click.echo(' {}: {}'.format(idx, hosts[idx]))
-def delete_hosts(hosts):
- while True:
- list_hosts(hosts)
- del_idx = click.prompt('Select host to delete, y/Y to confirm, ' \
- 'or n/N to add more hosts', default='n')
- try:
- del_idx = int(del_idx)
- hosts.remove(hosts[del_idx])
- except IndexError:
- click.echo("\"{}\" doesn't match any hosts listed.".format(del_idx))
- except ValueError:
- try:
- response = del_idx.lower()
- if response in ['y', 'n']:
- return hosts, response
- click.echo("\"{}\" doesn't coorespond to any valid input.".format(del_idx))
- except AttributeError:
- click.echo("\"{}\" doesn't coorespond to any valid input.".format(del_idx))
- return hosts, None
def collect_hosts(oo_cfg, existing_env=False, masters_set=False, print_summary=True):
"""
Collect host information from user. This will later be filled in using
- ansible.
+ Ansible.
Returns: a list of host information collected from the user
"""
@@ -105,28 +110,28 @@ def collect_hosts(oo_cfg, existing_env=False, masters_set=False, print_summary=T
message = """
You must now specify the hosts that will compose your OpenShift cluster.
-Please enter an IP or hostname to connect to for each system in the cluster.
-You will then be prompted to identify what role you would like this system to
+Please enter an IP address or hostname to connect to for each system in the
+cluster. You will then be prompted to identify what role you want this system to
serve in the cluster.
-OpenShift Masters serve the API and web console and coordinate the jobs to run
-across the environment. If desired you can specify multiple Master systems for
-an HA deployment, in which case you will be prompted to identify a *separate*
-system to act as the load balancer for your cluster after all Masters and Nodes
-are defined.
+OpenShift masters serve the API and web console and coordinate the jobs to run
+across the environment. Optionally, you can specify multiple master systems for
+a high-availability (HA) deployment. If you choose an HA deployment, then you
+are prompted to identify a *separate* system to act as the load balancer for
+your cluster once you define all masters and nodes.
-If only one Master is specified, an etcd instance embedded within the OpenShift
-Master service will be used as the datastore. This can be later replaced with a
-separate etcd instance if desired. If multiple Masters are specified, a
-separate etcd cluster will be configured with each Master serving as a member.
+If only one master is specified, an etcd instance is embedded within the
+OpenShift master service to use as the datastore. This can be later replaced
+with a separate etcd instance, if required. If multiple masters are specified,
+then a separate etcd cluster is configured with each master serving as a member.
-Any Masters configured as part of this installation process will also be
-configured as Nodes. This is so that the Master will be able to proxy to Pods
-from the API. By default this Node will be unschedulable but this can be changed
-after installation with 'oadm manage-node'.
+Any masters configured as part of this installation process are also
+configured as nodes. This enables the master to proxy to pods
+from the API. By default, this node is unschedulable, but this can be changed
+after installation with the 'oadm manage-node' command.
-OpenShift Nodes provide the runtime environments for containers. They will
-host the required services to be managed by the Master.
+OpenShift nodes provide the runtime environments for containers. They host the
+required services to be managed by the master.
http://docs.openshift.com/enterprise/latest/architecture/infrastructure_components/kubernetes_infrastructure.html#master
http://docs.openshift.com/enterprise/latest/architecture/infrastructure_components/kubernetes_infrastructure.html#node
@@ -144,7 +149,7 @@ http://docs.openshift.com/enterprise/latest/architecture/infrastructure_componen
value_proc=validate_prompt_hostname)
if not masters_set:
- if click.confirm('Will this host be an OpenShift Master?'):
+ if click.confirm('Will this host be an OpenShift master?'):
host_props['roles'].append('master')
host_props['roles'].append('etcd')
num_masters += 1
@@ -168,12 +173,11 @@ http://docs.openshift.com/enterprise/latest/architecture/infrastructure_componen
hosts.append(host)
-
if print_summary:
print_installation_summary(hosts, oo_cfg.settings['variant_version'])
# If we have one master, this is enough for an all-in-one deployment,
- # thus we can start asking if you wish to proceed. Otherwise we assume
+ # thus we can start asking if you want to proceed. Otherwise we assume
# you must.
if masters_set or num_masters != 2:
more_hosts = click.confirm('Do you want to add additional hosts?')
@@ -206,12 +210,12 @@ def print_installation_summary(hosts, version=None):
nodes = [host for host in hosts if host.is_node()]
dedicated_nodes = [host for host in hosts if host.is_node() and not host.is_master()]
click.echo('')
- click.echo('Total OpenShift Masters: %s' % len(masters))
- click.echo('Total OpenShift Nodes: %s' % len(nodes))
+ click.echo('Total OpenShift masters: %s' % len(masters))
+ click.echo('Total OpenShift nodes: %s' % len(nodes))
if len(masters) == 1 and version != '3.0':
ha_hint_message = """
-NOTE: Add a total of 3 or more Masters to perform an HA installation."""
+NOTE: Add a total of 3 or more masters to perform an HA installation."""
click.echo(ha_hint_message)
elif len(masters) == 2:
min_masters_message = """
@@ -220,19 +224,19 @@ Please add one more to proceed."""
click.echo(min_masters_message)
elif len(masters) >= 3:
ha_message = """
-NOTE: Multiple Masters specified, this will be an HA deployment with a separate
+NOTE: Multiple masters specified, this will be an HA deployment with a separate
etcd cluster. You will be prompted to provide the FQDN of a load balancer and
a host for storage once finished entering hosts.
"""
click.echo(ha_message)
dedicated_nodes_message = """
-WARNING: Dedicated Nodes are recommended for an HA deployment. If no dedicated
-Nodes are specified, each configured Master will be marked as a schedulable
-Node."""
+WARNING: Dedicated nodes are recommended for an HA deployment. If no dedicated
+nodes are specified, each configured master will be marked as a schedulable
+node."""
min_ha_nodes_message = """
-WARNING: A minimum of 3 dedicated Nodes are recommended for an HA
+WARNING: A minimum of 3 dedicated nodes are recommended for an HA
deployment."""
if len(dedicated_nodes) == 0:
click.echo(dedicated_nodes_message)
@@ -245,14 +249,14 @@ deployment."""
def print_host_summary(all_hosts, host):
click.echo("- %s" % host.connect_to)
if host.is_master():
- click.echo(" - OpenShift Master")
+ click.echo(" - OpenShift master")
if host.is_node():
if host.is_dedicated_node():
- click.echo(" - OpenShift Node (Dedicated)")
+ click.echo(" - OpenShift node (Dedicated)")
elif host.is_schedulable_node(all_hosts):
- click.echo(" - OpenShift Node")
+ click.echo(" - OpenShift node")
else:
- click.echo(" - OpenShift Node (Unscheduled)")
+ click.echo(" - OpenShift node (Unscheduled)")
if host.is_master_lb():
if host.preconfigured:
click.echo(" - Load Balancer (Preconfigured)")
@@ -276,14 +280,14 @@ def collect_master_lb(hosts):
this is an invalid configuration.
"""
message = """
-Setting up High Availability Masters requires a load balancing solution.
-Please provide a the FQDN of a host that will be configured as a proxy. This
+Setting up high-availability masters requires a load balancing solution.
+Please provide the FQDN of a host that will be configured as a proxy. This
can be either an existing load balancer configured to balance all masters on
port 8443 or a new host that will have HAProxy installed on it.
-If the host provided does is not yet configured, a reference haproxy load
-balancer will be installed. It's important to note that while the rest of the
-environment will be fault tolerant this reference load balancer will not be.
+If the host provided is not yet configured, a reference HAProxy load
+balancer will be installed. It's important to note that while the rest of the
+environment will be fault-tolerant, this reference load balancer will not be.
It can be replaced post-installation with a load balancer with the same
hostname.
"""
@@ -305,19 +309,20 @@ hostname.
host_props['connect_to'] = click.prompt('Enter hostname or IP address',
value_proc=validate_prompt_lb)
install_haproxy = \
- click.confirm('Should the reference haproxy load balancer be installed on this host?')
+ click.confirm('Should the reference HAProxy load balancer be installed on this host?')
host_props['preconfigured'] = not install_haproxy
host_props['roles'] = ['master_lb']
master_lb = Host(**host_props)
hosts.append(master_lb)
+
def collect_storage_host(hosts):
"""
Get a valid host for storage from the user and append it to the list of
hosts.
"""
message = """
-Setting up High Availability Masters requires a storage host. Please provide a
+Setting up high-availability masters requires a storage host. Please provide a
host that will be configured as a Registry Storage.
Note: Containerized storage hosts are not currently supported.
@@ -328,8 +333,8 @@ Note: Containerized storage hosts are not currently supported.
first_master = next(host for host in hosts if host.is_master())
hostname_or_ip = click.prompt('Enter hostname or IP address',
- value_proc=validate_prompt_hostname,
- default=first_master.connect_to)
+ value_proc=validate_prompt_hostname,
+ default=first_master.connect_to)
existing, existing_host = is_host_already_node_or_master(hostname_or_ip, hosts)
if existing and existing_host.is_node():
existing_host.roles.append('storage')
@@ -340,6 +345,7 @@ Note: Containerized storage hosts are not currently supported.
storage = Host(**host_props)
hosts.append(storage)
+
def is_host_already_node_or_master(hostname, hosts):
is_existing = False
existing_host = None
@@ -351,19 +357,20 @@ def is_host_already_node_or_master(hostname, hosts):
return is_existing, existing_host
+
def confirm_hosts_facts(oo_cfg, callback_facts):
hosts = oo_cfg.deployment.hosts
click.clear()
message = """
-A list of the facts gathered from the provided hosts follows. Because it is
-often the case that the hostname for a system inside the cluster is different
-from the hostname that is resolveable from command line or web clients
-these settings cannot be validated automatically.
+The following is a list of the facts gathered from the provided hosts. The
+hostname for a system inside the cluster is often different from the hostname
+that is resolveable from command-line or web clients, therefore these settings
+cannot be validated automatically.
-For some cloud providers the installer is able to gather metadata exposed in
-the instance so reasonable defaults will be provided.
+For some cloud providers, the installer is able to gather metadata exposed in
+the instance, so reasonable defaults will be provided.
-Plese confirm that they are correct before moving forward.
+Please confirm that they are correct before moving forward.
"""
notes = """
@@ -377,7 +384,7 @@ Notes:
* The public IP should be the externally accessible IP associated with the instance
* The hostname should resolve to the internal IP from the instances
themselves.
- * The public hostname should resolve to the external ip from hosts outside of
+ * The public hostname should resolve to the external IP from hosts outside of
the cloud.
"""
@@ -425,42 +432,41 @@ Edit %s with the desired values and run `atomic-openshift-installer --unattended
return default_facts
-
def check_hosts_config(oo_cfg, unattended):
click.clear()
masters = [host for host in oo_cfg.deployment.hosts if host.is_master()]
if len(masters) == 2:
- click.echo("A minimum of 3 Masters are required for HA deployments.")
+ click.echo("A minimum of 3 masters are required for HA deployments.")
sys.exit(1)
if len(masters) > 1:
master_lb = [host for host in oo_cfg.deployment.hosts if host.is_master_lb()]
if len(master_lb) > 1:
- click.echo('ERROR: More than one Master load balancer specified. Only one is allowed.')
+ click.echo('ERROR: More than one master load balancer specified. Only one is allowed.')
sys.exit(1)
elif len(master_lb) == 1:
if master_lb[0].is_master() or master_lb[0].is_node():
- click.echo('ERROR: The Master load balancer is configured as a master or node. ' \
+ click.echo('ERROR: The master load balancer is configured as a master or node. '
'Please correct this.')
sys.exit(1)
else:
message = """
ERROR: No master load balancer specified in config. You must provide the FQDN
-of a load balancer to balance the API (port 8443) on all Master hosts.
+of a load balancer to balance the API (port 8443) on all master hosts.
https://docs.openshift.org/latest/install_config/install/advanced_install.html#multiple-masters
"""
click.echo(message)
sys.exit(1)
- dedicated_nodes = [host for host in oo_cfg.deployment.hosts \
- if host.is_node() and not host.is_master()]
+ dedicated_nodes = [host for host in oo_cfg.deployment.hosts
+ if host.is_node() and not host.is_master()]
if len(dedicated_nodes) == 0:
message = """
-WARNING: No dedicated Nodes specified. By default, colocated Masters have
-their Nodes set to unschedulable. If you proceed all nodes will be labelled
+WARNING: No dedicated nodes specified. By default, colocated masters have
+their nodes set to unschedulable. If you proceed all nodes will be labelled
as schedulable.
"""
if unattended:
@@ -470,6 +476,7 @@ as schedulable.
return
+
def get_variant_and_version(multi_master=False):
message = "\nWhich variant would you like to install?\n\n"
@@ -477,7 +484,7 @@ def get_variant_and_version(multi_master=False):
combos = get_variant_version_combos()
for (variant, version) in combos:
message = "%s\n(%s) %s %s" % (message, i, variant.description,
- version.name)
+ version.name)
i = i + 1
message = "%s\n" % message
@@ -489,12 +496,14 @@ def get_variant_and_version(multi_master=False):
return product, version
+
def confirm_continue(message):
if message:
click.echo(message)
click.confirm("Are you ready to continue?", default=False, abort=True)
return
+
def error_if_missing_info(oo_cfg):
missing_info = False
if not oo_cfg.deployment.hosts:
@@ -534,6 +543,7 @@ def error_if_missing_info(oo_cfg):
if missing_info:
sys.exit(1)
+
def get_host_roles_set(oo_cfg):
roles_set = set()
for host in oo_cfg.deployment.hosts:
@@ -542,13 +552,17 @@ def get_host_roles_set(oo_cfg):
return roles_set
+
def get_proxy_hostnames_and_excludes():
message = """
-If a proxy is needed to reach HTTP and HTTPS traffic please enter the name below.
-This proxy will be configured by default for all processes needing to reach systems outside
-the cluster.
+If a proxy is needed to reach HTTP and HTTPS traffic, please enter the
+name below. This proxy will be configured by default for all processes
+that need to reach systems outside the cluster. An example proxy value
+would be:
+
+ http://proxy.example.com:8080/
-More advanced configuration is possible if using ansible directly:
+More advanced configuration is possible if using Ansible directly:
https://docs.openshift.com/enterprise/latest/install_config/http_proxies.html
"""
@@ -557,12 +571,14 @@ https://docs.openshift.com/enterprise/latest/install_config/http_proxies.html
message = "Specify your http proxy ? (ENTER for none)"
http_proxy_hostname = click.prompt(message, default='')
+ # TODO: Fix this prompt message and behavior. 'ENTER' will default
+ # to the http_proxy_hostname if one was provided
message = "Specify your https proxy ? (ENTER for none)"
https_proxy_hostname = click.prompt(message, default=http_proxy_hostname)
if http_proxy_hostname or https_proxy_hostname:
message = """
-All hosts in your openshift inventory will automatically be added to the NO_PROXY value.
+All hosts in your OpenShift inventory will automatically be added to the NO_PROXY value.
Please provide any additional hosts to be added to NO_PROXY. (ENTER for none)
"""
proxy_excludes = click.prompt(message, default='')
@@ -571,6 +587,7 @@ Please provide any additional hosts to be added to NO_PROXY. (ENTER for none)
return http_proxy_hostname, https_proxy_hostname, proxy_excludes
+
def get_missing_info_from_user(oo_cfg):
""" Prompts the user for any information missing from the given configuration. """
click.clear()
@@ -586,10 +603,10 @@ Please confirm that following prerequisites have been met:
repositories.
* All systems have run docker-storage-setup (part of the Red Hat docker RPM).
* All systems have working DNS that resolves not only from the perspective of
- the installer but also from within the cluster.
+ the installer, but also from within the cluster.
-When the process completes you will have a default configuration for Masters
-and Nodes. For ongoing environment maintenance it's recommended that the
+When the process completes you will have a default configuration for masters
+and nodes. For ongoing environment maintenance it's recommended that the
official Ansible playbooks be used.
For more information on installation prerequisites please see:
@@ -598,15 +615,15 @@ https://docs.openshift.com/enterprise/latest/admin_guide/install/prerequisites.h
confirm_continue(message)
click.clear()
- if not oo_cfg.settings.get('ansible_ssh_user', ''):
- oo_cfg.deployment.variables['ansible_ssh_user'] = \
- get_ansible_ssh_user()
+ if not oo_cfg.deployment.variables.get('ansible_ssh_user', False):
+ oo_cfg.deployment.variables['ansible_ssh_user'] = get_ansible_ssh_user()
click.clear()
if not oo_cfg.settings.get('variant', ''):
variant, version = get_variant_and_version()
oo_cfg.settings['variant'] = variant.name
oo_cfg.settings['variant_version'] = version.name
+ oo_cfg.settings['variant_subtype'] = version.subtype
click.clear()
if not oo_cfg.deployment.hosts:
@@ -617,13 +634,27 @@ https://docs.openshift.com/enterprise/latest/admin_guide/install/prerequisites.h
oo_cfg.deployment.roles[role] = Role(name=role, variables={})
click.clear()
- if not 'master_routingconfig_subdomain' in oo_cfg.deployment.variables:
- oo_cfg.deployment.variables['master_routingconfig_subdomain'] = \
- get_master_routingconfig_subdomain()
+ if 'master_routingconfig_subdomain' not in oo_cfg.deployment.variables:
+ oo_cfg.deployment.variables['master_routingconfig_subdomain'] = get_master_routingconfig_subdomain()
click.clear()
- if not oo_cfg.settings.get('openshift_http_proxy', None) and \
- LooseVersion(oo_cfg.settings.get('variant_version', '0.0')) >= LooseVersion('3.2'):
+ # Are any proxy vars already presisted?
+ proxy_vars = ['proxy_exclude_hosts', 'proxy_https', 'proxy_http']
+ # Empty list if NO proxy vars were presisted
+ saved_proxy_vars = [pv for pv in proxy_vars
+ if oo_cfg.deployment.variables.get(pv, 'UNSET') is not 'UNSET']
+
+ installer_log.debug("Evaluated proxy settings, found %s presisted values",
+ len(saved_proxy_vars))
+ current_version = parse_version(
+ oo_cfg.settings.get('variant_version', '0.0'))
+ min_version = parse_version('3.2')
+
+ # No proxy vars were saved and we are running a version which
+ # recognizes proxy parameters. We must prompt the user for values
+ # if this conditional is true.
+ if not saved_proxy_vars and current_version >= min_version:
+ installer_log.debug("Prompting user to enter proxy values")
http_proxy, https_proxy, proxy_excludes = get_proxy_hostnames_and_excludes()
oo_cfg.deployment.variables['proxy_http'] = http_proxy
oo_cfg.deployment.variables['proxy_https'] = https_proxy
@@ -641,10 +672,12 @@ def get_role_variable(oo_cfg, role_name, variable_name):
except (StopIteration, KeyError):
return None
+
def set_role_variable(oo_cfg, role_name, variable_name, variable_value):
target_role = next(role for role in oo_cfg.deployment.roles if role.name is role_name)
target_role[variable_name] = variable_value
+
def collect_new_nodes(oo_cfg):
click.clear()
click.echo('*** New Node Configuration ***')
@@ -655,32 +688,27 @@ Add new nodes here
new_nodes, _ = collect_hosts(oo_cfg, existing_env=True, masters_set=True, print_summary=False)
return new_nodes
+
def get_installed_hosts(hosts, callback_facts):
installed_hosts = []
-
- # count nativeha lb as an installed host
- try:
- first_master = next(host for host in hosts if host.is_master())
- lb_hostname = callback_facts[first_master.connect_to]['master'].get('cluster_hostname', '')
- lb_host = \
- next(host for host in hosts if host.ip == callback_facts[lb_hostname]['common']['ip'])
-
- installed_hosts.append(lb_host)
- except (KeyError, StopIteration):
- pass
-
+ uninstalled_hosts = []
for host in [h for h in hosts if h.is_master() or h.is_node()]:
- if host.connect_to in callback_facts.keys() and is_installed_host(host, callback_facts):
- installed_hosts.append(host)
- return installed_hosts
+ if host.connect_to in callback_facts.keys():
+ if is_installed_host(host, callback_facts):
+ installed_hosts.append(host)
+ else:
+ uninstalled_hosts.append(host)
+ return installed_hosts, uninstalled_hosts
+
def is_installed_host(host, callback_facts):
version_found = 'common' in callback_facts[host.connect_to].keys() and \
- callback_facts[host.connect_to]['common'].get('version', '') and \
- callback_facts[host.connect_to]['common'].get('version', '') != 'None'
+ callback_facts[host.connect_to]['common'].get('version', '') and \
+ callback_facts[host.connect_to]['common'].get('version', '') != 'None'
return version_found
+
# pylint: disable=too-many-branches
# This pylint error will be corrected shortly in separate PR.
def get_hosts_to_run_on(oo_cfg, callback_facts, unattended, force, verbose):
@@ -689,16 +717,16 @@ def get_hosts_to_run_on(oo_cfg, callback_facts, unattended, force, verbose):
hosts_to_run_on = list(oo_cfg.deployment.hosts)
# Check if master or nodes already have something installed
- installed_hosts = get_installed_hosts(oo_cfg.deployment.hosts, callback_facts)
+ installed_hosts, uninstalled_hosts = get_installed_hosts(oo_cfg.deployment.hosts, callback_facts)
if len(installed_hosts) > 0:
click.echo('Installed environment detected.')
# This check has to happen before we start removing hosts later in this method
if not force:
if not unattended:
- click.echo('By default the installer only adds new nodes ' \
+ click.echo('By default the installer only adds new nodes '
'to an installed environment.')
- response = click.prompt('Do you want to (1) only add additional nodes or ' \
- '(2) reinstall the existing hosts ' \
+ response = click.prompt('Do you want to (1) only add additional nodes or '
+ '(2) reinstall the existing hosts '
'potentially erasing any custom changes?',
type=int)
# TODO: this should be reworked with error handling.
@@ -712,29 +740,31 @@ def get_hosts_to_run_on(oo_cfg, callback_facts, unattended, force, verbose):
# present a message listing already installed hosts and remove hosts if needed
for host in installed_hosts:
if host.is_master():
- click.echo("{} is already an OpenShift Master".format(host))
+ click.echo("{} is already an OpenShift master".format(host))
# Masters stay in the list, we need to run against them when adding
# new nodes.
elif host.is_node():
- click.echo("{} is already an OpenShift Node".format(host))
+ click.echo("{} is already an OpenShift node".format(host))
# force is only used for reinstalls so we don't want to remove
# anything.
if not force:
hosts_to_run_on.remove(host)
# Handle the cases where we know about uninstalled systems
- new_hosts = set(hosts_to_run_on) - set(installed_hosts)
- if len(new_hosts) > 0:
- for new_host in new_hosts:
- click.echo("{} is currently uninstalled".format(new_host))
-
+ if len(uninstalled_hosts) > 0:
+ for uninstalled_host in uninstalled_hosts:
+ click.echo("{} is currently uninstalled".format(uninstalled_host))
# Fall through
- click.echo('Adding additional nodes...')
+ click.echo('\nUninstalled hosts have been detected in your environment. '
+ 'Please make sure your environment was installed successfully '
+ 'before adding new nodes. If you want a fresh install, use '
+ '`atomic-openshift-installer install --force`')
+ sys.exit(1)
else:
if unattended:
if not force:
- click.echo('Installed environment detected and no additional ' \
- 'nodes specified: aborting. If you want a fresh install, use ' \
+ click.echo('Installed environment detected and no additional '
+ 'nodes specified: aborting. If you want a fresh install, use '
'`atomic-openshift-installer install --force`')
sys.exit(1)
else:
@@ -748,14 +778,15 @@ def get_hosts_to_run_on(oo_cfg, callback_facts, unattended, force, verbose):
click.echo('Gathering information from hosts...')
callback_facts, error = openshift_ansible.default_facts(oo_cfg.deployment.hosts, verbose)
if error or callback_facts is None:
- click.echo("There was a problem fetching the required information. See " \
+ click.echo("There was a problem fetching the required information. See "
"{} for details.".format(oo_cfg.settings['ansible_log_path']))
sys.exit(1)
else:
- pass # proceeding as normal should do a clean install
+ pass # proceeding as normal should do a clean install
return hosts_to_run_on, callback_facts
+
def set_infra_nodes(hosts):
if all(host.is_master() for host in hosts):
infra_list = hosts
@@ -771,11 +802,11 @@ def set_infra_nodes(hosts):
@click.pass_context
@click.option('--unattended', '-u', is_flag=True, default=False)
@click.option('--configuration', '-c',
- type=click.Path(file_okay=True,
- dir_okay=False,
- writable=True,
- readable=True),
- default=None)
+ type=click.Path(file_okay=True,
+ dir_okay=False,
+ writable=True,
+ readable=True),
+ default=None)
@click.option('--ansible-playbook-directory',
'-a',
type=click.Path(exists=True,
@@ -786,24 +817,27 @@ def set_infra_nodes(hosts):
default=DEFAULT_PLAYBOOK_DIR,
envvar='OO_ANSIBLE_PLAYBOOK_DIRECTORY')
@click.option('--ansible-config',
- type=click.Path(file_okay=True,
- dir_okay=False,
- writable=True,
- readable=True),
- default=None)
+ type=click.Path(file_okay=True,
+ dir_okay=False,
+ writable=True,
+ readable=True),
+ default=None)
@click.option('--ansible-log-path',
- type=click.Path(file_okay=True,
- dir_okay=False,
- writable=True,
- readable=True),
- default="/tmp/ansible.log")
+ type=click.Path(file_okay=True,
+ dir_okay=False,
+ writable=True,
+ readable=True),
+ default="/tmp/ansible.log")
@click.option('-v', '--verbose',
- is_flag=True, default=False)
+ is_flag=True, default=False)
+@click.option('-d', '--debug',
+ help="Enable installer debugging (/tmp/installer.log)",
+ is_flag=True, default=False)
@click.help_option('--help', '-h')
-#pylint: disable=too-many-arguments
-#pylint: disable=line-too-long
+# pylint: disable=too-many-arguments
+# pylint: disable=line-too-long
# Main CLI entrypoint, not much we can do about too many arguments.
-def cli(ctx, unattended, configuration, ansible_playbook_directory, ansible_config, ansible_log_path, verbose):
+def cli(ctx, unattended, configuration, ansible_playbook_directory, ansible_config, ansible_log_path, verbose, debug):
"""
atomic-openshift-installer makes the process for installing OSE or AEP
easier by interactively gathering the data needed to run on each host.
@@ -811,6 +845,14 @@ def cli(ctx, unattended, configuration, ansible_playbook_directory, ansible_conf
Further reading: https://docs.openshift.com/enterprise/latest/install_config/install/quick_install.html
"""
+ if debug:
+ # DEFAULT log level threshold is set to CRITICAL (the
+ # highest), anything below that (we only use debug/warning
+ # presently) is not logged. If '-d' is given though, we'll
+ # lower the threshold to debug (almost everything gets through)
+ installer_log.setLevel(logging.DEBUG)
+ installer_log.debug("Quick Installer debugging initialized")
+
ctx.obj = {}
ctx.obj['unattended'] = unattended
ctx.obj['configuration'] = configuration
@@ -838,7 +880,7 @@ def cli(ctx, unattended, configuration, ansible_playbook_directory, ansible_conf
if ctx.obj['ansible_config']:
oo_cfg.settings['ansible_config'] = ctx.obj['ansible_config']
elif 'ansible_config' not in oo_cfg.settings and \
- os.path.exists(DEFAULT_ANSIBLE_CONFIG):
+ os.path.exists(DEFAULT_ANSIBLE_CONFIG):
# If we're installed by RPM this file should exist and we can use it as our default:
oo_cfg.settings['ansible_config'] = DEFAULT_ANSIBLE_CONFIG
@@ -867,7 +909,7 @@ def uninstall(ctx):
# Prompt interactively to confirm:
for host in hosts:
click.echo(" * %s" % host.connect_to)
- proceed = click.confirm("\nDo you wish to proceed?")
+ proceed = click.confirm("\nDo you want to proceed?")
if not proceed:
click.echo("Uninstall cancelled.")
sys.exit(0)
@@ -879,7 +921,7 @@ def uninstall(ctx):
@click.option('--latest-minor', '-l', is_flag=True, default=False)
@click.option('--next-major', '-n', is_flag=True, default=False)
@click.pass_context
-#pylint: disable=bad-builtin,too-many-statements
+# pylint: disable=too-many-statements
def upgrade(ctx, latest_minor, next_major):
oo_cfg = ctx.obj['oo_cfg']
@@ -922,33 +964,33 @@ def upgrade(ctx, latest_minor, next_major):
if next_major:
if 'major_playbook' not in mapping:
- click.echo("No major upgrade supported for %s %s with this version "\
+ click.echo("No major upgrade supported for %s %s with this version "
"of atomic-openshift-utils." % (variant, old_version))
sys.exit(0)
playbook = mapping['major_playbook']
new_version = mapping['major_version']
# Update config to reflect the version we're targetting, we'll write
- # to disk once ansible completes successfully, not before.
+ # to disk once Ansible completes successfully, not before.
oo_cfg.settings['variant_version'] = new_version
if oo_cfg.settings['variant'] == 'enterprise':
oo_cfg.settings['variant'] = 'openshift-enterprise'
if latest_minor:
if 'minor_playbook' not in mapping:
- click.echo("No minor upgrade supported for %s %s with this version "\
+ click.echo("No minor upgrade supported for %s %s with this version "
"of atomic-openshift-utils." % (variant, old_version))
sys.exit(0)
playbook = mapping['minor_playbook']
new_version = old_version
- click.echo("Openshift will be upgraded from %s %s to latest %s %s on the following hosts:\n" % (
+ click.echo("OpenShift will be upgraded from %s %s to latest %s %s on the following hosts:\n" % (
variant, old_version, oo_cfg.settings['variant'], new_version))
for host in oo_cfg.deployment.hosts:
click.echo(" * %s" % host.connect_to)
if not ctx.obj['unattended']:
# Prompt interactively to confirm:
- if not click.confirm("\nDo you wish to proceed?"):
+ if not click.confirm("\nDo you want to proceed?"):
click.echo("Upgrade cancelled.")
sys.exit(0)
@@ -957,7 +999,7 @@ def upgrade(ctx, latest_minor, next_major):
ctx.obj['verbose'])
if retcode > 0:
click.echo("Errors encountered during upgrade, please check %s." %
- oo_cfg.settings['ansible_log_path'])
+ oo_cfg.settings['ansible_log_path'])
else:
oo_cfg.save_to_disk()
click.echo("Upgrade completed! Rebooting all hosts is recommended.")
@@ -966,7 +1008,7 @@ def upgrade(ctx, latest_minor, next_major):
@click.command()
@click.option('--force', '-f', is_flag=True, default=False)
@click.option('--gen-inventory', is_flag=True, default=False,
- help="Generate an ansible inventory file and exit.")
+ help="Generate an Ansible inventory file and exit.")
@click.pass_context
def install(ctx, force, gen_inventory):
oo_cfg = ctx.obj['oo_cfg']
@@ -982,17 +1024,16 @@ def install(ctx, force, gen_inventory):
print_installation_summary(oo_cfg.deployment.hosts, oo_cfg.settings.get('variant_version', None))
click.echo('Gathering information from hosts...')
callback_facts, error = openshift_ansible.default_facts(oo_cfg.deployment.hosts,
- verbose)
+ verbose)
if error or callback_facts is None:
- click.echo("There was a problem fetching the required information. " \
+ click.echo("There was a problem fetching the required information. "
"Please see {} for details.".format(oo_cfg.settings['ansible_log_path']))
sys.exit(1)
hosts_to_run_on, callback_facts = get_hosts_to_run_on(
oo_cfg, callback_facts, ctx.obj['unattended'], force, verbose)
-
# We already verified this is not the case for unattended installs, so this can
# only trigger for live CLI users:
# TODO: if there are *new* nodes and this is a live install, we may need the user
@@ -1004,12 +1045,12 @@ def install(ctx, force, gen_inventory):
# Write quick installer config file to disk:
oo_cfg.save_to_disk()
- # Write ansible inventory file to disk:
+ # Write Ansible inventory file to disk:
inventory_file = openshift_ansible.generate_inventory(hosts_to_run_on)
click.echo()
click.echo('Wrote atomic-openshift-installer config: %s' % oo_cfg.config_path)
- click.echo("Wrote ansible inventory: %s" % inventory_file)
+ click.echo("Wrote Ansible inventory: %s" % inventory_file)
click.echo()
if gen_inventory:
@@ -1028,7 +1069,7 @@ If changes are needed please edit the config file above and re-run.
if error:
# The bootstrap script will print out the log location.
message = """
-An error was detected. After resolving the problem please relaunch the
+An error was detected. After resolving the problem please relaunch the
installation process.
"""
click.echo(message)
@@ -1038,7 +1079,7 @@ installation process.
The installation was successful!
If this is your first time installing please take a look at the Administrator
-Guide for advanced options related to routing, storage, authentication and much
+Guide for advanced options related to routing, storage, authentication, and
more:
http://docs.openshift.com/enterprise/latest/admin_guide/overview.html
diff --git a/utils/src/ooinstall/oo_config.py b/utils/src/ooinstall/oo_config.py
index 69ad2b4c5..393b36f6f 100644
--- a/utils/src/ooinstall/oo_config.py
+++ b/utils/src/ooinstall/oo_config.py
@@ -2,9 +2,13 @@
import os
import sys
+import logging
import yaml
from pkg_resources import resource_filename
+
+installer_log = logging.getLogger('installer')
+
CONFIG_PERSIST_SETTINGS = [
'ansible_ssh_user',
'ansible_callback_facts_yaml',
@@ -14,8 +18,9 @@ CONFIG_PERSIST_SETTINGS = [
'deployment',
'version',
'variant',
+ 'variant_subtype',
'variant_version',
- ]
+]
DEPLOYMENT_VARIABLES_BLACKLIST = [
'hosts',
@@ -25,6 +30,17 @@ DEPLOYMENT_VARIABLES_BLACKLIST = [
DEFAULT_REQUIRED_FACTS = ['ip', 'public_ip', 'hostname', 'public_hostname']
PRECONFIGURED_REQUIRED_FACTS = ['hostname', 'public_hostname']
+
+def print_read_config_error(error, path='the configuration file'):
+ message = """
+Error loading config. {}.
+
+See https://docs.openshift.com/enterprise/latest/install_config/install/quick_install.html#defining-an-installation-configuration-file
+for information on creating a configuration file or delete {} and re-run the installer.
+"""
+ print message.format(error, path)
+
+
class OOConfigFileError(Exception):
"""The provided config file path can't be read/written
"""
@@ -90,7 +106,6 @@ class Host(object):
def is_storage(self):
return 'storage' in self.roles
-
def is_etcd_member(self, all_hosts):
""" Will this host be a member of a standalone etcd cluster. """
if not self.is_master():
@@ -164,30 +179,54 @@ class OOConfig(object):
self._read_config()
self._set_defaults()
-
+ # pylint: disable=too-many-branches
+ # Lots of different checks ran in a single method, could
+ # use a little refactoring-love some time
def _read_config(self):
+ installer_log.debug("Attempting to read the OO Config")
try:
+ installer_log.debug("Attempting to see if the provided config file exists: %s", self.config_path)
if os.path.exists(self.config_path):
+ installer_log.debug("We think the config file exists: %s", self.config_path)
with open(self.config_path, 'r') as cfgfile:
loaded_config = yaml.safe_load(cfgfile.read())
- # Use the presence of a Description as an indicator this is
- # a legacy config file:
- if 'Description' in self.settings:
- self._upgrade_legacy_config()
+ if 'version' not in loaded_config:
+ print_read_config_error('Legacy configuration file found', self.config_path)
+ sys.exit(0)
+
+ if loaded_config.get('version', '') == 'v1':
+ loaded_config = self._upgrade_v1_config(loaded_config)
try:
host_list = loaded_config['deployment']['hosts']
role_list = loaded_config['deployment']['roles']
except KeyError as e:
- print "Error loading config, no such key: {}".format(e)
+ print_read_config_error("No such key: {}".format(e), self.config_path)
+ print "Error loading config, required key missing: {}".format(e)
sys.exit(0)
for setting in CONFIG_PERSIST_SETTINGS:
- try:
- self.settings[setting] = str(loaded_config[setting])
- except KeyError:
- continue
+ persisted_value = loaded_config.get(setting)
+ if persisted_value is not None:
+ self.settings[setting] = str(persisted_value)
+
+ # We've loaded any persisted configs, let's verify any
+ # paths which are required for a correct and complete
+ # install
+
+ # - ansible_callback_facts_yaml - Settings from a
+ # pervious run. If the file doesn't exist then we
+ # will just warn about it for now and recollect the
+ # facts.
+ if self.settings.get('ansible_callback_facts_yaml', None) is not None:
+ if not os.path.exists(self.settings['ansible_callback_facts_yaml']):
+ # Cached callback facts file does not exist
+ installer_log.warning("The specified 'ansible_callback_facts_yaml'"
+ "file does not exist (%s)",
+ self.settings['ansible_callback_facts_yaml'])
+ installer_log.debug("Remote system facts will be collected again later")
+ self.settings.pop('ansible_callback_facts_yaml')
for setting in loaded_config['deployment']:
try:
@@ -205,47 +244,67 @@ class OOConfig(object):
for name, variables in role_list.iteritems():
self.deployment.roles.update({name: Role(name, variables)})
-
except IOError, ferr:
raise OOConfigFileError('Cannot open config file "{}": {}'.format(ferr.filename,
ferr.strerror))
except yaml.scanner.ScannerError:
raise OOConfigFileError(
'Config file "{}" is not a valid YAML document'.format(self.config_path))
+ installer_log.debug("Parsed the config file")
+
+ def _upgrade_v1_config(self, config):
+ new_config_data = {}
+ new_config_data['deployment'] = {}
+ new_config_data['deployment']['hosts'] = []
+ new_config_data['deployment']['roles'] = {}
+ new_config_data['deployment']['variables'] = {}
- def _upgrade_legacy_config(self):
- new_hosts = []
- remove_settings = ['validated_facts', 'Description', 'Name',
- 'Subscription', 'Vendor', 'Version', 'masters', 'nodes']
-
- 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']:
- value['node'] = True
- new_hosts.append(value)
- self.settings['hosts'] = new_hosts
-
- for s in remove_settings:
- if s in self.settings:
- del self.settings[s]
-
- # A legacy config implies openshift-enterprise 3.0:
- self.settings['variant'] = 'openshift-enterprise'
- self.settings['variant_version'] = '3.0'
-
- def _upgrade_v1_config(self):
- #TODO write code to upgrade old config
- return
+ role_list = {}
+
+ if config.get('ansible_ssh_user', False):
+ new_config_data['deployment']['ansible_ssh_user'] = config['ansible_ssh_user']
+
+ if config.get('variant', False):
+ new_config_data['variant'] = config['variant']
+
+ if config.get('variant_version', False):
+ new_config_data['variant_version'] = config['variant_version']
+
+ for host in config['hosts']:
+ host_props = {}
+ host_props['roles'] = []
+ host_props['connect_to'] = host['connect_to']
+
+ for prop in ['ip', 'public_ip', 'hostname', 'public_hostname', 'containerized', 'preconfigured']:
+ host_props[prop] = host.get(prop, None)
+
+ for role in ['master', 'node', 'master_lb', 'storage', 'etcd']:
+ if host.get(role, False):
+ host_props['roles'].append(role)
+ role_list[role] = ''
+
+ new_config_data['deployment']['hosts'].append(host_props)
+
+ new_config_data['deployment']['roles'] = role_list
+
+ return new_config_data
def _set_defaults(self):
+ installer_log.debug("Setting defaults, current OOConfig settings: %s", self.settings)
if 'ansible_inventory_directory' not in self.settings:
self.settings['ansible_inventory_directory'] = self._default_ansible_inv_dir()
+
if not os.path.exists(self.settings['ansible_inventory_directory']):
+ installer_log.debug("'ansible_inventory_directory' does not exist, "
+ "creating it now (%s)",
+ self.settings['ansible_inventory_directory'])
os.makedirs(self.settings['ansible_inventory_directory'])
+ else:
+ installer_log.debug("We think this 'ansible_inventory_directory' "
+ "is OK: %s",
+ self.settings['ansible_inventory_directory'])
+
if 'ansible_plugins_directory' not in self.settings:
self.settings['ansible_plugins_directory'] = \
resource_filename(__name__, 'ansible_plugins')
@@ -253,8 +312,14 @@ class OOConfig(object):
self.settings['version'] = 'v2'
if 'ansible_callback_facts_yaml' not in self.settings:
+ installer_log.debug("No 'ansible_callback_facts_yaml' in self.settings")
self.settings['ansible_callback_facts_yaml'] = '%s/callback_facts.yaml' % \
self.settings['ansible_inventory_directory']
+ installer_log.debug("Value: %s", self.settings['ansible_callback_facts_yaml'])
+ else:
+ installer_log.debug("'ansible_callback_facts_yaml' already set "
+ "in self.settings: %s",
+ self.settings['ansible_callback_facts_yaml'])
if 'ansible_ssh_user' not in self.settings:
self.settings['ansible_ssh_user'] = ''
@@ -262,11 +327,17 @@ class OOConfig(object):
self.settings['ansible_inventory_path'] = \
'{}/hosts'.format(os.path.dirname(self.config_path))
+ # pylint: disable=consider-iterating-dictionary
+ # Disabled because we shouldn't alter the container we're
+ # iterating over
+ #
# clean up any empty sets
for setting in self.settings.keys():
if not self.settings[setting]:
self.settings.pop(setting)
+ installer_log.debug("Updated OOConfig settings: %s", self.settings)
+
def _default_ansible_inv_dir(self):
return os.path.normpath(
os.path.dirname(self.config_path) + "/.ansible")
@@ -329,7 +400,6 @@ class OOConfig(object):
print "Error persisting settings: {}".format(e)
sys.exit(0)
-
return p_settings
def yaml(self):
diff --git a/utils/src/ooinstall/openshift_ansible.py b/utils/src/ooinstall/openshift_ansible.py
index ef7906828..75d26c10a 100644
--- a/utils/src/ooinstall/openshift_ansible.py
+++ b/utils/src/ooinstall/openshift_ansible.py
@@ -4,9 +4,12 @@ import socket
import subprocess
import sys
import os
+import logging
import yaml
from ooinstall.variants import find_variant
+installer_log = logging.getLogger('installer')
+
CFG = None
ROLES_TO_GROUPS_MAP = {
@@ -20,16 +23,19 @@ ROLES_TO_GROUPS_MAP = {
VARIABLES_MAP = {
'ansible_ssh_user': 'ansible_ssh_user',
'deployment_type': 'deployment_type',
- 'master_routingconfig_subdomain':'openshift_master_default_subdomain',
- 'proxy_http':'openshift_http_proxy',
+ 'variant_subtype': 'deployment_subtype',
+ 'master_routingconfig_subdomain': 'openshift_master_default_subdomain',
+ 'proxy_http': 'openshift_http_proxy',
'proxy_https': 'openshift_https_proxy',
'proxy_exclude_hosts': 'openshift_no_proxy',
}
+
def set_config(cfg):
global CFG
CFG = cfg
+
def generate_inventory(hosts):
global CFG
@@ -48,8 +54,7 @@ def generate_inventory(hosts):
write_inventory_vars(base_inventory, multiple_masters, lb)
-
- #write_inventory_hosts
+ # write_inventory_hosts
for role in CFG.deployment.roles:
# write group block
group = ROLES_TO_GROUPS_MAP.get(role, role)
@@ -68,15 +73,17 @@ def generate_inventory(hosts):
base_inventory.close()
return base_inventory_path
+
def determine_lb_configuration(hosts):
lb = next((host for host in hosts if host.is_master_lb()), None)
if lb:
- if lb.hostname == None:
+ if lb.hostname is None:
lb.hostname = lb.connect_to
lb.public_hostname = lb.connect_to
return lb
+
def write_inventory_children(base_inventory, scaleup):
global CFG
@@ -114,28 +121,30 @@ def write_inventory_vars(base_inventory, multiple_masters, lb):
"openshift_master_cluster_public_hostname={}\n".format(lb.public_hostname))
if CFG.settings.get('variant_version', None) == '3.1':
- #base_inventory.write('openshift_image_tag=v{}\n'.format(CFG.settings.get('variant_version')))
+ # base_inventory.write('openshift_image_tag=v{}\n'.format(CFG.settings.get('variant_version')))
base_inventory.write('openshift_image_tag=v{}\n'.format('3.1.1.6'))
write_proxy_settings(base_inventory)
# Find the correct deployment type for ansible:
ver = find_variant(CFG.settings['variant'],
- version=CFG.settings.get('variant_version', None))[1]
+ version=CFG.settings.get('variant_version', None))[1]
base_inventory.write('deployment_type={}\n'.format(ver.ansible_key))
+ if getattr(ver, 'variant_subtype', False):
+ base_inventory.write('deployment_subtype={}\n'.format(ver.deployment_subtype))
if 'OO_INSTALL_ADDITIONAL_REGISTRIES' in os.environ:
- base_inventory.write('openshift_docker_additional_registries={}\n'
- .format(os.environ['OO_INSTALL_ADDITIONAL_REGISTRIES']))
+ base_inventory.write('openshift_docker_additional_registries={}\n'.format(
+ os.environ['OO_INSTALL_ADDITIONAL_REGISTRIES']))
if 'OO_INSTALL_INSECURE_REGISTRIES' in os.environ:
- base_inventory.write('openshift_docker_insecure_registries={}\n'
- .format(os.environ['OO_INSTALL_INSECURE_REGISTRIES']))
+ base_inventory.write('openshift_docker_insecure_registries={}\n'.format(
+ os.environ['OO_INSTALL_INSECURE_REGISTRIES']))
if 'OO_INSTALL_PUDDLE_REPO' in os.environ:
# We have to double the '{' here for literals
base_inventory.write("openshift_additional_repos=[{{'id': 'ose-devel', "
- "'name': 'ose-devel', "
- "'baseurl': '{}', "
- "'enabled': 1, 'gpgcheck': 0}}]\n".format(os.environ['OO_INSTALL_PUDDLE_REPO']))
+ "'name': 'ose-devel', "
+ "'baseurl': '{}', "
+ "'enabled': 1, 'gpgcheck': 0}}]\n".format(os.environ['OO_INSTALL_PUDDLE_REPO']))
for name, role_obj in CFG.deployment.roles.iteritems():
if role_obj.variables:
@@ -151,17 +160,17 @@ def write_inventory_vars(base_inventory, multiple_masters, lb):
def write_proxy_settings(base_inventory):
try:
base_inventory.write("openshift_http_proxy={}\n".format(
- CFG.settings['openshift_http_proxy']))
+ CFG.settings['openshift_http_proxy']))
except KeyError:
pass
try:
base_inventory.write("openshift_https_proxy={}\n".format(
- CFG.settings['openshift_https_proxy']))
+ CFG.settings['openshift_https_proxy']))
except KeyError:
pass
try:
base_inventory.write("openshift_no_proxy={}\n".format(
- CFG.settings['openshift_no_proxy']))
+ CFG.settings['openshift_no_proxy']))
except KeyError:
pass
@@ -191,7 +200,6 @@ def write_host(host, role, inventory, schedulable=None):
if role == 'node':
facts += ' openshift_node_labels="{}"'.format(host.node_labels)
-
# Distinguish between three states, no schedulability specified (use default),
# explicitly set to True, or explicitly set to False:
if role != 'node' or schedulable is None:
@@ -216,17 +224,21 @@ def load_system_facts(inventory_file, os_facts_path, env_vars, verbose=False):
"""
Retrieves system facts from the remote systems.
"""
+ installer_log.debug("Inside load_system_facts")
FNULL = open(os.devnull, 'w')
args = ['ansible-playbook', '-v'] if verbose \
else ['ansible-playbook']
args.extend([
'--inventory-file={}'.format(inventory_file),
os_facts_path])
+ installer_log.debug("Going to subprocess out to ansible now with these args: %s", ' '.join(args))
status = subprocess.call(args, env=env_vars, stdout=FNULL)
- if not status == 0:
+ if status != 0:
+ installer_log.debug("Exit status from subprocess was not 0")
return [], 1
with open(CFG.settings['ansible_callback_facts_yaml'], 'r') as callback_facts_file:
+ installer_log.debug("Going to try to read this file: %s", CFG.settings['ansible_callback_facts_yaml'])
try:
callback_facts = yaml.safe_load(callback_facts_file)
except yaml.YAMLError, exc:
@@ -239,6 +251,7 @@ def load_system_facts(inventory_file, os_facts_path, env_vars, verbose=False):
def default_facts(hosts, verbose=False):
global CFG
+ installer_log.debug("Current global CFG vars here: %s", CFG)
inventory_file = generate_inventory(hosts)
os_facts_path = '{}/playbooks/byo/openshift_facts.yml'.format(CFG.ansible_playbook_directory)
@@ -250,6 +263,9 @@ def default_facts(hosts, verbose=False):
facts_env["ANSIBLE_LOG_PATH"] = CFG.settings['ansible_log_path']
if 'ansible_config' in CFG.settings:
facts_env['ANSIBLE_CONFIG'] = CFG.settings['ansible_config']
+
+ installer_log.debug("facts_env: %s", facts_env)
+ installer_log.debug("Going to 'load_system_facts' next")
return load_system_facts(inventory_file, os_facts_path, facts_env, verbose)
@@ -280,7 +296,7 @@ def run_ansible(playbook, inventory, env_vars, verbose=False):
def run_uninstall_playbook(hosts, verbose=False):
playbook = os.path.join(CFG.settings['ansible_playbook_directory'],
- 'playbooks/adhoc/uninstall.yml')
+ 'playbooks/adhoc/uninstall.yml')
inventory_file = generate_inventory(hosts)
facts_env = os.environ.copy()
if 'ansible_log_path' in CFG.settings:
@@ -292,7 +308,7 @@ def run_uninstall_playbook(hosts, verbose=False):
def run_upgrade_playbook(hosts, playbook, verbose=False):
playbook = os.path.join(CFG.settings['ansible_playbook_directory'],
- 'playbooks/byo/openshift-cluster/upgrades/{}'.format(playbook))
+ 'playbooks/byo/openshift-cluster/upgrades/{}'.format(playbook))
# TODO: Upgrade inventory for upgrade?
inventory_file = generate_inventory(hosts)
diff --git a/utils/src/ooinstall/variants.py b/utils/src/ooinstall/variants.py
index 1706b4165..6993794fe 100644
--- a/utils/src/ooinstall/variants.py
+++ b/utils/src/ooinstall/variants.py
@@ -11,12 +11,16 @@ to be specified by the user, and to point the generic variants to the latest
version.
"""
+import logging
+installer_log = logging.getLogger('installer')
+
class Version(object):
- def __init__(self, name, ansible_key):
+ def __init__(self, name, ansible_key, subtype=''):
self.name = name # i.e. 3.0, 3.1
self.ansible_key = ansible_key
+ self.subtype = subtype
class Variant(object):
@@ -35,20 +39,35 @@ class Variant(object):
# WARNING: Keep the versions ordered, most recent first:
OSE = Variant('openshift-enterprise', 'OpenShift Container Platform',
- [
- Version('3.2', 'openshift-enterprise'),
- ]
+ [
+ Version('3.3', 'openshift-enterprise'),
+ ]
+)
+
+REG = Variant('openshift-enterprise', 'Registry',
+ [
+ Version('3.3', 'openshift-enterprise', 'registry'),
+ ]
)
origin = Variant('origin', 'OpenShift Origin',
- [
- Version('1.2', 'origin'),
- ]
+ [
+ Version('1.2', 'origin'),
+ ]
+)
+
+LEGACY = Variant('openshift-enterprise', 'OpenShift Container Platform',
+ [
+ Version('3.2', 'openshift-enterprise'),
+ Version('3.1', 'openshift-enterprise'),
+ Version('3.0', 'openshift-enterprise'),
+ ]
)
# Ordered list of variants we can install, first is the default.
-SUPPORTED_VARIANTS = (OSE, origin)
-DISPLAY_VARIANTS = (OSE, )
+SUPPORTED_VARIANTS = (OSE, REG, origin, LEGACY)
+DISPLAY_VARIANTS = (OSE, REG,)
+
def find_variant(name, version=None):
"""
@@ -67,6 +86,7 @@ def find_variant(name, version=None):
return (None, None)
+
def get_variant_version_combos():
combos = []
for variant in DISPLAY_VARIANTS: