Browse Source

validate and normalize inventory variables

In openshift_repos and everywhere, ensure deployment_type and
openshift_deployment_type are defined and the same.
We really want to set openshift_deployment_type, but users will likely
still have just deployment_type, so accept both. And don't make every
playbook default openshift_deployment_type to deployment_type.

This introduces the openshift_sanitize_inventory role to run before anything else.
Luke Meyer 8 years ago
parent
commit
f5827111a7

+ 1 - 1
inventory/byo/hosts.openstack

@@ -15,7 +15,7 @@ ansible_become=yes
 # Debug level for all OpenShift components (Defaults to 2)
 debug_level=2
 
-deployment_type=openshift-enterprise
+openshift_deployment_type=openshift-enterprise
 
 openshift_additional_repos=[{'id': 'ose-3.1', 'name': 'ose-3.1', 'baseurl': 'http://pulp.dist.prod.ext.phx2.redhat.com/content/dist/rhel/server/7/7Server/x86_64/ose/3.1/os', 'enabled': 1, 'gpgcheck': 0}]
 

+ 1 - 1
inventory/byo/hosts.origin.example

@@ -23,7 +23,7 @@ ansible_ssh_user=root
 debug_level=2
 
 # deployment type valid values are origin, online, atomic-enterprise and openshift-enterprise
-deployment_type=origin
+openshift_deployment_type=origin
 
 # Specify the generic release of OpenShift to install. This is used mainly just during installation, after which we
 # rely on the version running on the first master. Works best for containerized installs where we can usually

+ 1 - 1
inventory/byo/hosts.ose.example

@@ -23,7 +23,7 @@ ansible_ssh_user=root
 debug_level=2
 
 # deployment type valid values are origin, online, atomic-enterprise, and openshift-enterprise
-deployment_type=openshift-enterprise
+openshift_deployment_type=openshift-enterprise
 
 # Specify the generic release of OpenShift to install. This is used mainly just during installation, after which we
 # rely on the version running on the first master. Works best for containerized installs where we can usually

+ 0 - 1
playbooks/byo/openshift-cluster/config.yml

@@ -7,5 +7,4 @@
   vars:
     openshift_cluster_id: "{{ cluster_id | default('default') }}"
     openshift_debug_level: "{{ debug_level | default(2) }}"
-    openshift_deployment_type: "{{ deployment_type }}"
     openshift_deployment_subtype: "{{ deployment_subtype | default(none) }}"

+ 0 - 1
playbooks/byo/openshift-cluster/openshift-logging.yml

@@ -32,4 +32,3 @@
   vars:
     openshift_cluster_id: "{{ cluster_id | default('default') }}"
     openshift_debug_level: "{{ debug_level | default(2) }}"
-    openshift_deployment_type: "{{ deployment_type }}"

+ 0 - 1
playbooks/byo/openshift-cluster/upgrades/docker/upgrade.yml

@@ -30,7 +30,6 @@
     g_new_master_hosts: []
     g_new_node_hosts: []
     openshift_cluster_id: "{{ cluster_id | default('default') }}"
-    openshift_deployment_type: "{{ deployment_type }}"
 
 - include: ../../../../common/openshift-cluster/upgrades/initialize_nodes_to_upgrade.yml
 

+ 0 - 2
playbooks/byo/openshift-etcd/restart.yml

@@ -4,5 +4,3 @@
   - always
 
 - include: ../../common/openshift-etcd/restart.yml
-  vars:
-    openshift_deployment_type: "{{ deployment_type }}"

+ 0 - 2
playbooks/byo/openshift-master/restart.yml

@@ -4,5 +4,3 @@
   - always
 
 - include: ../../common/openshift-master/restart.yml
-  vars:
-    openshift_deployment_type: "{{ deployment_type }}"

+ 0 - 1
playbooks/byo/openshift-master/scaleup.yml

@@ -27,4 +27,3 @@
   vars:
     openshift_cluster_id: "{{ cluster_id | default('default') }}"
     openshift_debug_level: "{{ debug_level | default(2) }}"
-    openshift_deployment_type: "{{ deployment_type }}"

+ 0 - 2
playbooks/byo/openshift-node/restart.yml

@@ -4,5 +4,3 @@
   - always
 
 - include: ../../common/openshift-node/restart.yml
-  vars:
-    openshift_deployment_type: "{{ deployment_type }}"

