Skip to content

sap_swpm: Add Pseudo-Idempotency - #1213

Open
marcelmamula wants to merge 4 commits into
sap-linuxlab:devfrom
marcelmamula:swpm_idempotent
Open

sap_swpm: Add Pseudo-Idempotency#1213
marcelmamula wants to merge 4 commits into
sap-linuxlab:devfrom
marcelmamula:swpm_idempotent

Conversation

@marcelmamula

@marcelmamula marcelmamula commented May 11, 2026

Copy link
Copy Markdown
Contributor

Premise

We have been tip toing around this subject for far too long and it is time we fix this. I was discussing this during my presentation at SUSECON26 two weeks ago and I found time to consolidate all points from our discussion #1005 into working code, that implements Pseudo-Idempotency.

Pseudo-Idempotency definition

Implementation follows logic that I implemented in sap_hana_install role already:

  1. Detection.
  2. Skip destructive tasks, but continue valid post-tasks.
  3. Inform users about it.

This is preventive detection to ensure existing SAP Systems are not destroyed, not fully idempotent code that ensures exact specific SAP Product is installed!

Changes

  1. New pre_install/detect_sap*.yml task files added, which is started from within pre_install/swpm_prepare.yml in order to follow existing structure of tasks and tags. This file contains whole complex logic for detection and exceptions.

  2. New product based dictionaries in vars/main.yml. These dictionaries are very complex, but commented in detail to simplify their management.

  3. User expiration post-task was split into dedicated tasks in separate file. This ensures that we do not blindly call chage and mark it always as change. Note was added about potential use of ansible.builtin.user, but it requires ansible-core 2.18+.

  4. Update debug message blocks to align with rest of changes (remove lines since pipe loads it line by line).

  5. Add new override variable sap_swpm_force: false and # sap_swpm_skip_detection: false.

Detection Approach

New approach uses detection matrix:

### List of scenarios for determining next steps.
# This ensures that installation can be skipped when needed to prevent any potential issues affecting existing installations.
# Optional override is available in defaults/main.yml to execute regardless of warning.
# NOTE: SAP Host Agent can be skipped during installation using 'sap_swpm_install_saphostagent: false'.

## 'saphostctrl' is present:
# 1. SKIP - 'root' saphostctrl check finds the desired SID and instance number.
# 2. INSTALL - 'root' saphostctrl check does not find the desired SID and instance number, and no other indicators are found.
# 3. FAIL - 'root' saphostctrl check does not find the desired SID and instance number, and any other indicators are found.

# 'saphostctrl' is not present:
# 4. SKIP - 'sidadm' sapcontrol check finds the desired SID and instance number.
# 5. INSTALL - 'sidadm' sapcontrol check does not find the desired SID and instance number, and no other indicators are found.
# 6. FAIL - 'sidadm' sapcontrol check does not find the desired SID and instance number, and any other indicators are found.

# Breakdown of potential scenarios and actions:
# | saphostctrl | sapcontrol | Instance Found | Files Found | Action
# |-------------|------------|----------------|-------------|--------
# | Yes         | N/A        | Yes            | N/A         | SKIP
# | Yes         | N/A        | No             | No          | INSTALL
# | Yes         | N/A        | No             | Any         | FAIL
# | No          | Yes        | Yes            | N/A         | SKIP
# | No          | Yes        | No             | Any         | FAIL
# | No          | No         | No             | No          | INSTALL

# List of non-saphostctrl indicators for potential existing SAP installation:
# A. Files found in /usr/sap/<SID> directory.
# B. Profile files found in /sapmnt/<SID>/profile/ directory.
# C. Services found in /usr/sap/sapservices file.

Tests

Tested on SLES_SAP 16.0 using various different combinations:

  • Empty server or preinstalled instances
  • Different products like NW_ABAP_CI, NW_ABAP_ASCS, NW_ABAP_ERS, NW_ABAP_OneHost, NW_ABAP_DB, or other invalid values.
  • Tested with executing multiple installs on same host, where Product ID and sections list limit detection scope to avoid existing unrelated instances.

Examples of new informational tasks

SAP Instance was detected, proceeding to skip installation steps

 [started TASK: community.sap_install.sap_swpm : SAP SWPM Pre Install - Detect - Inform that installation was detected on ae1ascs]
ok: [ae1ascs] =>
    msg: |-
        WARN: Existing SAP System installation detected using 'saphostctrl' or 'sapcontrol' command checks.
        Installation steps will be skipped!

        If you intend to proceed with the installation despite this warning,
        set 'sap_swpm_force' variable to 'true' and execute this Ansible Role again.

No system was detected (just information that checks occured).

 [started TASK: community.sap_install.sap_swpm : SAP SWPM Pre Install - Detect - Inform that no existing installation was detected on s05hana]
ok: [s05hana] =>
    msg: |-
        INFO: No existing SAP System installation detected for SID S05.
        Installation will proceed.

        Detection methods used:
        - saphostctrl command (ListInstances)
        - sapcontrol command (GetInstanceProperties)
        - Instance directories (/usr/sap/S05/)
        - SAP services file (/usr/sap/sapservices)
        - Profile files (/sapmnt/S05/profile/)

Enforced alignment of UID and GID, if variables are used.

TASK [community.sap_install.sap_swpm : SAP SWPM Pre Install - Detect - Fail if conflict exists for group ID 'sapsys']
fatal: [s05hana]: FAILED! =>
    changed: false
    msg: |-
        FAIL: Group 'sapsys' exists but with a different group ID.
        Expected: '3001'
        Found: '79'

Database Load product was detected, informing users that installation will proceed but it is all in hands of SWPM.

[community.sap_install.sap_swpm : SAP SWPM Pre Install - Detect - Inform about products with limited detection capabilities]
WARN: SAP Product NW_ABAP_DB:X cannot be reliably detected by this role due to its nature.

- Database Load does not store any local files that can be detected.
  SWPM handles repeated execution by itself, but you need to proceed with caution when targeting live SAP System.

Bad SAP Product Catalog ID detected.

        WARN: Unable to extract SAP Product ID prefix for product catalog ID 'NW_ABAP_OneHost'.
        Expected format of product catalog ID is 'PREFIX:REST_OF_ID' (e.g., 'NW_ABAP_ASCS:S4HANA2025.CORE.HDB.ABAP').
        Detection of existing SAP instances will proceed based on contents of 'sap_swpm_inifile_sections_list' variable.

        NOTE: Providing invalid SAP Product ID will most likely lead into failure during SWPM execution.

Missing section for known Product prefix

        FAIL: The SAP Product 'NW_ABAP_ASCS:S4HANA2023.CORE.HDB.ABAPHA'
        requires all of the following sections to be defined
        in the variable 'sap_swpm_inifile_sections_list':
        - nw_config_central_services_abap

Adding @berndfinger @sean-freeman @rob0d @rhmk as original participants in our discussion #1005.

@marcelmamula marcelmamula self-assigned this May 11, 2026
@marcelmamula marcelmamula added the enhancement New feature or request label May 11, 2026
@marcelmamula
marcelmamula marked this pull request as draft May 15, 2026 10:33
@marcelmamula

Copy link
Copy Markdown
Contributor Author

Moved back to draft, because I found much safer way for detection and I will be updating it.

@marcelmamula
marcelmamula marked this pull request as ready for review May 20, 2026 14:49
@marcelmamula

Copy link
Copy Markdown
Contributor Author

Whole workflow was redone to align with much complex and strict detection. This will cover all scenarios, without allowing relaxed detection that was in original PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant