Skip to content

Commit

Permalink
Move validate_hosts to prerequisites.yml
Browse files Browse the repository at this point in the history
Move more checks outside of init/main.yml for
speeding up upgrades and other operational plays that
need to run.
  • Loading branch information
michaelgugino committed Dec 20, 2017
1 parent 5faaf9c commit edde00a
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
roles:
- openshift_facts
tasks:
- set_fact:
repoquery_cmd: "{{ 'dnf repoquery --latest-limit 1 -d 0' if ansible_pkg_mgr == 'dnf' else 'repoquery --plugins' }}"

- fail:
msg: Cannot upgrade Docker on Atomic operating systems.
when: openshift_is_atomic | bool
Expand Down
25 changes: 0 additions & 25 deletions playbooks/init/facts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,6 @@
openshift_is_atomic: "{{ ostree_booted.stat.exists }}"
openshift_is_containerized: "{{ ostree_booted.stat.exists or (containerized | default(false) | bool) }}"

# TODO: Should this be moved into health checks??
# Seems as though any check that happens with a corresponding fail should move into health_checks
- name: Validate python version - ans_dist is fedora and python is v3
fail:
msg: |
openshift-ansible requires Python 3 for {{ ansible_distribution }};
For information on enabling Python 3 with Ansible, see https://docs.ansible.com/ansible/python_3_support.html
when:
- ansible_distribution == 'Fedora'
- ansible_python['version']['major'] != 3

# TODO: Should this be moved into health checks??
# Seems as though any check that happens with a corresponding fail should move into health_checks
- name: Validate python version - ans_dist not Fedora and python must be v2
fail:
msg: "openshift-ansible requires Python 2 for {{ ansible_distribution }}"
when:
- ansible_distribution != 'Fedora'
- ansible_python['version']['major'] != 2

# TODO: Should this be moved into health checks??
# Seems as though any check that happens with a corresponding fail should move into health_checks
# Fail as early as possible if Atomic and old version of Docker
Expand Down Expand Up @@ -136,11 +116,6 @@
local_facts:
sdn_mtu: "{{ openshift_node_sdn_mtu | default(None) }}"

- name: initialize_facts set_fact repoquery command
set_fact:
repoquery_cmd: "{{ 'dnf repoquery --latest-limit 1 -d 0' if ansible_pkg_mgr == 'dnf' else 'repoquery --plugins' }}"
repoquery_installed: "{{ 'dnf repoquery --latest-limit 1 -d 0 --disableexcludes=all --installed' if ansible_pkg_mgr == 'dnf' else 'repoquery --plugins --installed' }}"

- name: Initialize special first-master variables
hosts: oo_first_master
roles:
Expand Down
3 changes: 0 additions & 3 deletions playbooks/init/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
- import_playbook: sanity_checks.yml
when: not (skip_sanity_checks | default(False))

- import_playbook: validate_hostnames.yml
when: not (skip_validate_hostnames | default(False))

- import_playbook: version.yml
when: not (skip_verison | default(False))

Expand Down
3 changes: 3 additions & 0 deletions playbooks/prerequisites.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
vars:
skip_verison: True

- import_playbook: validate_hostnames.yml
when: not (skip_validate_hostnames | default(False))

- import_playbook: init/repos.yml

# This is required for container runtime for crio, only needs to run once.
Expand Down
2 changes: 0 additions & 2 deletions roles/container_runtime/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
docker_cli_auth_config_path: '/root/.docker'
openshift_docker_signature_verification: False

repoquery_cmd: "{{ 'dnf repoquery --latest-limit 1 -d 0' if ansible_pkg_mgr == 'dnf' else 'repoquery --plugins' }}"

openshift_docker_alternative_creds: False

# oreg_url is defined by user input.
Expand Down
16 changes: 15 additions & 1 deletion roles/lib_utils/action_plugins/sanity_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@ def template_var(self, hostvars, host, varname):
return None
return self._templar.template(res)

def check_python_version(self, hostvars, host, distro):
"""Ensure python version is 3 for Fedora and python 2 for others"""
ansible_python = self.template_var(hostvars, host, 'ansible_python')
if distro == "Fedora":
if ansible_python['version']['major'] != 3:
msg = "openshift-ansible requires Python 3 for {};".format(distro)
msg += " For information on enabling Python 3 with Ansible,"
msg += " see https://docs.ansible.com/ansible/python_3_support.html"
raise errors.AnsibleModuleError(msg)
else:
if ansible_python['version']['major'] != 2:
msg = "openshift-ansible requires Python 2 for {};".format(distro)

def network_plugin_check(self, hostvars, host):
"""Ensure only one type of network plugin is enabled"""
res = []
Expand Down Expand Up @@ -59,7 +72,8 @@ def check_hostname_vars(self, hostvars, host):

def run_checks(self, hostvars, host):
"""Execute the hostvars validations against host"""
# msg = hostvars[host]['ansible_default_ipv4']
distro = self.template_var(hostvars, host, 'ansible_distribution')
self.check_python_version(hostvars, host, distro)
self.network_plugin_check(hostvars, host)
self.check_hostname_vars(hostvars, host)

Expand Down
3 changes: 3 additions & 0 deletions roles/openshift_facts/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ openshift_cli_image_dict:
origin: 'openshift/origin'
openshift-enterprise: 'openshift3/ose'

repoquery_cmd: "{{ ansible_pkg_mgr == 'dnf' | ternary('dnf repoquery --latest-limit 1 -d 0', 'repoquery --plugins') }}"
repoquery_installed: "{{ ansible_pkg_mgr == 'dnf' | ternary('dnf repoquery --latest-limit 1 -d 0 --disableexcludes=all --installed', 'repoquery --plugins --installed') }}"

openshift_hosted_images_dict:
origin: 'openshift/origin-${component}:${version}'
openshift-enterprise: 'openshift3/ose-${component}:${version}'
Expand Down

0 comments on commit edde00a

Please sign in to comment.