Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sap_general_preconfigure - Checking for english locales, issue 907 #914

Open
wants to merge 13 commits into
base: dev
Choose a base branch
from
3 changes: 3 additions & 0 deletions roles/sap_general_preconfigure/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,7 @@ sap_general_preconfigure_domain: "{{ sap_domain | d(ansible_domain) }}"
# Configuring Process Resource Limits
# Example: See README.md

# in SAP Note 2369910 SAP requires English locale
# If you want to define the locale set this to e.g. en_US.UTF-8
sap_general_preconfigure_default_locale: ""
# END: Default Variables for sap_general_preconfigure
8 changes: 8 additions & 0 deletions roles/sap_general_preconfigure/meta/argument_specs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -341,3 +341,11 @@ argument_specs:
sap_general_preconfigure_db_group_name: 'dba'
required: false
type: str

sap_general_preconfigure_default_locale:
description:
- Use this variable to specify the default system locale.
example:
sap_general_preconfigure_db_group_name: 'en_US.UTF-8'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am guessing you mean:
sap_general_preconfigure_default_locale: 'en_US.UTF-8' -- or C.UTF-8 depending what you think should be the "default" recommendation :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Klaas- fixed this one, in addition @berndfinger and I found a bug in the algorithm so that this was variable was never used in certain circumstances (non-English locale set as default would always stop although variable was set)
This variable above is just an example, per default nothing is changed (variable empty in defaults/main.yml)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also removed the code from being executed on SLES because the reviewers are not available for the next weeks -- We may need to open another PR to enable this on SLES

required: false
type: str
53 changes: 53 additions & 0 deletions roles/sap_general_preconfigure/tasks/sapnote/2369910.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# SPDX-License-Identifier: Apache-2.0
---
- name: Configure - Display SAP note number 2369910 and its version
ansible.builtin.debug:
msg: "SAP note {{ (__sap_general_preconfigure_sapnotes_versions | selectattr('number', 'match', '^2369910$') | first).number }}
(version {{ (__sap_general_preconfigure_sapnotes_versions | selectattr('number', 'match', '^2369910$') | first).version }}): SAP Software on Linux: General Information"
tags:
- always

- name: Check locales
when: sap_general_preconfigure_config_all | d(true) or sap_general_preconfigure_2369910 | d(false)
tags:
- sap_general_preconfigure_2369910
- sap_general_preconfigure_configure_locale
block:
- name: Get list of installed locales
ansible.builtin.command: locale -a
changed_when: false
register: __sap_general_preconfigure_locales_installed

- name: Assert that an English locale is installed
ansible.builtin.assert:
that: __sap_general_preconfigure_locales_installed.stdout_lines | select('match', '^en_') | list | length > 0
fail_msg: "FAIL: No English locale is installed. Please install an English locale!"
success_msg: "PASS: An English locale is installed."

- name: Get the current default locale
ansible.builtin.command: awk '/^LANG=/&&(/C.UTF-8/||/en_/){print}' /etc/locale.conf
changed_when: false
register: __sap_general_preconfigure_current_default_locale

- name: Assert that an English locale is the default
ansible.builtin.assert:
that: __sap_general_preconfigure_current_default_locale.stdout_lines | length > 0
fail_msg: "FAIL: English is not set as the default locale. Please define an English default locale with the 'sap_general_preconfigure_default_locale' variable!"
success_msg: "PASS: An English default locale is set."

# Optimization: Check if defined locale is installed, valid and English.
# This code currently allows an invalid locale such as 'en_XY.UTF-74'
- name: Configure English locale
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested and now suggest to use the following code (including the comments to explain the logic a bit):

# We are setting a new locale from sap_general_preconfigure_default_locale if:
# - the new locale starts with "en_" or if it is "C.UTF-8" AND
# - the new locale (replacing "UTF-8" by "utf8" if necessary) is part of the installed locales
    - name: Configure English locale
      when:
        - sap_general_preconfigure_default_locale is defined
        - sap_general_preconfigure_default_locale | length > 0
        - sap_general_preconfigure_default_locale.startswith('en_') or sap_general_preconfigure_default_locale == 'C.UTF-8'
        - __sap_general_preconfigure_locales_installed.stdout_lines | select('match', sap_general_preconfigure_default_locale | regex_replace('UTF-8', 'utf8')) | join('') | trim | length > 0

It allows for setting an English locale using either the UTF-8 or utf8 notation (the output of locale -a contains only utf8 on RHEL 8 and RHEL 9) and also avoids setting an unsupported locale.

If there is an SAP supported OS which has UTF-8 in the output of locale -a, we could of course add the regex_replace filter also after __sap_general_preconfigure_locales_installed.stdout_lines.

when:
- sap_general_preconfigure_default_locale is defined
- sap_general_preconfigure_default_locale | length > 0
- sap_general_preconfigure_default_locale.startswith('en_') or sap_general_preconfigure_default_locale.startswith('C.UTF-8')
ansible.builtin.lineinfile:
path: /etc/locale.conf
regexp: ^LANG=
line: "LANG=\"{{ sap_general_preconfigure_default_locale }}\""
state: present
create: true
owner: root
group: root
mode: '0644'
36 changes: 36 additions & 0 deletions roles/sap_general_preconfigure/tasks/sapnote/assert-2369910.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# SPDX-License-Identifier: Apache-2.0
---
- name: Assert - Display SAP note number 2369910 and its version
ansible.builtin.debug:
msg: "SAP note {{ (__sap_general_preconfigure_sapnotes_versions | selectattr('number', 'match', '^2369910$') | first).number }}
(version {{ (__sap_general_preconfigure_sapnotes_versions | selectattr('number', 'match', '^2369910$') | first).version }}): SAP Software on Linux: General Information"
tags:
- always

## STEP 3.1 -- System Language
- name: Step 3.1 - Check if English Language is installed
tags:
- sap_general_preconfigure_2369910
- sap_general_preconfigure_2369910_03
block:
- name: Get list of installed locales
ansible.builtin.command: locale -a
changed_when: false
register: __sap_general_preconfigure_locales_installed

- name: Assert that an English locale is installed
ansible.builtin.assert:
that: __sap_general_preconfigure_locales_installed.stdout_lines | select('match', '^en_') | list | length > 0
fail_msg: "FAIL: No English locale is installed. Please install an English locale!"
success_msg: "PASS: An English locale is installed."

- name: Get the current default locale
ansible.builtin.command: awk '/^LANG=/&&(/C.UTF-8/||/en_/){print}' /etc/locale.conf
changed_when: false
register: __sap_general_preconfigure_current_default_locale

- name: Assert that an English locale is the default
ansible.builtin.assert:
that: __sap_general_preconfigure_current_default_locale.stdout_lines | length > 0
fail_msg: "FAIL: English is not set as the default locale. Please define a valid English default locale with the variable 'sap_general_preconfigure_default_locale' !"
success_msg: "PASS: An English default locale is set."
13 changes: 13 additions & 0 deletions roles/sap_general_preconfigure/vars/RedHat_7.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# vars file for sap_general_preconfigure

__sap_general_preconfigure_sapnotes_versions:
- { number: '2369910', version: '18' }
- { number: '2002167', version: '36' }
- { number: '1771258', version: '6' }
- { number: '1391070', version: '41' }
Expand Down Expand Up @@ -93,6 +94,9 @@ __sap_general_preconfigure_packages_x86_64:
- compat-sap-c++-7
- compat-sap-c++-9
- compat-sap-c++-10
# English locale packages are required as per SAP note 2369910:
- langpacks-en
- glibc-langpack-en

