Skip to content

Commit

Permalink
sap_hana_preconfigure: fix wrong variable substitution inside assert-…
Browse files Browse the repository at this point in the history
…services.yml

Signed-off-by: Bernd Finger <[email protected]>
  • Loading branch information
berndfinger committed Dec 21, 2023
1 parent 5afc8c3 commit e3e3073
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,11 @@
- name: Assert that service abrt-ccpp is disabled, and inactive or stopped
ansible.builtin.include_tasks: assert-services.yml
vars:
line_item: abrt-ccpp
__sap_hana_preconfigure_service_status: "{{ ansible_facts.services['abrt-ccpp.service'].status }}"
__sap_hana_preconfigure_service_state: "{{ ansible_facts.services['abrt-ccpp.service'].state }}"
__sap_hana_preconfigure_packages_and_services_pkg: "{{ __sap_hana_preconfigure_packages_and_services['abrt-ccpp']['pkg'] }}"
__sap_hana_preconfigure_packages_and_services_svc: "{{ __sap_hana_preconfigure_packages_and_services['abrt-ccpp']['svc'] }}"
__sap_hana_preconfigure_packages_and_services_svc_status: "{{ __sap_hana_preconfigure_packages_and_services['abrt-ccpp']['svc_status'] }}"
__sap_hana_preconfigure_packages_and_services_svc_state: "{{ __sap_hana_preconfigure_packages_and_services['abrt-ccpp']['svc_state'] }}"
__sap_hana_preconfigure_packages_and_services_systemd_enabled: "{{ __sap_hana_preconfigure_packages_and_services['abrt-ccpp']['systemd_enabled'] }}"
__sap_hana_preconfigure_packages_and_services_systemd_state: "{{ __sap_hana_preconfigure_packages_and_services['abrt-ccpp']['systemd_state'] }}"
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,11 @@
- name: Assert that service abrtd is disabled, and inactive or stopped
ansible.builtin.include_tasks: assert-services.yml
vars:
line_item: abrtd
__sap_hana_preconfigure_service_status: "{{ ansible_facts.services['abrtd.service'].status }}"
__sap_hana_preconfigure_service_state: "{{ ansible_facts.services['abrtd.service'].state }}"
__sap_hana_preconfigure_packages_and_services_pkg: "{{ __sap_hana_preconfigure_packages_and_services['abrtd']['pkg'] }}"
__sap_hana_preconfigure_packages_and_services_svc: "{{ __sap_hana_preconfigure_packages_and_services['abrtd']['svc'] }}"
__sap_hana_preconfigure_packages_and_services_svc_status: "{{ __sap_hana_preconfigure_packages_and_services['abrtd']['svc_status'] }}"
__sap_hana_preconfigure_packages_and_services_svc_state: "{{ __sap_hana_preconfigure_packages_and_services['abrtd']['svc_state'] }}"
__sap_hana_preconfigure_packages_and_services_systemd_enabled: "{{ __sap_hana_preconfigure_packages_and_services['abrtd']['systemd_enabled'] }}"
__sap_hana_preconfigure_packages_and_services_systemd_state: "{{ __sap_hana_preconfigure_packages_and_services['abrtd']['systemd_state'] }}"
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@
- name: Assert that service numad is disabled, and inactive or stopped, if tuned is not to be used
ansible.builtin.include_tasks: assert-services.yml
vars:
line_item: numad
__sap_hana_preconfigure_service_status: "{{ ansible_facts.services['numad.service'].status }}"
__sap_hana_preconfigure_service_state: "{{ ansible_facts.services['numad.service'].state }}"
__sap_hana_preconfigure_packages_and_services_pkg: "{{ __sap_hana_preconfigure_packages_and_services['numad']['pkg'] }}"
__sap_hana_preconfigure_packages_and_services_svc: "{{ __sap_hana_preconfigure_packages_and_services['numad']['svc'] }}"
__sap_hana_preconfigure_packages_and_services_svc_status: "{{ __sap_hana_preconfigure_packages_and_services['numad']['svc_status'] }}"
__sap_hana_preconfigure_packages_and_services_svc_state: "{{ __sap_hana_preconfigure_packages_and_services['numad']['svc_state'] }}"
__sap_hana_preconfigure_packages_and_services_systemd_enabled: "{{ __sap_hana_preconfigure_packages_and_services['numad']['systemd_enabled'] }}"
__sap_hana_preconfigure_packages_and_services_systemd_state: "{{ __sap_hana_preconfigure_packages_and_services['numad']['systemd_state'] }}"

