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: Use tags for limiting the role scope #653

Merged
merged 9 commits into from
Feb 28, 2024
48 changes: 48 additions & 0 deletions roles/sap_general_preconfigure/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,54 @@ sap_general_preconfigure_db_group_name: dba

<!-- END: Role Input Parameters for sap_general_preconfigure -->

## Tags (RHEL systems only)

With the following tags, the role can be called to perform certain activities only:
- tag `sap_general_preconfigure_installation`: Perform only the installation tasks
- tag `sap_general_preconfigure_configuration`: Perform only the configuration tasks
- tag `sap_general_preconfigure_configuration_all_steps`: Perform all configuration tasks
- tag `sap_general_preconfigure_3108316_03`: Perform only the tasks(s) related to this step of the SAP note.
- tag `sap_general_preconfigure_etc_hosts`: Perform only the tasks(s) related to this step. This step might be one of multiple
configuration activities of a SAP note. Also this step might be valid for multiple RHEL major releases.

Sample call for only performing all installation and configuration tasks. This is the default behavior. If no tag is specified, all
installation and configuration tasks are enabled:
```
# ansible-playbook sap-general-preconfigure.yml
```

Sample call for only performing all installation tasks:
```
# ansible-playbook sap-general-preconfigure.yml --tags=sap_general_preconfigure_installation
```

Sample call for only performing all configuration tasks. The tag sap_general_preconfigure_configuration is needed to only use
the configuration tasks, and the tag sap_general_preconfigure_configuration_all_steps activates each individual configuration task. Both
need to be enabled for running all the configuration tasks:
```
# ansible-playbook sap-general-preconfigure.yml --tags=sap_general_preconfigure_configuration,sap_general_preconfigure_configuration_all_steps
```

Sample call for only verifying and modifying the /etc/hosts file:
```
# ansible-playbook sap-general-preconfigure.yml --tags=sap_general_preconfigure_configuration,sap_general_preconfigure_etc_hosts
```

Sample call for performing all configuration steps except verifying and modifying the /etc/hosts file:
```
# ansible-playbook sap-general-preconfigure.yml --tags=sap_general_preconfigure_configuration,sap_general_preconfigure_configuration_all_steps --skip_tags=sap_general_preconfigure_etc_hosts
```

Sample call for only performing the configuration actitvities related to step 2 (SELinux settings) of SAP note 3108316:
```
# ansible-playbook sap-general-preconfigure.yml --tags=sap_general_preconfigure_configuration,sap_general_preconfigure_3108316_02
```

Sample call for performing all configuration actitvities except those related to step 2 (SELinux settings) of SAP note 3108316:
```
# ansible-playbook sap-general-preconfigure.yml --tags=sap_general_preconfigure_configuration,sap_general_preconfigure_configuration_all_steps --skip_tags=sap_general_preconfigure_3108316_02
```

## Dependencies

This role does not depend on any other role.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@
when: sap_general_preconfigure_create_directories or sap_general_preconfigure_modify_selinux_labels

- name: Configure - Include configuration actions for required sapnotes
ansible.builtin.include_tasks: "sapnote/{{ sap_note_line_item.number }}.yml"
ansible.builtin.include_tasks:
file: "sapnote/{{ sap_note_line_item.number }}.yml"
with_items: "{{ __sap_general_preconfigure_sapnotes_versions | difference(['']) }}"
loop_control:
loop_var: sap_note_line_item
tags:
- sap_general_preconfigure_configuration
- sap_general_preconfigure_configuration_all_steps
Copy link
Member

Choose a reason for hiding this comment

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

Is the tag sap_general_preconfigure_configuration_all_steps really necessary?

Copy link
Member Author

Choose a reason for hiding this comment

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

Is the tag sap_general_preconfigure_configuration_all_steps really necessary?

Thanks! I tested again and it found no longer a combination of tags which would require both tags. So it seems it's really not required. I'll update the code accordingly.

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 was a bit too fast. Further testing revealed that only with both tags, sap_general_preconfigure_configuration and sap_general_preconfigure_configuration_all_steps, it is possible to execute just one or a few of the configuration steps.
With just the tag sap_general_preconfigure_configuration, it is possible to run all configuration steps and skip some of them. But I want more. ;-)
See also the examples in README.md.

