From 689f985238845699654481d593fe72d31ccfcf64 Mon Sep 17 00:00:00 2001 From: liubo0127 Date: Fri, 5 Jul 2019 14:25:20 +0800 Subject: [PATCH] fix precheck --- roles/check_config_static/tasks/main.yml | 39 ++++++++++++++++++++++ roles/check_system_static/tasks/main.yml | 41 +----------------------- 2 files changed, 40 insertions(+), 40 deletions(-) diff --git a/roles/check_config_static/tasks/main.yml b/roles/check_config_static/tasks/main.yml index 8778ac8ff..407c408cf 100644 --- a/roles/check_config_static/tasks/main.yml +++ b/roles/check_config_static/tasks/main.yml @@ -37,3 +37,42 @@ ignore_errors: true changed_when: false failed_when: false + +- name: Check ansible version + fail: + msg: "Stop if ansible version is too low, make sure that the Ansible version is 2.4.2 or later, otherwise a compatibility issue occurs. Current ansible version is {{ ansible_version.full }}" + when: ansible_version.full | version_compare('2.4.2', '<') + +- name: Get if jmespath info[1] + shell: pip list | grep -iw jmespath | wc -l + register: jmespath_exist + +- name: Get if jinja2 exist[1] + shell: pip list | grep -iw jinja2 | wc -l + register: jinja2_exist + +- name: Preflight check - Fail when jmespath or jinja2 doesn't exist + fail: + msg: "Jmespath or Jinja2 does not exist, Please run `pip install -r requirements.txt` to install." + when: jmespath_exist.stdout | int == 0 or jinja2_exist.stdout | int == 0 + +- name: Get jmespath info[2] + shell: pip show jmespath | grep Version |grep -v Metadata-Version + register: jmespath + +- name: Get jmespath version + set_fact: + jmespath_version: "{{ jmespath.stdout_lines[0] | replace('Version: ', '') }}" + +- name: Get jinja2 info[2] + shell: pip show jinja2 | grep Version |grep -v Metadata-Version + register: jinja2 + +- name: Get jinja2 version + set_fact: + jinja2_version: "{{ jinja2.stdout_lines[0] | replace('Version: ', '') }}" + +- name: Preflight check - Fail when the versions of jmespath and jinja2 doesn't meet the requirements + fail: + msg: "Jmespath({{ jmespath_version }}) or jinja2({{ jinja2_version }}) version is too low, Please run `pip install --upgrade -r requirements.txt` to upgrade." + when: jmespath_version | version_compare('0.9.0', '<') or jinja2_version | version_compare('2.9.6', '<') \ No newline at end of file diff --git a/roles/check_system_static/tasks/main.yml b/roles/check_system_static/tasks/main.yml index 209fdc2e9..09f0be002 100644 --- a/roles/check_system_static/tasks/main.yml +++ b/roles/check_system_static/tasks/main.yml @@ -63,43 +63,4 @@ - name: Preflight check - Fail when Linux kernel vm.overcommit_memory parameter is set to 2 fail: msg: "It is not recommended to set vm.overcommit_memory to 2, set it to 0 or 1." - when: vm_overcommit_memory.stdout | int == 2 - -- name: Check ansible version - fail: - msg: "Stop if ansible version is too low, make sure that the Ansible version is 2.4.2 or later, otherwise a compatibility issue occurs. Current ansible version is {{ ansible_version.full }}" - when: ansible_version.full | version_compare('2.4.2', '<') - -- name: Get if jmespath info[1] - shell: pip list | grep -iw jmespath | wc -l - register: jmespath_exist - -- name: Get if jinja2 exist[1] - shell: pip list | grep -iw jinja2 | wc -l - register: jinja2_exist - -- name: Preflight check - Fail when jmespath or jinja2 doesn't exist - fail: - msg: "Jmespath or Jinja2 does not exist, Please run `pip install -r requirements.txt` to install." - when: jmespath_exist.stdout | int == 0 or jinja2_exist.stdout | int == 0 - -- name: Get jmespath info[2] - shell: pip show jmespath | grep Version |grep -v Metadata-Version - register: jmespath - -- name: Get jmespath version - set_fact: - jmespath_version: "{{ jmespath.stdout_lines[0] | replace('Version: ', '') }}" - -- name: Get jinja2 info[2] - shell: pip show jinja2 | grep Version |grep -v Metadata-Version - register: jinja2 - -- name: Get jinja2 version - set_fact: - jinja2_version: "{{ jinja2.stdout_lines[0] | replace('Version: ', '') }}" - -- name: Preflight check - Fail when the versions of jmespath and jinja2 doesn't meet the requirements - fail: - msg: "Jmespath({{ jmespath_version }}) or jinja2({{ jinja2_version }}) version is too low, Please run `pip install --upgrade -r requirements.txt` to upgrade." - when: jmespath_version | version_compare('0.9.0', '<') or jinja2_version | version_compare('2.9.6', '<') + when: vm_overcommit_memory.stdout | int == 2 \ No newline at end of file