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 all 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
68 changes: 62 additions & 6 deletions playbooks/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,64 @@

# List of playbooks
# Ansible Collection Playbooks

The playbooks starting with `sample-` in this directory can be used as examples for your own playbooksi and cannot be called directly from the commandline.
The other playbooks can be called directly with a prepared variable file or imported in your own playbooks or workflows.
The playbooks can run against localhost, all hosts or defined group.

## Usage of playbooks

### Prepare System for SAP HANA installation: `sap_hana_prepare_exec.yml`

This playbook runs against localhost and/or remote hosts.
You need to define the variable `sap_hana_group`to run this playbook against a particular group of hosts which is defined in your inventory.
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.

To run this playbook you need to prepare a variable file with a minimum viable set of variables.

#### Example:

Create a parameter file `my_vars.yml` with similar content:

```[yaml]
# sap_playbook_parameter_confirm: false # Set to true if you want to list parameters and confirm execution
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
```

Create the file `my_inventory` similar to:

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

Now you can run the playbook with

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

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

You can also call the playbook inside another playbook with:

```
- name: Include HANA preparation from collection for group my_hanas
ansible.builtin.import_playbook: community.sap_install.sap_hana_prepare_exec.yml
vars:
sap_hana_group: my_hanas
# add other vars here, or define somewhere else
```

- prepare-for-hana
- prepare-for-netweaver
- install-sap-hana
- install-sap-hana-cluster
- install-sap-hana-s4
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