+ 0 - 1
playbooks/byo/openshift-node/scaleup.yml

@@ -27,6 +27,5 @@
   vars:
     openshift_cluster_id: "{{ cluster_id | default('default') }}"
     openshift_debug_level: "{{ debug_level | default(2) }}"
-    openshift_deployment_type: "{{ deployment_type }}"
     openshift_master_etcd_hosts: "{{ groups.etcd | default([]) }}"
     openshift_master_etcd_port: 2379

+ 0 - 2
playbooks/byo/rhel_subscribe.yml

@@ -5,8 +5,6 @@
 
 - name: Subscribe hosts, update repos and update OS packages
   hosts: l_oo_all_hosts
-  vars:
-    openshift_deployment_type: "{{ deployment_type }}"
   roles:
   - role: rhel_subscribe
     when: deployment_type in ['atomic-enterprise', 'enterprise', 'openshift-enterprise'] and

+ 0 - 2
playbooks/common/openshift-cluster/enable_dnsmasq.yml

@@ -56,8 +56,6 @@
     - role: node
       local_facts:
         dns_ip: "{{ hostvars[inventory_hostname]['ansible_default_ipv4']['address'] }}"
-  vars:
-    openshift_deployment_type: "{{ deployment_type }}"
   roles:
   - openshift_node_dnsmasq
   post_tasks:

+ 0 - 2
playbooks/common/openshift-cluster/initialize_facts.yml

@@ -15,5 +15,3 @@
         hostname: "{{ openshift_hostname | default(None) }}"
   - set_fact:
       openshift_docker_hosted_registry_network: "{{ hostvars[groups.oo_first_master.0].openshift.common.portal_net }}"
-  - set_fact:
-      openshift_deployment_type: "{{ deployment_type }}"

+ 0 - 2
playbooks/common/openshift-cluster/std_include.yml

@@ -22,8 +22,6 @@
   - always
   tasks:
   - include_vars: ../../byo/openshift-cluster/cluster_hosts.yml
-  - set_fact:
-      openshift_deployment_type: "{{ deployment_type }}"
 
 - include: evaluate_groups.yml
   tags:

+ 0 - 2
playbooks/common/openshift-cluster/update_repos_and_packages.yml

@@ -3,8 +3,6 @@
 
 - name: Subscribe hosts, update repos and update OS packages
   hosts: oo_hosts_to_update
-  vars:
-    openshift_deployment_type: "{{ deployment_type }}"
   roles:
   # Explicitly calling openshift_facts because it appears that when
   # rhel_subscribe is skipped that the openshift_facts dependency for

+ 0 - 1
playbooks/common/openshift-cluster/upgrades/init.yml

@@ -29,7 +29,6 @@
     g_new_master_hosts: []
     g_new_node_hosts: []
     openshift_cluster_id: "{{ cluster_id | default('default') }}"
-    openshift_deployment_type: "{{ deployment_type }}"
 
 - name: Set oo_options
   hosts: oo_all_hosts

+ 0 - 1
playbooks/common/openshift-cluster/upgrades/post_control_plane.yml

@@ -5,7 +5,6 @@
 - name: Upgrade default router and default registry
   hosts: oo_first_master
   vars:
-    openshift_deployment_type: "{{ deployment_type }}"
     registry_image: "{{  openshift.master.registry_url | replace( '${component}', 'docker-registry' )  | replace ( '${version}', openshift_image_tag ) }}"
     router_image: "{{ openshift.master.registry_url | replace( '${component}', 'haproxy-router' ) | replace ( '${version}', openshift_image_tag ) }}"
     oc_cmd: "{{ openshift.common.client_binary }} --config={{ openshift.common.config_base }}/master/admin.kubeconfig"

+ 2 - 1
roles/openshift_facts/meta/main.yml

@@ -12,4 +12,5 @@ galaxy_info:
   categories:
   - cloud
   - system
-dependencies: []
+dependencies:
+- role: openshift_sanitize_inventory

+ 1 - 2
roles/openshift_facts/tasks/main.yml

@@ -64,8 +64,7 @@
     role: common
     local_facts:
       debug_level: "{{ openshift_debug_level | default(2) }}"