43 changes: 41 additions & 2 deletions roles/sap_general_preconfigure/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@
- name: Display the role path
ansible.builtin.debug:
var: role_path
tags:
- sap_general_preconfigure_installation
- sap_general_preconfigure_configuration

- name: Include OS specific vars, specific
ansible.builtin.include_vars: '{{ item }}'
with_first_found:
- '{{ ansible_distribution.split("_")[0] }}_{{ ansible_distribution_version }}.yml'
- '{{ ansible_distribution.split("_")[0] }}_{{ ansible_distribution_major_version }}.yml'
- '{{ ansible_os_family }}.yml'
tags:
- sap_general_preconfigure_installation
- sap_general_preconfigure_configuration

- name: Rename user sap_preconfigure variables if found, generic
ansible.builtin.set_fact:
Expand All @@ -31,6 +37,9 @@
sap_general_preconfigure_modify_etc_hosts: "{{ sap_preconfigure_modify_etc_hosts | d(sap_general_preconfigure_modify_etc_hosts) }}"
sap_general_preconfigure_kernel_parameters: "{{ sap_preconfigure_kernel_parameters | d(sap_general_preconfigure_kernel_parameters) }}"
sap_general_preconfigure_max_hostname_length: "{{ sap_preconfigure_max_hostname_length | d(sap_general_preconfigure_max_hostname_length) }}"
tags:
- sap_general_preconfigure_installation
- sap_general_preconfigure_configuration

- name: Rename user sap_preconfigure variables if found, RHEL only
ansible.builtin.set_fact:
Expand All @@ -52,45 +61,75 @@
sap_general_preconfigure_2772999_09: "{{ (sap_preconfigure_2772999_09 | d(sap_general_preconfigure_2772999_09)) | d(false) }}"
sap_general_preconfigure_2772999_10: "{{ (sap_preconfigure_2772999_10 | d(sap_general_preconfigure_2772999_10)) | d(false) }}"
when: ansible_facts['distribution'] in ['RedHat']
tags:
- sap_general_preconfigure_installation
- sap_general_preconfigure_configuration

- name: Rename sap_preconfigure_db_group_name if defined
ansible.builtin.set_fact:
sap_general_preconfigure_db_group_name: "{{ sap_preconfigure_db_group_name | d(sap_general_preconfigure_db_group_name) }}"
when: sap_preconfigure_db_group_name is defined or sap_general_preconfigure_db_group_name is defined
tags:
- sap_general_preconfigure_installation
- sap_general_preconfigure_configuration

- name: Set filename prefix to empty string if role is run in normal mode
ansible.builtin.set_fact:
__sap_general_preconfigure_fact_assert_filename_prefix: ""
when: not sap_general_preconfigure_assert | d(false)
tags:
- sap_general_preconfigure_installation
- sap_general_preconfigure_configuration

- name: Prepend filename with assert string if role is run in assert mode
ansible.builtin.set_fact:
__sap_general_preconfigure_fact_assert_filename_prefix: "assert-"
when: sap_general_preconfigure_assert | d(false)
tags:
- sap_general_preconfigure_installation
- sap_general_preconfigure_configuration

# required for installation and configuration tasks:
- name: Gather package facts
ansible.builtin.package_facts:
tags:
- sap_general_preconfigure_installation

- name: Include tasks from 'installation.yml'
ansible.builtin.include_tasks: '{{ item }}/{{ __sap_general_preconfigure_fact_assert_filename_prefix }}installation.yml'
ansible.builtin.include_tasks:
file: '{{ item }}/{{ __sap_general_preconfigure_fact_assert_filename_prefix }}installation.yml'
apply:
tags: sap_general_preconfigure_installation
Copy link
Member

Choose a reason for hiding this comment

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

There is already a tag in this task, why adding the same one?

Copy link
Member Author

@berndfinger berndfinger Feb 14, 2024

Choose a reason for hiding this comment

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

