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

Collection: Add playbook for direct execution #842

Merged
merged 24 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from 21 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
65 changes: 59 additions & 6 deletions playbooks/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,61 @@

# List of playbooks
# Ansible Collection Playbooks

- prepare-for-hana
- prepare-for-netweaver
- install-sap-hana
- install-sap-hana-cluster
- install-sap-hana-s4
The playbooks in this directory can be used as templates for your own playbooks
(starting with sample-) and some can be called directly with interactive variable collection
or included in your own playbooks or workflows.

## Usage of playbooks

### Prepare System for SAP HANA installation (sap_hana_prepare.yml/sap_hana_prepare_exec.yml)

This playbook collects information for preparing an SAP system for an SAP HANA installation.
Run the following command:

```[bash]
ansible-playbook community.sap_install.sap_hana_preconfigure.yml
```

This playbook runs against localhost and/or remote hosts.
Remote hosts can be defined in an inventory file, or with -i on the commandline e.g. `-i inventoryfile` or `-i host1,host2,host3,` and execution can be limited with -l.
You need to confirm the hosts in the interactive dialog.
When you call this playbook against a remote host make sure the user can connect and assume root without a password or pass the following parameters if necessary

```[bash]
-u <connection user>: User that establishes the ssh connection
-k: asks for password or passphrase of the connection user, if required for ssh
-K: asks for the privilege escalation password of the connection user to become root on the target host
```