when: not sap_hana_preconfigure_use_tuned or
sap_hana_preconfigure_assert_all_config|d(false)
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,11 @@
- name: Assert that service firewalld is disabled, and inactive or stopped
ansible.builtin.include_tasks: assert-services.yml
vars:
line_item: firewalld
__sap_hana_preconfigure_service_status: "{{ ansible_facts.services['firewalld.service'].status }}"
__sap_hana_preconfigure_service_state: "{{ ansible_facts.services['firewalld.service'].state }}"
__sap_hana_preconfigure_packages_and_services_pkg: "{{ __sap_hana_preconfigure_packages_and_services['firewalld']['pkg'] }}"
__sap_hana_preconfigure_packages_and_services_svc: "{{ __sap_hana_preconfigure_packages_and_services['firewalld']['svc'] }}"
__sap_hana_preconfigure_packages_and_services_svc_status: "{{ __sap_hana_preconfigure_packages_and_services['firewalld']['svc_status'] }}"
__sap_hana_preconfigure_packages_and_services_svc_state: "{{ __sap_hana_preconfigure_packages_and_services['firewalld']['svc_state'] }}"
__sap_hana_preconfigure_packages_and_services_systemd_enabled: "{{ __sap_hana_preconfigure_packages_and_services['firewalld']['systemd_enabled'] }}"
__sap_hana_preconfigure_packages_and_services_systemd_state: "{{ __sap_hana_preconfigure_packages_and_services['firewalld']['systemd_state'] }}"
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,11 @@
- name: Assert that service kdump is disabled, and inactive or stopped
ansible.builtin.include_tasks: assert-services.yml
vars:
line_item: kdump
__sap_hana_preconfigure_service_status: "{{ ansible_facts.services['kdump.service'].status }}"
__sap_hana_preconfigure_service_state: "{{ ansible_facts.services['kdump.service'].state }}"
__sap_hana_preconfigure_packages_and_services_pkg: "{{ __sap_hana_preconfigure_packages_and_services['kdump']['pkg'] }}"
__sap_hana_preconfigure_packages_and_services_svc: "{{ __sap_hana_preconfigure_packages_and_services['kdump']['svc'] }}"
__sap_hana_preconfigure_packages_and_services_svc_status: "{{ __sap_hana_preconfigure_packages_and_services['kdump']['svc_status'] }}"
__sap_hana_preconfigure_packages_and_services_svc_state: "{{ __sap_hana_preconfigure_packages_and_services['kdump']['svc_state'] }}"
__sap_hana_preconfigure_packages_and_services_systemd_enabled: "{{ __sap_hana_preconfigure_packages_and_services['kdump']['systemd_enabled'] }}"
__sap_hana_preconfigure_packages_and_services_systemd_state: "{{ __sap_hana_preconfigure_packages_and_services['kdump']['systemd_state'] }}"
Original file line number Diff line number Diff line change
@@ -1,46 +1,38 @@
---

- name: Assert that service {{ __sap_hana_preconfigure_packages_and_services[line_item].svc }} is disabled
if package {{ __sap_hana_preconfigure_packages_and_services[line_item].pkg }} is installed
when: "__sap_hana_preconfigure_packages_and_services[line_item].pkg in ansible_facts.packages"
- name: Assert that service {{ __sap_hana_preconfigure_packages_and_services_svc }} is disabled
if package {{ __sap_hana_preconfigure_packages_and_services_pkg }} is installed
when: "__sap_hana_preconfigure_packages_and_services_pkg in ansible_facts.packages"
block:

- name: "Report that package {{ __sap_hana_preconfigure_packages_and_services[line_item].pkg }} is installed"
- name: "Report that package {{ __sap_hana_preconfigure_packages_and_services_pkg }} is installed"
ansible.builtin.debug:
msg: "INFO: Package '{{ __sap_hana_preconfigure_packages_and_services[line_item].pkg }}' is installed."
msg: "INFO: Package '{{ __sap_hana_preconfigure_packages_and_services_pkg }}' is installed."

- name: Define a new variable for the assertion of the service status
ansible.builtin.set_fact:
__sap_hana_preconfigure_service_item_status: ansible_facts.services['{{ __sap_hana_preconfigure_packages_and_services[line_item].svc }}.service'].status