This code will apply a tag to all tasks of the included file(s). And without the tags: lines at the end of the same task, this current task will not be run when using that tag. See also: https://docs.ansible.com/ansible/latest/collections/ansible/builtin/include_tasks_module.html .

Copy link
Member

Choose a reason for hiding this comment

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

LGTM

when: sap_general_preconfigure_config_all | d(true) or sap_general_preconfigure_installation | d(false)
with_first_found:
- '{{ ansible_distribution.split("_")[0] }}'
- '{{ ansible_distribution }}'
- '{{ ansible_os_family }}.yml'
tags:
- sap_general_preconfigure_installation

- name: Gather package facts again after the installation phase
ansible.builtin.package_facts:
tags:
- sap_general_preconfigure_installation
- sap_general_preconfigure_configuration

- name: Include tasks from 'configuration.yml'
ansible.builtin.include_tasks: '{{ item }}/{{ __sap_general_preconfigure_fact_assert_filename_prefix }}configuration.yml'
ansible.builtin.include_tasks:
file: '{{ item }}/{{ __sap_general_preconfigure_fact_assert_filename_prefix }}configuration.yml'
apply:
tags: sap_general_preconfigure_configuration_all_steps
Copy link
Member

Choose a reason for hiding this comment

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

Same question done in the line 102

Copy link
Member Author

Choose a reason for hiding this comment

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

See above.

when: sap_general_preconfigure_config_all | d(true) or sap_general_preconfigure_configuration | d(false)
with_first_found:
- '{{ ansible_distribution.split("_")[0] }}'
- '{{ ansible_distribution }}'
- '{{ ansible_os_family }}.yml'
tags:
- sap_general_preconfigure_configuration

# allow a reboot at the end of the preconfigure role
- name: Flush handlers
ansible.builtin.meta: flush_handlers
tags:
- sap_general_preconfigure_installation
- sap_general_preconfigure_configuration
5 changes: 5 additions & 0 deletions roles/sap_general_preconfigure/tasks/sapnote/0941735.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
memtotal_mb = {{ ansible_memtotal_mb }};
swaptotal_mb = {{ ansible_swaptotal_mb }};
sap_general_preconfigure_size_of_tmpfs_gb = {{ sap_general_preconfigure_size_of_tmpfs_gb }}"
tags:
- sap_general_preconfigure_configuration

- name: Import tasks from '../RedHat/generic/configure-tmpfs.yml'
ansible.builtin.import_tasks: ../RedHat/generic/configure-tmpfs.yml
when: sap_general_preconfigure_config_all | d(true) or sap_general_preconfigure_0941735 | d(false)
tags:
- sap_general_preconfigure_0941735
- sap_general_preconfigure_configure_tmpfs
5 changes: 5 additions & 0 deletions roles/sap_general_preconfigure/tasks/sapnote/1391070.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
ansible.builtin.debug:
msg: "SAP note {{ (__sap_general_preconfigure_sapnotes_versions | selectattr('number', 'match', '^1391070$') | first).number }}
(version {{ (__sap_general_preconfigure_sapnotes_versions | selectattr('number', 'match', '^1391070$') | first).version }}): Configure uuidd"
tags:
- sap_general_preconfigure_configuration

- name: Import tasks from '../RedHat/generic/configure-uuidd.yml'
ansible.builtin.import_tasks: ../RedHat/generic/configure-uuidd.yml
when: sap_general_preconfigure_config_all | d(true) or sap_general_preconfigure_1391070 | d(false)
tags:
- sap_general_preconfigure_1391070
- sap_general_preconfigure_configure_uuidd
5 changes: 5 additions & 0 deletions roles/sap_general_preconfigure/tasks/sapnote/1771258.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
ansible.builtin.debug:
msg: "SAP note {{ (__sap_general_preconfigure_sapnotes_versions | selectattr('number', 'match', '^1771258$') | first).number }}
(version {{ (__sap_general_preconfigure_sapnotes_versions | selectattr('number', 'match', '^1771258$') | first).version }}): User and system resource limits"
tags:
- sap_general_preconfigure_configuration

