Example Ansible Playbook v7.4
A sample Ansible playbook to install a WarehousePG software release onto the hosts that will comprise a WarehousePG cluster.
This Ansible playbook shows how tasks described in [Installing WarehousePG]() might be automated using Ansible.
Important This playbook is provided as an example only to illustrate how WarehousePG cluster configuration and software installation tasks can be automated using provisioning tools such as Ansible, Chef, or Puppet. Presented as an example.
The example playbook is designed for use with RedHat. It creates the gpadmin user, installs the WarehousePG software release, sets the owner and group of the installed software to gpadmin, and sets the Pam security limits for the gpadmin user.
You can revise the script to work with your operating system platform and to perform additional host configuration tasks.
Following are steps to use this Ansible playbook.
Install Ansible on the control node using your package manager. See the Ansible documentation for help with installation.
Set up passwordless SSH from the control node to all hosts that will be a part of the WarehousePG cluster. You can use the
ssh-copy-idcommand to install your public SSH key on each host in the cluster. Alternatively, your provisioning software may provide more convenient ways to securely install public keys on multiple hosts.Create an Ansible inventory by creating a file called
hostswith a list of the hosts that will comprise your WarehousePG cluster. For example:cdw sdw1 sdw2 ...
This file can be edited and used with the WarehousePG
gpssh-exkeysandgpinitsystemutilities later on.Copy the playbook code below to a file
ansible-playbook.ymlon your Ansible control node.Edit the playbook variables at the top of the playbook, such as the
gpadminadministrative user and password to create, and the version of WarehousePG you are installing.Run the playbook, passing the package to be installed to the
package_pathparameter.ansible-playbook ansible-playbook.yml -i hosts -e package_path=./greenplum-db-7.0.0-rhel8-x86_64.rpm
Ansible Playbook - WarehousePG Installation for RedHat
---
- hosts: all
vars:
- version: "7.0.0"
- greenplum_admin_user: "gpadmin"
- greenplum_admin_password: "changeme"
# - package_path: passed via the command line with: -e package_path=./greenplum-db-7.0.0-rhel8-x86_64.rpm
remote_user: root
become: yes
become_method: sudo
connection: ssh
gather_facts: yes
tasks:
- name: create greenplum admin user
user:
name: "{{ greenplum_admin_user }}"
password: "{{ greenplum_admin_password | password_hash('sha512', 'DvkPtCtNH+UdbePZfm9muQ9pU') }}"
- name: copy package to host
copy:
src: "{{ package_path }}"
dest: /tmp
- name: install package
yum:
name: "/tmp/{{ package_path | basename }}"
state: present
- name: cleanup package file from host
file:
path: "/tmp/{{ package_path | basename }}"
state: absent
- name: find install directory
find:
paths: /usr/local
patterns: 'greenplum*'
file_type: directory
register: installed_dir
- name: change install directory ownership
file:
path: '{{ item.path }}'
owner: "{{ greenplum_admin_user }}"
group: "{{ greenplum_admin_user }}"
recurse: yes
with_items: "{{ installed_dir.files }}"
- name: update pam_limits
pam_limits:
domain: "{{ greenplum_admin_user }}"
limit_type: '-'
limit_item: "{{ item.key }}"
value: "{{ item.value }}"
with_dict:
nofile: 524288
nproc: 131072
- name: find installed greenplum version
shell: . /usr/edb/whpg7/greenplum_path.sh && /usr/edb/whpg7/bin/postgres --gp-version
register: postgres_gp_version
- name: fail if the correct greenplum version is not installed
fail:
msg: "Expected greenplum version {{ version }}, but found '{{ postgres_gp_version.stdout }}'"
when: "version is not defined or version not in postgres_gp_version.stdout"When the playbook has run successfully, you can proceed with Creating the Data Storage Areas and Initializing WarehousePG.
Parent topic: Installing and Upgrading WarehousePG