This repository has been archived by the owner on Jun 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 274
Add jmespath and jinja2 precheck #802
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,3 +64,42 @@ | |
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 -i jmespath | wc -l | ||
register: jmespath_exist | ||
|
||
- name: Get if jinja2 exist[1] | ||
shell: pip list | grep -i jinja2 | wc -l | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. But more, when there is a package named: jinja2-abc the shell command will succeed. |
||
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', '<') |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pip show <package>
is more efficient.and user jmespath_exist.rc == 0
Ref: https://pip.pypa.io/en/stable/reference/pip_show/