- name: Import tasks from '../RedHat/generic/increase-nofile-limits.yml'
ansible.builtin.import_tasks: ../RedHat/generic/increase-nofile-limits.yml
when: sap_general_preconfigure_config_all | d(true) or sap_general_preconfigure_1771258 | d(false)
tags:
- sap_general_preconfigure_1771258
- sap_general_preconfigure_nofile_limits
12 changes: 12 additions & 0 deletions roles/sap_general_preconfigure/tasks/sapnote/2002167.yml
ja9fuchs marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,35 @@
ansible.builtin.debug:
msg: "SAP note {{ (__sap_general_preconfigure_sapnotes_versions | selectattr('number', 'match', '^2002167$') | first).number }}
(version {{ (__sap_general_preconfigure_sapnotes_versions | selectattr('number', 'match', '^2002167$') | first).version }}): Configure RHEL 7"
tags:
- sap_general_preconfigure_configuration

- name: Import tasks from '2002167/02-configuration-changes.yml'
ansible.builtin.import_tasks: 2002167/02-configuration-changes.yml
when: sap_general_preconfigure_config_all | d(true) or sap_general_preconfigure_2002167_02 | d(false)
tags:
- sap_general_preconfigure_2002167_02

- name: Import tasks from '2002167/03-setting-the-hostname.yml'
ansible.builtin.import_tasks: 2002167/03-setting-the-hostname.yml
when: sap_general_preconfigure_config_all | d(true) or sap_general_preconfigure_2002167_03 | d(false)
tags:
- sap_general_preconfigure_2002167_03

- name: Import tasks from '2002167/04-linux-kernel-parameters.yml'
ansible.builtin.import_tasks: 2002167/04-linux-kernel-parameters.yml
when: sap_general_preconfigure_config_all | d(true) or sap_general_preconfigure_2002167_04 | d(false)
tags:
- sap_general_preconfigure_2002167_04

- name: Import tasks from '2002167/05-process-resource-limits.yml'
ansible.builtin.import_tasks: 2002167/05-process-resource-limits.yml
when: sap_general_preconfigure_config_all | d(true) or sap_general_preconfigure_2002167_05 | d(false)
tags:
- sap_general_preconfigure_2002167_05

- name: Import tasks from '2002167/06-additional-notes-for-installing-sap-systems.yml'
ansible.builtin.import_tasks: 2002167/06-additional-notes-for-installing-sap-systems.yml
when: sap_general_preconfigure_config_all | d(true) or sap_general_preconfigure_2002167_06 | d(false)
tags:
- sap_general_preconfigure_2002167_06
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@
- name: Assert 2002167-2a
ansible.builtin.debug:
msg: "SAP note 2002167 Step 2a: Configure the Firewall"
tags:
- sap_general_preconfigure_firewall

- name: Import tasks from '../../RedHat/generic/assert-firewall.yml'
ansible.builtin.import_tasks: ../../RedHat/generic/assert-firewall.yml
tags:
- sap_general_preconfigure_firewall

- name: Assert 2002167-2b
ansible.builtin.debug:
msg: "SAP note 2002167 Step 2b: Configure SELinux"
tags:
- sap_general_preconfigure_selinux

- name: Import tasks from '../../RedHat/generic/assert-selinux.yml'
ansible.builtin.import_tasks: ../../RedHat/generic/assert-selinux.yml
tags:
- sap_general_preconfigure_selinux
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@
- name: Configure 2002167-2a
ansible.builtin.debug:
msg: "SAP note 2002167 Step 2a: Configure the Firewall"
tags:
- sap_general_preconfigure_firewall
- sap_general_preconfigure_selinux

- name: Import tasks from '../../RedHat/generic/configure-firewall.yml'
ansible.builtin.import_tasks: ../../RedHat/generic/configure-firewall.yml
tags:
- sap_general_preconfigure_firewall

- name: Configure 2002167-2b
ansible.builtin.debug:
msg: "SAP note 2002167 Step 2b: Configure SELinux"

- name: Import tasks from '../../RedHat/generic/configure-selinux.yml'
ansible.builtin.import_tasks: ../../RedHat/generic/configure-selinux.yml
tags:
- sap_general_preconfigure_selinux
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,22 @@
- name: Assert 2002167-3
ansible.builtin.debug:
msg: "SAP note 2002167 Step 3: Setting the Hostname"
tags:
- sap_general_preconfigure_hostname
- sap_general_preconfigure_etc_hosts
- sap_general_preconfigure_dns_name_resolution

- name: Import tasks from '../../RedHat/generic/assert-hostname.yml'
ansible.builtin.import_tasks: ../../RedHat/generic/assert-hostname.yml
tags:
- sap_general_preconfigure_hostname

- name: Import tasks from '../../RedHat/generic/assert-etc-hosts.yml'
ansible.builtin.import_tasks: ../../RedHat/generic/assert-etc-hosts.yml
tags:
- sap_general_preconfigure_etc_hosts

- name: Import tasks from '../../RedHat/generic/assert-dns-name-resolution.yml'
ansible.builtin.import_tasks: ../../RedHat/generic/assert-dns-name-resolution.yml
tags:
- sap_general_preconfigure_dns_name_resolution
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,22 @@
- name: Configure 2002167-3
ansible.builtin.debug:
msg: "SAP note 2002167 Step 3: Setting the Hostname"
tags:
- sap_general_preconfigure_hostname
- sap_general_preconfigure_etc_hosts
- sap_general_preconfigure_dns_name_resolution

- name: Import tasks from '../../RedHat/generic/configure-hostname.yml'
ansible.builtin.import_tasks: ../../RedHat/generic/configure-hostname.yml
tags:
- sap_general_preconfigure_hostname

- name: Import tasks from '../../RedHat/generic/configure-etc-hosts.yml'
ansible.builtin.import_tasks: ../../RedHat/generic/configure-etc-hosts.yml
tags:
- sap_general_preconfigure_etc_hosts

- name: Import tasks from '../../RedHat/generic/check-dns-name-resolution.yml'
ansible.builtin.import_tasks: ../../RedHat/generic/check-dns-name-resolution.yml
tags:
- sap_general_preconfigure_dns_name_resolution
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
- name: Assert 2002167-4
ansible.builtin.debug:
msg: "SAP note 2002167 Step 4: Linux Kernel Parameters"
tags:
- sap_general_preconfigure_kernel_parameters

- name: Import tasks from '../../RedHat/generic/assert-kernel-parameters.yml'
ansible.builtin.import_tasks: ../../RedHat/generic/assert-kernel-parameters.yml
tags:
- sap_general_preconfigure_kernel_parameters
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
- name: Configure 2002167-4
ansible.builtin.debug:
msg: "SAP note 2002167 Step 4: Linux Kernel Parameters"
tags:
- sap_general_preconfigure_kernel_parameters

- name: Import tasks from '../../RedHat/generic/configure-kernel-parameters.yml'
ansible.builtin.import_tasks: ../../RedHat/generic/configure-kernel-parameters.yml
tags:
- sap_general_preconfigure_kernel_parameters
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@
- name: Assert 2002167-5
ansible.builtin.debug:
msg: "SAP note 2002167 Step 5: Process Resource Limits"
tags:
- sap_general_preconfigure_nproc_limits

- name: Import tasks from '../../RedHat/generic/assert-limits-conf-file.yml'
ansible.builtin.import_tasks: ../../RedHat/generic/assert-limits-conf-file.yml
tags:
- sap_general_preconfigure_nproc_limits

- name: Import tasks from '../../RedHat/generic/assert-nproc-limits.yml'
ansible.builtin.import_tasks: ../../RedHat/generic/assert-nproc-limits.yml
tags:
- sap_general_preconfigure_nproc_limits
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
- name: Configure 2002167-5
ansible.builtin.debug:
msg: "SAP note 2002167 Step 5: Process Resource Limits"
tags:
- sap_general_preconfigure_nproc_limits

- name: Import tasks from '../../RedHat/generic/increase-nproc-limits.yml'
ansible.builtin.import_tasks: ../../RedHat/generic/increase-nproc-limits.yml
tags:
- sap_general_preconfigure_nproc_limits
Loading
Loading