Skip to content
This repository has been archived by the owner on May 30, 2022. It is now read-only.

Commit

Permalink
Refactor version checks
Browse files Browse the repository at this point in the history
Use ansible.builtin.package_facts instead of shell
  • Loading branch information
aleksei-burlakov committed Oct 26, 2021
1 parent 9f9404c commit 8400670
Show file tree
Hide file tree
Showing 11 changed files with 14 additions and 83 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ RUN make build
FROM python:3.7-slim AS trento-runner
RUN ln -s /usr/local/bin/python /usr/bin/python \
&& /usr/bin/python -m venv /venv \
&& /venv/bin/pip install 'ansible~=4.6.0' 'ara~=1.5.7' \
&& /venv/bin/pip install 'ansible~=4.6.0' 'ara~=1.5.7' 'rpm~=0.0.2' \
&& apt-get update && apt-get install -y --no-install-recommends \
ssh \
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
Expand Down
14 changes: 1 addition & 13 deletions runner/ansible/roles/checks/2.2.1/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
---

- name: "{{ name }}.check"
shell: |
#
readlink /etc/products.d/baseproduct | grep -i "{{ expected [name] }}" || exit 1
exit 0
check_mode: false
register: config_updated
changed_when: config_updated.rc != 0
failed_when: config_updated.rc > 1

- block:
- name: Post results
import_role:
name: post-results
when:
- ansible_check_mode
vars:
status: "{{ config_updated is not changed }}"
status: "{{ ansible_distribution is version(expected[name], '==') }}"
4 changes: 1 addition & 3 deletions runner/ansible/roles/checks/2.2.2/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@
- name: Post results
import_role:
name: post-results
when:
- ansible_check_mode
vars:
status: "{{ ansible_distribution_version is version(expected[name], '>=') }}"
status: "{{ ansible_distribution_version is version(expected[name], '>=') }}"
14 changes: 1 addition & 13 deletions runner/ansible/roles/checks/2.2.3/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
---

- name: "{{ name }}.check"
shell: |
# Check the pacemaker version IS
# If not installed, exit with error
rpm -q --qf "%{VERSION}\n" pacemaker || exit 2
check_mode: false
register: config_updated
changed_when: config_updated.stdout is version(expected[name], '<')
failed_when: config_updated.rc > 1

- block:
- name: Post results
import_role:
name: post-results
when:
- ansible_check_mode
vars:
status: "{{ config_updated is not changed }}"
status: "{{'pacemaker' in ansible_facts.packages and ansible_facts.packages['pacemaker'][0].version is version(expected[name], '>') }}"
14 changes: 1 addition & 13 deletions runner/ansible/roles/checks/2.2.4/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
---

- name: "{{ name }}.check"
shell: |
# Check the corosync version IS
# If not installed, exit with error
rpm -q --qf "%{VERSION}\n" corosync || exit 2
check_mode: false
register: config_updated
changed_when: config_updated.stdout is version(expected[name], '<')
failed_when: config_updated.rc > 1

- block:
- name: Post results
import_role:
name: post-results
when:
- ansible_check_mode
vars:
status: "{{ config_updated is not changed }}"
status: "{{'corosync' in ansible_facts.packages and ansible_facts.packages['corosync'][0].version is version(expected[name], '>') }}"
14 changes: 1 addition & 13 deletions runner/ansible/roles/checks/2.2.5/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
---

- name: "{{ name }}.check"
shell: |
# Check the sbd version IS
# If not installed, exit with error
rpm -q --qf "%{VERSION}\n" sbd || exit 2
check_mode: false
register: config_updated
changed_when: config_updated.stdout is version(expected[name], '<')
failed_when: config_updated.rc > 1

- block:
- name: Post results
import_role:
name: post-results
when:
- ansible_check_mode
vars:
status: "{{ config_updated is not changed }}"
status: "{{'sbd' in ansible_facts.packages and ansible_facts.packages['sbd'][0].version is version(expected[name], '>') }}"
14 changes: 1 addition & 13 deletions runner/ansible/roles/checks/2.2.6/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
---

- name: "{{ name }}.check"
shell: |
# Check the SAPHanaSR version is at least
# If not installed, exit with error
rpm -q --qf "%{VERSION}\n" SAPHanaSR || exit 2
check_mode: false
register: config_updated
changed_when: config_updated.stdout is version(expected[name], '<')
failed_when: config_updated.rc > 1

- block:
- name: Post results
import_role:
name: post-results
when:
- ansible_check_mode
vars:
status: "{{ config_updated is not changed }}"
status: "{{'SAPHanaSR' in ansible_facts.packages and ansible_facts.packages['SAPHanaSR'][0].version is version(expected[name], '>') }}"
13 changes: 1 addition & 12 deletions runner/ansible/roles/checks/2.2.7/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,8 @@
---

- name: "{{ name }}.check"
shell: |
# Check python version
python3 --version | cut -d" " -f2
check_mode: false
register: config_updated
changed_when: config_updated.stdout is version(expected[name], '<')
failed_when: config_updated.rc !=0

- block:
- name: Post results
import_role:
name: post-results
when:
- ansible_check_mode
vars:
status: "{{ config_updated is not changed }}"
status: "{{'python3' in ansible_facts.packages and ansible_facts.packages['python3'][0].version is version(expected[name], '>') }}"
4 changes: 4 additions & 0 deletions runner/ansible/roles/load_facts/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
delegate_to: localhost
run_once: true

- name: Gather the package facts
ansible.builtin.package_facts:
manager: auto

- name: set default value to cluster_selected_checks_list
set_fact:
cluster_selected_checks_list: "{{ cluster_selected_checks|default('')|split(',') }}"
Expand Down
2 changes: 1 addition & 1 deletion runner/ansible/vars/azure_env.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ expected:
"2.1.7.path": "/usr/share/SAPHanaSR"
"2.1.7.execution_order": "1"
"2.1.7.ha_dr_saphanasr": "info"
"2.2.1": "sles_sap.prod"
"2.2.1": "SLES_SAP"
"2.2.2": "15.1"
"2.2.3": "2.0.3"
"2.2.3.exclude": "2.0.3+20200511.2b248d828"
Expand Down
2 changes: 1 addition & 1 deletion runner/ansible/vars/dev_env.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ expected:
"2.1.7.path": "/usr/share/SAPHanaSR"
"2.1.7.execution_order": "1"
"2.1.7.ha_dr_saphanasr": "info"
"2.2.1": "sles_sap.prod"
"2.2.1": "SLES_SAP"
"2.2.2": "15.1"
"2.2.3": "2.0.3"
"2.2.3.exclude": "2.0.3+20200511.2b248d828"
Expand Down

0 comments on commit 8400670

Please sign in to comment.