diff --git a/tasks/install_prerequisites.yaml b/tasks/install_prerequisites.yaml new file mode 100644 index 0000000..31476e3 --- /dev/null +++ b/tasks/install_prerequisites.yaml @@ -0,0 +1,6 @@ +--- + +- import_tasks: steps/ansible_requirements.yml +- include_tasks: steps/install_goswagger.yml + vars: + threescale_cicd_local_bin_path: /usr/local/bin diff --git a/tasks/main.yml b/tasks/main.yml index 7f93a1f..9af0609 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -2,6 +2,7 @@ # Make sure we have everything we need to run this playbook - import_tasks: steps/requirements.yml +- import_tasks: steps/ansible_requirements.yml # Validate the API definition against the Swagger 2.0 / OAS 3.0 - include_tasks: steps/validate_openapi.yml diff --git a/tasks/steps/ansible_requirements.yml b/tasks/steps/ansible_requirements.yml new file mode 100644 index 0000000..7a8cf99 --- /dev/null +++ b/tasks/steps/ansible_requirements.yml @@ -0,0 +1,47 @@ +--- + +- name: Verify that Ansible version is >= 2.4 + assert: + that: "ansible_version.full is version_compare('2.4', '>=')" + msg: This module requires at least Ansible 2.4 + +- 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 + +- name: Check if the "do" jinja extension is enabled + debug: msg={% do {}.update({}) %}{{ success }} + vars: + success: 'The do extension is enabled' + register: check_jinja_do_ext + 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'." + +- assert: + that: + - 'check_jinja_do_ext is success' + msg: |- + You need to enable the 'do' extension of Jinja in your ansible.cfg: + [default] + jinja2_extensions = jinja2.ext.do diff --git a/tasks/steps/requirements.yml b/tasks/steps/requirements.yml index f458d5d..6271e20 100644 --- a/tasks/steps/requirements.yml +++ b/tasks/steps/requirements.yml @@ -16,49 +16,3 @@ - threescale_cicd_openapi_file_format|upper == 'JSON' or threescale_cicd_openapi_file_format|upper == 'YAML' msg: |- The threescale_cicd_openapi_file_format parameter needs to be either 'JSON' or 'YAML' - -- name: Verify that Ansible version is >= 2.4 - assert: - that: "ansible_version.full is version_compare('2.4', '>=')" - msg: This module requires at least Ansible 2.4 - -- 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 - -- name: Check if the "do" jinja extension is enabled - debug: msg={% do {}.update({}) %}{{ success }} - vars: - success: 'The do extension is enabled' - register: check_jinja_do_ext - 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'." - -- assert: - that: - - 'check_jinja_do_ext is success' - msg: |- - You need to enable the 'do' extension of Jinja in your ansible.cfg: - [default] - jinja2_extensions = jinja2.ext.do