Skip to content

Commit

Permalink
sap_swpm: Solve issue 281
Browse files Browse the repository at this point in the history
Add some tags to allow for easily executing only certain steps of the
role:

sap_swpm_pre_install: Only run all preinstallation steps
sap_swpm_generate_inifile: Only generate the SWPM inifile
sap_swpm_sapinst_commandline: Only display the full sapinst command line
sap_swpm_install: Run all preinstallation and installation steps but omit
                  the postinstallation steps
  • Loading branch information
berndfinger committed Dec 5, 2022
1 parent c3edaed commit 08c299e
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 22 deletions.
5 changes: 5 additions & 0 deletions roles/sap_swpm/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@

- name: SAP SWPM - run pre_install tasks
ansible.builtin.import_tasks: pre_install.yml
tags:
- sap_swpm_pre_install
- sap_swpm_install

- name: SAP SWPM - run swpm
ansible.builtin.import_tasks: swpm.yml
tags:
- sap_swpm_install

- name: SAP SWPM - run postinstall task
ansible.builtin.import_tasks: post_install.yml
11 changes: 6 additions & 5 deletions roles/sap_swpm/tasks/pre_install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

- name: SAP SWPM Pre Install - Run Preinstallation Steps
ansible.builtin.include_tasks: swpm/swpm_pre_install.yml

tags:
- sap_swpm_generate_inifile
- sap_swpm_sapinst_commandline

################
# Set sapinst command
Expand All @@ -20,6 +22,7 @@
# IF SWPM is running a HA installation, Ansible Variable sap_swpm_swpm_command_virtual_hostname is set and contains "SAPINST_USE_HOSTNAME={{ sap_swpm_virtual_hostname }}"
# If SWPM is running a MP Stack XML installation, Ansible Variable sap_swpm_swpm_command_mp_stack is set and contains "SAPINST_STACK_XML={{ sap_swpm_mp_stack_path }}/{{ sap_swpm_mp_stack_file_name }}"
sap_swpm_swpm_command_extra_args: "SAPINST_SKIP_DIALOGS=true SAPINST_START_GUISERVER=false {{ sap_swpm_swpm_command_virtual_hostname }} {{ sap_swpm_swpm_command_mp_stack }}"
tags: sap_swpm_sapinst_commandline

################
# Pre Install Optional Tasks
Expand All @@ -29,15 +32,13 @@

- name: SAP SWPM Pre Install - Firewall Setup
ansible.builtin.include_tasks: pre_install/firewall.yml
when:
- "sap_swpm_setup_firewall | bool"
when: "sap_swpm_setup_firewall | bool"

# /etc/hosts

- name: SAP SWPM Pre Install - Update /etc/hosts
ansible.builtin.include_tasks: pre_install/update_etchosts.yml
when:
- "sap_swpm_update_etchosts | bool"
when: "sap_swpm_update_etchosts | bool"

################
# Display Parameters
Expand Down
8 changes: 5 additions & 3 deletions roles/sap_swpm/tasks/pre_install/install_type.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
sap_swpm_swpm_command_virtual_hostname: ""
sap_swpm_swpm_command_mp_stack: ""


################
# Determine Installation Type
################
Expand Down Expand Up @@ -47,7 +46,10 @@
# Run Installation Type Steps
################

- name: SAP SWPM Pre Install - Display the Installation Type
ansible.builtin.debug:
var: sap_swpm_swpm_installation_type

- name: SAP SWPM Pre Install - Run Installation Type Steps
ansible.builtin.include_tasks: "install_type/{{ sap_swpm_swpm_installation_type }}_install.yml"
when:
- "sap_swpm_swpm_installation_type | length > 0"
when: "sap_swpm_swpm_installation_type | length > 0"
11 changes: 8 additions & 3 deletions roles/sap_swpm/tasks/swpm/swpm_inifile_generate_advanced.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
---

# Remove Existing inifile.params
- name: SAP SWPM advanced mode - Create inifile.params
- name: SAP SWPM advanced mode - Ensure 'inifile.params' exists
ansible.builtin.file:
path: "{{ sap_swpm_tmpdir.path }}/inifile.params"
state: touch
mode: '0640'
tags: sap_swpm_generate_inifile

- name: SAP SWPM advanced mode - Loop over the dictionary and output to file
ansible.builtin.lineinfile:
path: "{{ sap_swpm_tmpdir.path }}/inifile.params"
state: present
line: "{{ item.key }} = {{ item.value }}"
with_dict: "{{ sap_swpm_inifile_custom_values_dictionary }}"
tags: sap_swpm_generate_inifile