- name: Assert that service {{ __sap_hana_preconfigure_packages_and_services[line_item].svc }} is
{{ __sap_hana_preconfigure_packages_and_services[line_item].svc_status }}
- name: Assert that service {{ __sap_hana_preconfigure_packages_and_services_svc }} is
{{ __sap_hana_preconfigure_packages_and_services_svc_status }}
ansible.builtin.assert:
that: __sap_hana_preconfigure_service_item_status == __sap_hana_preconfigure_packages_and_services[line_item].svc_status
fail_msg: "FAIL: Service '{{ __sap_hana_preconfigure_packages_and_services[line_item].svc }}' is not
{{ __sap_hana_preconfigure_packages_and_services[line_item].svc_status }}!"
success_msg: "PASS: Service '{{ __sap_hana_preconfigure_packages_and_services[line_item].svc }}' is
{{ __sap_hana_preconfigure_packages_and_services[line_item].svc_status }}."
that: __sap_hana_preconfigure_service_status == __sap_hana_preconfigure_packages_and_services_svc_status
fail_msg: "FAIL: Service '{{ __sap_hana_preconfigure_packages_and_services_svc }}' is not
{{ __sap_hana_preconfigure_packages_and_services_svc_status }}!"
success_msg: "PASS: Service '{{ __sap_hana_preconfigure_packages_and_services_svc }}' is
{{ __sap_hana_preconfigure_packages_and_services_svc_status }}."
ignore_errors: "{{ sap_hana_preconfigure_assert_ignore_errors | d(false) }}"

- name: Define a new variable for the assertion of the service state
ansible.builtin.set_fact:
__sap_hana_preconfigure_service_item_state: ansible_facts.services['{{ __sap_hana_preconfigure_packages_and_services[line_item].svc }}.service'].state

- name: Assert that service {{ __sap_hana_preconfigure_packages_and_services[line_item].svc }} is
{{ __sap_hana_preconfigure_packages_and_services[line_item].svc_state }} or
{{ __sap_hana_preconfigure_packages_and_services[line_item].systemd_state }}
- name: Assert that service {{ __sap_hana_preconfigure_packages_and_services_svc }} is
{{ __sap_hana_preconfigure_packages_and_services_svc_state }} or
{{ __sap_hana_preconfigure_packages_and_services_systemd_state }}
ansible.builtin.assert:
that: (__sap_hana_preconfigure_service_item_state == __sap_hana_preconfigure_packages_and_services[line_item].svc_state) or
(__sap_hana_preconfigure_service_item_state == __sap_hana_preconfigure_packages_and_services[line_item].systemd_state)
fail_msg: "FAIL: Service '{{ __sap_hana_preconfigure_packages_and_services[line_item].svc }}' is not
{{ __sap_hana_preconfigure_packages_and_services[line_item].svc_state }}!"
success_msg: "PASS: Service '{{ __sap_hana_preconfigure_packages_and_services[line_item].svc }}' is
{{ __sap_hana_preconfigure_packages_and_services[line_item].svc_state }} or
{{ __sap_hana_preconfigure_packages_and_services[line_item].systemd_state }}."
that: (__sap_hana_preconfigure_service_state == __sap_hana_preconfigure_packages_and_services_svc_state) or
(__sap_hana_preconfigure_service_state == __sap_hana_preconfigure_packages_and_services_systemd_state)
fail_msg: "FAIL: Service '{{ __sap_hana_preconfigure_packages_and_services_svc }}' is not
{{ __sap_hana_preconfigure_packages_and_services_svc_state }}!"
success_msg: "PASS: Service '{{ __sap_hana_preconfigure_packages_and_services_svc }}' is
{{ __sap_hana_preconfigure_packages_and_services_svc_state }} or
{{ __sap_hana_preconfigure_packages_and_services_systemd_state }}."
ignore_errors: "{{ sap_hana_preconfigure_assert_ignore_errors | d(false) }}"

- name: "Report that package {{ __sap_hana_preconfigure_packages_and_services[line_item].pkg }} is not installed"
- name: "Report that package {{ __sap_hana_preconfigure_packages_and_services_pkg }} is not installed"
ansible.builtin.debug:
msg: "PASS: Package '{{ __sap_hana_preconfigure_packages_and_services[line_item].pkg }}' is not installed."
when: "__sap_hana_preconfigure_packages_and_services[line_item].pkg not in ansible_facts.packages"
msg: "PASS: Package '{{ __sap_hana_preconfigure_packages_and_services_pkg }}' is not installed."
when: "__sap_hana_preconfigure_packages_and_services_pkg not in ansible_facts.packages"

0 comments on commit e3e3073

Please sign in to comment.