From fb6ffbf4f482382094d17dcb48d10ab0826f2147 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20Mass=C3=A9?= Date: Thu, 3 May 2018 08:55:16 +0200 Subject: [PATCH] check requirements before playbook is run --- README.md | 8 ++++---- tasks/check_requirements.yml | 27 +++++++++++++++++++++++++++ tasks/main.yml | 2 ++ 3 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 tasks/check_requirements.yml diff --git a/README.md b/README.md index 581311d..d67f0bd 100644 --- a/README.md +++ b/README.md @@ -20,14 +20,14 @@ you can install it with: pip install jmespath ``` -A recent version of Jinja (2.8) is also required. You can install it with: +A recent version of Jinja (2.8) is also required. You can upgrade your Jinja version with: ``` -pip install jinja2 +pip install -U Jinja2 ``` -If your control node runs on RHEL7, you can run +If your control node runs on RHEL7, you can run [this playbook](https://github.com/nmasse-itix/OpenShift-Lab/blob/master/common/verify-local-requirements.yml) -to install the missing dependencies. +to install the missing dependencies. ## Example: Deploy an API on 3scale SaaS with hosted APIcast gateways diff --git a/tasks/check_requirements.yml b/tasks/check_requirements.yml new file mode 100644 index 0000000..9584460 --- /dev/null +++ b/tasks/check_requirements.yml @@ -0,0 +1,27 @@ +--- + +- name: Check if jmespath is installed locally + debug: msg={{dummy|json_query('@')}} + register: check_jmespath + ignore_errors: yes + vars: + dummy: Hello World + +- name: Check if jinja 2.8 is installed locally + debug: msg={{(dummy|selectattr("id", "equalto", "hello")|first)['value']}} + vars: + dummy: + - id: hello + value: Hello World + register: check_jinja28 + ignore_errors: yes + +- assert: + that: + - 'check_jmespath is success' + msg: "The JMESPath library is required by this role. Please install the JMESPath library with 'pip install jmespath'." + +- assert: + that: + - 'check_jinja28 is success' + msg: "At least Jinja v2.8 is required by this role. Please update Jinja with 'pip install -U Jinja2'." diff --git a/tasks/main.yml b/tasks/main.yml index 6578025..54cdf72 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,5 +1,7 @@ --- +- import_tasks: check_requirements.yml + - name: Ensure pre-requisites are met assert: that: