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 17 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

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

Maybe this one is better, as it looks for ' en_[A-Z]*' AND Unicode:

__sap_general_preconfigure_locales_installed.stdout_lines | regex_findall('en_[A-Z]*[.](utf8|UTF-8)') | length > 0

Copy link
Member

Choose a reason for hiding this comment

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

Update: As we only have to take into account operating systems on which the command localectl is available (RHEL 7+ and SLES15+), we do not have to check if an English locale is installed. Starting with RHEL 8 and SLES15, the localectl set-locale command is checking if a locale is also installed. For RHEL 7 managed nodes, we can cover this topic in the documentation.

So we can remove the tasks Get list of installed locales and Assert that an English locale is installed.

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=/&&/en_/{print}' /etc/locale.conf
Copy link

Choose a reason for hiding this comment

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

this does not take into account that C.UTF-8 is also english

Copy link
Member Author

@rhmk rhmk Dec 16, 2024

Choose a reason for hiding this comment

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

You are right. Although C is English it is not sufficient for HANA2 SPS08. The en_* locales have to be installed.
A test run showed that having the system locale C while having en_* installed was sufficient.
I am not sure how we can deal with it. For now I suggest accepting C and en_* locales, as long as en_* is installed. IIRC SAP recommends en_US.UTF-8, so if some body has a proof for that and put here or to the issue would be great. Then we could at least print a warning.

Copy link
Member

Choose a reason for hiding this comment

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

@rhmk I just installed HANA SPS08 (rev 81) on RHEL 9.4 using:

  • control node:

    • LANG set to en_US.UTF-8 in the shell which called the ansible-playbook command
  • managed node:

    • LANG="C.UTF-8" in /etc/locale.conf
    • package glibc-langpack-en being installed but not package langpacks-en. An attempt to remove the package glibc-langpack-en failed due to a dependency on the package grub2-tools-minimal.

Copy link
Member

Choose a reason for hiding this comment

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

suggested new awk statement:
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."

- name: Assert that the role variable sap_general_preconfigure_default_locale starts with 'en_'
ansible.builtin.assert:
that: sap_general_preconfigure_default_locale.startswith('en_')
fail_msg: "FAIL: No English locale is defined in variable 'sap_general_preconfigure_default_locale'!"
success_msg: "PASS: The English default locale is valid"

- 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.

Copy link
Member

@berndfinger berndfinger Jan 3, 2025

Choose a reason for hiding this comment

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

Update: With localectl set-locale, we can use the following code:

    - name: Configure an English locale
      when:
        - sap_general_preconfigure_default_locale is defined and sap_general_preconfigure_default_locale
        - sap_general_preconfigure_default_locale == 'C.UTF-8' or
          sap_general_preconfigure_default_locale == 'C.utf8' or
          sap_general_preconfigure_default_locale.startswith('en_') and
            (sap_general_preconfigure_default_locale.endswith('UTF-8') or
             sap_general_preconfigure_default_locale.endswith('utf8'))
      ansible.builtin.command: "localectl set-locale LANG={{ sap_general_preconfigure_default_locale }}"

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=/&&/en_/{print}' /etc/locale.conf
Copy link
Member

Choose a reason for hiding this comment

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

suggested new awk statement:
awk '/^LANG=/&&(/C.UTF-8/||/en_/){print}' /etc/locale.conf

Copy link
Member Author

Choose a reason for hiding this comment

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

Change made and also fixed an issue with the variable check to set the locale

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."
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