-      # TODO: Deprecate deployment_type in favor of openshift_deployment_type
-      deployment_type: "{{ openshift_deployment_type | default(deployment_type) }}"
+      deployment_type: "{{ openshift_deployment_type }}"
       deployment_subtype: "{{ openshift_deployment_subtype | default(None) }}"
       cluster_id: "{{ openshift_cluster_id | default('default') }}"
       hostname: "{{ openshift_hostname | default(None) }}"

+ 2 - 1
roles/openshift_repos/meta/main.yml

@@ -11,4 +11,5 @@ galaxy_info:
     - 7
   categories:
   - cloud
-dependencies: []
+dependencies:
+- role: openshift_sanitize_inventory

+ 0 - 4
roles/openshift_repos/tasks/main.yaml

@@ -4,10 +4,6 @@
     path: /run/ostree-booted
   register: ostree_booted
 
-- assert:
-    that: openshift_deployment_type in known_openshift_deployment_types
-    msg: "openshift_deployment_type must be one of {{ known_openshift_deployment_types }}"
-
 - block:
   - name: Ensure libselinux-python is installed
     package: name=libselinux-python state=present

+ 37 - 0
roles/openshift_sanitize_inventory/README.md

@@ -0,0 +1,37 @@
+OpenShift Inventory
+===================
+
+Provides a role to validate and normalize the variables the user has
+provided. This role should run before pretty much everything else so that
+this kind of logic only has to be in one place. However, complicated
+business logic should usually be left to other roles.
+
+Requirements
+------------
+
+None
+
+Role Variables
+--------------
+
+None
+
+Dependencies
+------------
+
+None
+
+Example Playbook
+----------------
+
+TODO
+
+License
+-------
+
+Apache License, Version 2.0
+
+Author Information
+------------------
+
+OpenShift dev (dev@lists.openshift.redhat.com)

+ 15 - 0
roles/openshift_sanitize_inventory/meta/main.yml

@@ -0,0 +1,15 @@
+---
+galaxy_info:
+  author: OpenShift dev
+  description:
+  company: Red Hat, Inc.
+  license: Apache License, Version 2.0
+  min_ansible_version: 1.8
+  platforms:
+  - name: EL
+    versions:
+    - 7
+  categories:
+  - cloud
+  - system
+dependencies: []

+ 28 - 0
roles/openshift_sanitize_inventory/tasks/main.yml

@@ -0,0 +1,28 @@
+---
+- name: Standardize on latest variable names
+  no_log: True  # keep task description legible
+  set_fact:
+    # goal is to deprecate deployment_type in favor of openshift_deployment_type.
+    # both will be accepted for now, but code should refer to the new name.
+    # TODO: once this is well-documented, add deprecation notice if using old name.
+    deployment_type: "{{ openshift_deployment_type | default(deployment_type) | default | string }}"
+    openshift_deployment_type: "{{ openshift_deployment_type | default(deployment_type) | default | string }}"
+
+- name: Normalize openshift_release
+  no_log: True  # keep task description legible
+  set_fact:
+    # Normalize release if provided, e.g. "v3.5" => "3.5"
+    # Currently this is not required to be defined for all installs, and the
+    # `openshift_version` role can generally figure out the specific version
+    # that gets installed (e.g. 3.5.0.1). So consider this the user's expressed
+    # intent (if any), not the authoritative version that will be installed.
+    openshift_release: "{{ openshift_release | string | regex_replace('^v', '') }}"
+  when: openshift_release is defined
+
+- name: Ensure a valid deployment type has been given.
+  # this variable is required; complain early and clearly if it is invalid.
+  when: openshift_deployment_type not in known_openshift_deployment_types
+  fail:
+    msg: |-
+      Please set openshift_deployment_type to one of:
+      {{ known_openshift_deployment_types | join(', ') }}

roles/openshift_repos/vars/main.yml → roles/openshift_sanitize_inventory/vars/main.yml


+ 0 - 8
roles/openshift_version/tasks/main.yml

@@ -13,14 +13,6 @@
 
 # Normalize some values that we need in a certain format that might be confusing:
 - set_fact:
-    openshift_release: "{{ openshift_release[1:] }}"
-  when: openshift_release is defined and openshift_release[0] == 'v'
-
-- set_fact:
-    openshift_release: "{{ openshift_release | string }}"
-  when: openshift_release is defined
-
-- set_fact:
     openshift_image_tag: "{{ 'v' + openshift_image_tag }}"
   when: openshift_image_tag is defined and openshift_image_tag[0] != 'v' and openshift_image_tag != 'latest'