# NOTE: Values in Dictionary Keys for instance numbers must be string using '01' single quote, otherwise SAP SWPM will crash


# Detect variables from generated inifile
- name: SAP SWPM advanced mode - Detect Variables
ansible.builtin.include_tasks: detect_variables.yml
ansible.builtin.include_tasks:
file: detect_variables.yml
apply:
tags: sap_swpm_generate_inifile
tags: sap_swpm_generate_inifile

# Prepare Software
- name: SAP SWPM advanced mode - Prepare Software
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,22 @@
- name: SAP SWPM advanced_templates mode - Set product_catalog_id
ansible.builtin.set_fact:
sap_swpm_product_catalog_id: "{{ sap_swpm_templates_install_dictionary[sap_swpm_templates_product_input]['sap_swpm_product_catalog_id'] }}"
tags: sap_swpm_generate_inifile

- name: SAP SWPM advanced_templates mode - Create temporary directory
ansible.builtin.tempfile:
state: directory
suffix: swpmconfig
register: sap_swpm_tmpdir
tags: sap_swpm_generate_inifile

# Remove Existing inifile.params
- name: SAP SWPM advanced_templates mode - Ensure inifile.params
- name: SAP SWPM advanced_templates mode - Ensure 'inifile.params' exists
ansible.builtin.file:
path: "{{ sap_swpm_tmpdir.path }}/inifile.params"
state: touch
mode: '0640'
tags: sap_swpm_generate_inifile

- name: SAP SWPM advanced_templates mode - Loop over the dictionary and output to file
ansible.builtin.lineinfile:
Expand All @@ -25,19 +28,23 @@
insertafter: EOF
line: "{{ item.key }}={{ item.value }}"
with_dict: "{{ sap_swpm_templates_install_dictionary[sap_swpm_templates_product_input]['sap_swpm_inifile_custom_values_dictionary'] }}"
tags: sap_swpm_generate_inifile

# NOTE: Values in Dictionary Keys for instance numbers must be string using '01' single quote, otherwise SAP SWPM will crash


# Detect variables from generated inifile
- name: SAP SWPM advanced_templates mode - Detect Variables
ansible.builtin.include_tasks: detect_variables.yml
ansible.builtin.include_tasks:
file: detect_variables.yml
apply:
tags: sap_swpm_generate_inifile
tags: sap_swpm_generate_inifile

# Prepare Software
- name: SAP SWPM advanced_templates mode - Prepare Software
ansible.builtin.include_tasks: prepare_software.yml


# ALT: Generate complete inifile.params with all parameters from control.xml, for every SAP software product
#- name: ALT: SAP SWPM advanced_templates mode - Generate complete inifile.params
# script: ./plugins/module_utils/swpm2_parameters_inifile_generate.py '/path/to/controlxml/'
Expand Down
13 changes: 11 additions & 2 deletions roles/sap_swpm/tasks/swpm/swpm_inifile_generate_default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@

# Determine Installation Type
- name: SAP SWPM default mode - Determine Installation Type
ansible.builtin.include_tasks: "../pre_install/install_type.yml"
ansible.builtin.include_tasks:
file: ../pre_install/install_type.yml
apply:
tags: sap_swpm_generate_inifile
tags: sap_swpm_generate_inifile

# Password Facts
- name: SAP SWPM default mode - Password Facts
ansible.builtin.include_tasks: ../pre_install/password_facts.yml
ansible.builtin.include_tasks:
file: ../pre_install/password_facts.yml
apply:
tags: sap_swpm_generate_inifile
tags: sap_swpm_generate_inifile

# Prepare Software
- name: SAP SWPM default mode - Prepare Software
Expand All @@ -19,3 +27,4 @@
dest: "{{ sap_swpm_tmpdir.path }}/inifile.params"
mode: '0640'
register: sap_swpm_cftemplate
tags: sap_swpm_generate_inifile
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,35 @@
ansible.builtin.set_fact:
sap_swpm_product_catalog_id: "{{ sap_swpm_templates_install_dictionary[sap_swpm_templates_product_input]['sap_swpm_product_catalog_id'] }}"
sap_swpm_inifile_list: "{{ sap_swpm_templates_install_dictionary[sap_swpm_templates_product_input]['sap_swpm_inifile_list'] }}"
tags: sap_swpm_generate_inifile

- name: SAP SWPM default_templates mode - Set product_catalog_id and inifile_list
ansible.builtin.set_fact:
sap_swpm_java_template_id_selected_list: "{{ sap_swpm_templates_install_dictionary[sap_swpm_templates_product_input]['sap_swpm_java_template_id_selected_list'] }}"
when: "'java' in sap_swpm_templates_install_dictionary[sap_swpm_templates_product_input]['sap_swpm_product_catalog_id'] | lower"
tags: sap_swpm_generate_inifile