__sap_general_preconfigure_packages_ppc64le:
- uuidd
Expand All @@ -103,17 +107,26 @@ __sap_general_preconfigure_packages_ppc64le:
- compat-sap-c++-7
- compat-sap-c++-9
- compat-sap-c++-10
# English locale packages are required as per SAP note 2369910:
- langpacks-en
- glibc-langpack-en

__sap_general_preconfigure_packages_ppc64:
- uuidd
- tcsh
- psmisc
- compat-sap-c++-5
# English locale packages are required as per SAP note 2369910:
- langpacks-en
- glibc-langpack-en

__sap_general_preconfigure_packages_s390x:
- uuidd
- tcsh
- psmisc
# English locale packages are required as per SAP note 2369910:
- langpacks-en
- glibc-langpack-en

__sap_general_preconfigure_packages: "{{ lookup('vars', '__sap_general_preconfigure_packages_' + ansible_architecture) }}"

Expand Down
4 changes: 4 additions & 0 deletions roles/sap_general_preconfigure/vars/RedHat_8.0.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# vars file for sap_general_preconfigure

__sap_general_preconfigure_sapnotes_versions:
- { number: '2369910', version: '18' }
- { number: '2772999', version: '24' }
- { number: '1771258', version: '6' }

Expand Down Expand Up @@ -47,6 +48,9 @@ __sap_general_preconfigure_packages:
- psmisc
- nfs-utils
- bind-utils
# English locale packages are required as per SAP note 2369910:
- langpacks-en
- glibc-langpack-en

__sap_general_preconfigure_required_ppc64le:
- ibm-power-managed-rhel8
Expand Down
10 changes: 10 additions & 0 deletions roles/sap_general_preconfigure/vars/RedHat_8.1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# vars file for sap_general_preconfigure

__sap_general_preconfigure_sapnotes_versions:
- { number: '2369910', version: '18' }
- { number: '2772999', version: '24' }
- { number: '1771258', version: '6' }

Expand Down Expand Up @@ -49,6 +50,9 @@ __sap_general_preconfigure_packages_x86_64:
- bind-utils
- compat-sap-c++-9
- compat-sap-c++-10
# English locale packages are required as per SAP note 2369910:
- langpacks-en
- glibc-langpack-en

__sap_general_preconfigure_packages_ppc64le:
- uuidd
Expand All @@ -59,6 +63,9 @@ __sap_general_preconfigure_packages_ppc64le:
- bind-utils
- compat-sap-c++-9
- compat-sap-c++-10
# English locale packages are required as per SAP note 2369910:
- langpacks-en
- glibc-langpack-en

__sap_general_preconfigure_packages_s390x:
- uuidd
Expand All @@ -67,6 +74,9 @@ __sap_general_preconfigure_packages_s390x:
- psmisc
- nfs-utils
- bind-utils
# English locale packages are required as per SAP note 2369910:
- langpacks-en
- glibc-langpack-en

__sap_general_preconfigure_packages: "{{ lookup('vars', '__sap_general_preconfigure_packages_' + ansible_architecture) }}"

Expand Down
10 changes: 10 additions & 0 deletions roles/sap_general_preconfigure/vars/RedHat_8.2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# vars file for sap_general_preconfigure

__sap_general_preconfigure_sapnotes_versions:
- { number: '2369910', version: '18' }
- { number: '2772999', version: '24' }
- { number: '1771258', version: '6' }

Expand Down Expand Up @@ -49,6 +50,9 @@ __sap_general_preconfigure_packages_x86_64:
- bind-utils
- compat-sap-c++-9
- compat-sap-c++-10
# English locale packages are required as per SAP note 2369910:
- langpacks-en
- glibc-langpack-en

__sap_general_preconfigure_packages_ppc64le:
- uuidd
Expand All @@ -59,6 +63,9 @@ __sap_general_preconfigure_packages_ppc64le:
- bind-utils
- compat-sap-c++-9
- compat-sap-c++-10
# English locale packages are required as per SAP note 2369910:
- langpacks-en
- glibc-langpack-en