If you want to embed this playbook or run a non-interactive version, you need to prepare an ansible inventory that contains a group for the hosts you want to install, e.g. my_hanas (see also <https://docs.ansible.com/ansible/latest/inventory_guide/intro_inventory.html>).

Create the file `my_inventory` similar to:

```[yaml]
[my_hanas]
hana1
hana2
```

Prepare a variable config file with the following parameters (adapt to your needs):
Create a parameter file `my_vars.yml` with similar content:

```[yaml]
# sap_playbook_parameter_confirm: false
sap_hana_group: 'my_hanas'
sap_domain: my.sap.domain
sap_general_preconfigure_modify_etc_hosts: true
sap_general_preconfigure_update: true
sap_general_preconfigure_fail_if_reboot_required: false
sap_hana_preconfigure_update: true
sap_hana_preconfigure_fail_if_reboot_required: false
sap_hana_preconfigure_reboot_ok: true
```

Now you can run the playbook non-interactively with

```[bash]
ansible-playbook community.sap_install.sap_hana_preconfigure_exec.yml -i my_inventory -e @my_vars.yml
```

NOTE: If you do not define the parameter `sap_hana_group` the playbook will run against all hosts in the inventory unless limited with `-l hostname' or localhost if no inventory is defined.
126 changes: 126 additions & 0 deletions playbooks/sap_hana_preconfigure.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
---
##
# Call this playbook interactively with
# ansible-playbook community.sap_install.sap_hana_preconfigure
#
# or alternatively unattended with
# ansible-playbook community.sap_install.sap_hana_preconfigure -e @myvars.yml
#
# The file myvars.yaml needs to contain the following variables
#
# please read README.md in playbooks folder for details
#
- name: Playbook Usage
hosts: localhost
gather_facts: false
tasks:
- name: Playbook Usage # noqa trailing-spaces
ansible.builtin.debug:
msg: |+
*****************************************************************************
* sap_hana_preconfigure *
* *
* This playbook is used to prepare an SAP HANA system. *
* The minimum viable parameters to successfully prepare your system for an *
* SAP HANA installation will be asked. *
* Useful defaults will be set, so that it is save to just press enter *
* *
* If you want to run these steps unattended, please use the playbook *
* sap_hana_preconfigure_exec.yml instead with a properly prepared variable *
* file. (See README for more details) *
*****************************************************************************

- name: Collecting Parameters for OS preparation or check to install SAP HANA
hosts: localhost
gather_facts: false

vars:
- sap_systems: "{{ (groups['all'] == []) | ternary ('localhost', 'all') }}"
# sap_systems: "{{ (groups['all'] == []) | ternary ('localhost', groups['all'] | join(',')) }}"

tasks:
- name: Get minimal facts
ansible.builtin.setup:
gather_subset:
- '!all'

- name: Target systems for hana installation
ansible.builtin.pause:
prompt: "Enter comma separated list of systems that you want to check or prepare for SAP HANA: [{{ sap_systems }}]"
echo: true
register: _sap_systems

- name: SAP server DNS domain must not be empty
ansible.builtin.pause:
prompt: "Enter DNS Domainname of your SAP systems: [{{ sap_domain | d(ansible_domain) }}]"
echo: true
register: _sap_domain

- name: Run mode
ansible.builtin.pause:
prompt: "Do you want to check the current setup only (assert mode)? (y/n) [n]"
echo: true
register: _assert_mode

- name: Input additional parameters if no assert mode is defined
when: _assert_mode.user_input != "y"
block:
- ansible.builtin.pause: # noqa name[missing] - role default true
prompt: "Do you want the system to update /etc/hosts for SAP? (y/n) [y]"
echo: true
register: _sap_update_hosts
- ansible.builtin.pause: # noqa name[missing] - role default false
prompt: "Do you want to update the system? (y/n) [n]"
echo: true
register: _sap_update
- ansible.builtin.pause: # noqa name[missing] - role default false
prompt: "Do you want to reboot the system if required? (y/n) [n]"
echo: true
register: _sap_reboot
- ansible.builtin.pause: # noqa name[missing] - role default true
prompt: "Do you want to stop with an error if the system needs a reboot? (y/n) [y]"
echo: true
register: _sap_fail_if_reboot_required
when: _sap_reboot.user_input != 'y'

- name: Prepare inventory
when:
- _sap_systems.user_input is defined
- _sap_systems.user_input| trim != ''
ansible.builtin.add_host:
groups: sap_hana_prepare_hosts
name: '{{ item }}'
loop: '{{ _sap_systems.user_input | split(",") | list }}'

- name: Configure Role Variables
ansible.builtin.set_fact:
sap_domain: '{{ ((_sap_domain.user_input | trim) != "") | ternary(_sap_domain.user_input, sap_domain | d(ansible_domain)) }}'
### redhat.sap_install.sap_general_preconfigure
sap_general_preconfigure_modify_etc_hosts: '{{ (_sap_update_hosts.user_input is defined) and (_sap_update_hosts.user_input == "n") | ternary(false, true) }}' # default true
sap_general_preconfigure_update: '{{ (_sap_update.user_input is defined) and (_sap_update.user_input == "y") | ternary(true, false) }}' # default false
sap_general_preconfigure_fail_if_reboot_required: '{{ (_sap_fail_if_reboot_required.user_input is defined) and (_sap_fail_if_reboot_required.user_input == "n") | ternary(false, true) }}' # default true
sap_general_preconfigure_assert: '{{ (_assert_mode.user_input == "y") | ternary(true, false) }}'
# sap_general_preconfigure_system_roles_collection: 'redhat.rhel_system_roles'
### redhat.sap_install.sap_hana_preconfigure
sap_hana_preconfigure_update: '{{ (_sap_update.user_input is defined) and (_sap_update.user_input == "y") | ternary(true, false) }}' # default false
sap_hana_preconfigure_fail_if_reboot_required: '{{ (_sap_fail_if_reboot_required.user_input is defined) and (_sap_fail_if_reboot_required.user_input == "n") | ternary(false, true) }}' # default true
sap_hana_preconfigure_reboot_ok: '{{ (_sap_reboot.user_input is defined) and (_sap_reboot.user_input == "y") | ternary(true, false) }}' # default false
sap_hana_preconfigure_assert: '{{ (_assert_mode.user_input == "y") | ternary(true, false) }}'
# sap_hana_preconfigure_system_roles_collection: 'redhat.rhel_system_roles'

- name: Run sap_hana_prepare_exec playbook
ansible.builtin.import_playbook: sap_hana_preconfigure_exec.yml
vars:
sap_playbook_parameter_confirm: true
sap_hana_group: "{{ (groups['sap_hana_prepare_hosts'] is defined) | ternary ('sap_hana_prepare_hosts',sap_systems) }}"
sap_domain: "{{ hostvars['localhost']['sap_domain'] }}"
sap_general_preconfigure_modify_etc_hosts: "{{ hostvars['localhost']['sap_general_preconfigure_modify_etc_hosts'] }}"
sap_general_preconfigure_update: "{{ hostvars['localhost']['sap_general_preconfigure_update'] }}"
sap_general_preconfigure_fail_if_reboot_required: "{{ hostvars['localhost']['sap_general_preconfigure_fail_if_reboot_required'] }}"
sap_general_preconfigure_assert: "{{ hostvars['localhost']['sap_general_preconfigure_assert'] }}"
sap_general_preconfigure_assert_ignore_errors: true
sap_hana_preconfigure_update: "{{ hostvars['localhost']['sap_hana_preconfigure_update'] }}"
sap_hana_preconfigure_fail_if_reboot_required: "{{ hostvars['localhost']['sap_hana_preconfigure_fail_if_reboot_required'] }}"
sap_hana_preconfigure_reboot_ok: "{{ hostvars['localhost']['sap_hana_preconfigure_reboot_ok'] }}"
sap_hana_preconfigure_assert: "{{ hostvars['localhost']['sap_hana_preconfigure_assert'] }}"
sap_hana_preconfigure_assert_ignore_errors: true
50 changes: 50 additions & 0 deletions playbooks/sap_hana_preconfigure_exec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
##
# Call this playbook only with all variables defined.
#
# The minimum viable set of variables which need to be defined are:
#
# sap_hana_group: name of group in inventory - defaults to localhost if not set
# sap_domain: SAP domain - defaults to ansible_domain if not set, but must not be empty
#
# for redhat.sap_install.sap_general_preconfigure
# sap_general_preconfigure_modify_etc_hosts: defaults to true
# sap_general_preconfigure_update: defaults to false
# sap_general_preconfigure_fail_if_reboot_required: defaults to true
#
# for redhat.sap_install.sap_hana_preconfigure
# sap_hana_preconfigure_update: defaults to false
# sap_hana_preconfigure_fail_if_reboot_required: defaults to true
# sap_hana_preconfigure_reboot_ok: defaults to false
#
# Please note: if the variable sap_playbook_parameter_confirm is set to true, the playbook
# stops execution and waits for an input. If you want to run the playbook in
# non-interactive mode, leave the variable unset or set to false.

- name: Prepare system for SAP HANA Installation
hosts: "{{ sap_hana_group | d((groups['all'] == []) | ternary ('localhost', 'all')) }}"
become: true
tasks:
- name: Ansible Role Configuration
ansible.builtin.debug:
msg: |-
The Hana setup runs with the following configuration
- 'Hostname : {{ sap_hostname | d(ansible_hostname) }}'
- 'IP Address : {{ sap_ip | d(ansible_default_ipv4.address) }}'
- 'Domain : {{ (sap_domain | d('') | length > 0) | ternary(sap_domain, ansible_domain) }}'
- 'Modify hosts : {{ sap_general_preconfigure_modify_etc_hosts | d('false') }}'
- 'Update OS : {{ sap_hana_preconfigure_update | d('false') }}'
- 'Auto Reboot : {{ sap_hana_preconfigure_reboot_ok | d('false') }}'
- 'Fail if reboot is needed: {{ sap_hana_preconfigure_fail_if_reboot_required | d('true') }}'

- name: Pause Playbook to verify parameters
when: sap_playbook_parameter_confirm | d(false)
ansible.builtin.pause:

- name: Perform the general SAP configuration
ansible.builtin.include_role:
name: community.sap_install.sap_general_preconfigure

- name: Perform the SAP HANA specific configuration
ansible.builtin.include_role:
name: community.sap_install.sap_hana_preconfigure
Loading