- name: SAP SWPM default_templates mode - If not already defined, use the default variable for the template
ansible.builtin.set_fact:
"{{ item.key }}": "{{ item.value }}"
with_dict: "{{ sap_swpm_templates_install_dictionary[sap_swpm_templates_product_input]['sap_swpm_inifile_dictionary'] }}"

tags: sap_swpm_generate_inifile

# Determine Installation Type
- name: SAP SWPM default_templates mode - Determine Installation Type
ansible.builtin.include_tasks: "../pre_install/install_type.yml"
ansible.builtin.include_tasks:
file: ../pre_install/install_type.yml
apply:
tags: sap_swpm_generate_inifile
tags: sap_swpm_generate_inifile

# Password Facts
- name: SAP SWPM default_templates mode - Password Facts
ansible.builtin.include_tasks: ../pre_install/password_facts.yml
ansible.builtin.include_tasks:
file: ../pre_install/password_facts.yml
apply:
tags: sap_swpm_generate_inifile
tags: sap_swpm_generate_inifile

# Prepare Software
- name: SAP SWPM default_templates mode - Prepare Software
Expand All @@ -36,3 +46,4 @@
dest: "{{ sap_swpm_tmpdir.path }}/inifile.params"
mode: '0640'
register: sap_swpm_cftemplate
tags: sap_swpm_generate_inifile
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,29 @@
src: "{{ sap_swpm_inifile_reuse_source }}"
dest: "{{ sap_swpm_tmpdir.path }}/inifile.params"
mode: '0640'
tags: sap_swpm_generate_inifile

# Check inifile for des25
- name: SAP SWPM inifile_reuse mode - Check inifile for des25
ansible.builtin.shell: set -o pipefail && cat "{{ sap_swpm_tmpdir.path }}/inifile.params" | grep des25 | wc -l
register: sap_swpm_inifile_read_file
changed_when: false
tags: sap_swpm_generate_inifile

# Check if inifile is reusable
- name: SAP SWPM inifile_reuse mode - Check if inifile is reusable
ansible.builtin.fail:
msg: "{{ sap_swpm_inifile_reuse_source }} is not reusable"
when: sap_swpm_inifile_read_file.stdout != '0'
tags: sap_swpm_generate_inifile

# Detect variables from generated inifile
- name: SAP SWPM inifile_reuse mode - Detect Variables
ansible.builtin.include_tasks: detect_variables.yml
ansible.builtin.include_tasks:
file: detect_variables.yml
apply:
tags: sap_swpm_generate_inifile
tags: sap_swpm_generate_inifile

# Prepare Software
- name: SAP SWPM inifile_reuse mode - Prepare Software
Expand Down
14 changes: 12 additions & 2 deletions roles/sap_swpm/tasks/swpm/swpm_pre_install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
state: directory
suffix: swpmconfig
register: sap_swpm_tmpdir
tags:
- sap_swpm_generate_inifile
- sap_swpm_sapinst_commandline

# Copy password file to the same location as inifile.params
- name: SAP SWPM Pre Install - Copy password file to the same location as inifile.params
Expand All @@ -15,17 +18,24 @@
remote_src: yes
mode: '0640'
when: sap_swpm_use_password_file == "y"
tags: sap_swpm_generate_inifile

# Run SWPM inifile generation based on ansible role mode
- name: SAP SWPM - generate swpm inifile
- name: SAP SWPM Pre Install - generate swpm inifile
ansible.builtin.include_tasks: "swpm_inifile_generate_{{ sap_swpm_ansible_role_mode }}.yml"
tags: sap_swpm_generate_inifile

- name: SAP SWPM Pre Install - Display the location of file 'inifile.params'
ansible.builtin.debug:
msg: "{{ sap_swpm_tmpdir.path }}/inifile.params"
tags: sap_swpm_generate_inifile

# Set fact for SWPM path
- name: SAP SWPM Pre Install - Set fact for SWPM path
ansible.builtin.set_fact:
sap_swpm_sapinst_path: "{{ sap_swpm_swpm_path }}/sap_swpm_extracted"

- name: Create directories if does not exist
- name: SAP SWPM Pre Install - Ensure directory '{{ sap_swpm_sapinst_path }}' exists
ansible.builtin.file:
path: "{{ sap_swpm_sapinst_path }}"
state: directory
Expand Down

0 comments on commit 08c299e

Please sign in to comment.