__sap_general_preconfigure_packages_s390x:
- uuidd
Expand All @@ -67,6 +74,9 @@ __sap_general_preconfigure_packages_s390x:
- psmisc
- nfs-utils
- bind-utils
# English locale packages are required as per SAP note 2369910:
- langpacks-en
- glibc-langpack-en

__sap_general_preconfigure_packages: "{{ lookup('vars', '__sap_general_preconfigure_packages_' + ansible_architecture) }}"

Expand Down
10 changes: 10 additions & 0 deletions roles/sap_general_preconfigure/vars/RedHat_8.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# vars file for sap_general_preconfigure

__sap_general_preconfigure_sapnotes_versions:
- { number: '2369910', version: '18' }
- { number: '2772999', version: '24' }
- { number: '1771258', version: '6' }

Expand Down Expand Up @@ -59,6 +60,9 @@ __sap_general_preconfigure_packages_x86_64:
- compat-sap-c++-9
- compat-sap-c++-10
- compat-sap-c++-11
# English locale packages are required as per SAP note 2369910:
- langpacks-en
- glibc-langpack-en

__sap_general_preconfigure_packages_ppc64le:
- uuidd
Expand All @@ -70,6 +74,9 @@ __sap_general_preconfigure_packages_ppc64le:
- compat-sap-c++-9
- compat-sap-c++-10
- compat-sap-c++-11
# English locale packages are required as per SAP note 2369910:
- langpacks-en
- glibc-langpack-en

__sap_general_preconfigure_packages_s390x:
- uuidd
Expand All @@ -79,6 +86,9 @@ __sap_general_preconfigure_packages_s390x:
- nfs-utils
- bind-utils
- compat-sap-c++-10
# English locale packages are required as per SAP note 2369910:
- langpacks-en
- glibc-langpack-en

__sap_general_preconfigure_packages: "{{ lookup('vars', '__sap_general_preconfigure_packages_' + ansible_architecture) }}"

Expand Down
10 changes: 10 additions & 0 deletions roles/sap_general_preconfigure/vars/RedHat_9.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# vars file for sap_general_preconfigure

__sap_general_preconfigure_sapnotes_versions:
- { number: '2369910', version: '18' }
- { number: '3108316', version: '2' }
- { number: '1771258', version: '6' }

Expand Down Expand Up @@ -65,6 +66,9 @@ __sap_general_preconfigure_packages_x86_64:
- tuned
# package libxcrypt-compat: needed by sapstartsrv and SAP HANA on RHEL 9:
- libxcrypt-compat
# English locale packages are required as per SAP note 2369910:
- langpacks-en
- glibc-langpack-en

__sap_general_preconfigure_packages_ppc64le:
- uuidd
Expand All @@ -79,6 +83,9 @@ __sap_general_preconfigure_packages_ppc64le:
- tuned
# package libxcrypt-compat: needed by sapstartsrv and SAP HANA on RHEL 9:
- libxcrypt-compat
# English locale packages are required as per SAP note 2369910:
- langpacks-en
- glibc-langpack-en

__sap_general_preconfigure_packages_s390x:
- uuidd
Expand All @@ -93,6 +100,9 @@ __sap_general_preconfigure_packages_s390x:
- tuned
# package libxcrypt-compat: needed by sapstartsrv on RHEL 9:
- libxcrypt-compat
# English locale packages are required as per SAP note 2369910:
- langpacks-en
- glibc-langpack-en

__sap_general_preconfigure_packages: "{{ lookup('vars', '__sap_general_preconfigure_packages_' + ansible_architecture) }}"

Expand Down
2 changes: 1 addition & 1 deletion roles/sap_general_preconfigure/vars/Suse.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# - SUSE Linux Enterprise Server 16

__sap_general_preconfigure_sapnotes_versions:
- ''
- { number: '2369910', version: '18'}

__sap_general_preconfigure_packages:
- uuidd
Expand Down
Loading