Skip to content

Commit 3117600

Browse files
committed
Sample Ansible playbooks to deploy a DPF instance
1 parent b7f0ef6 commit 3117600

12 files changed

+553
-0
lines changed

ansible/dpf/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
These are some sample Ansible playbooks to setup a Db2 DPF instance on a set of VMs.
2+
3+
The Db2 DPF instance uses NFS for the shared instance home directory.
4+
5+
The playbooks assume your storage is also virtualized.
6+
Meaning a VM exists that provides storage (via iSCSI) to the VMs running Db2.
7+
8+
See the [vars.yaml](playbooks/vars.yaml) file for how you can specify things like the IP
9+
addresses of the VMs, the name of the Db2 installation image, the number of MLNs per VM
10+
and more.
11+
12+
With VMs created, the following commands would run the playbooks to setup the DPF instance:
13+
14+
```shell
15+
ansible-playbook -i inventory.ini playbooks/vm_setup.yaml
16+
ansible-playbook -i inventory.ini playbooks/storage_host_setup.yaml
17+
ansible-playbook -i inventory.ini playbooks/storage_client_setup.yaml
18+
ansible-playbook -i inventory.ini playbooks/db2_dpf_setup.yaml
19+
ansible-playbook -i inventory.ini playbooks/db2_storage_setup.yaml
20+
```

ansible/dpf/inventory.ini

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# All hosts that can run Db2
2+
[db2_hosts]
3+
dbhost1
4+
dbhost2
5+
dbhost3
6+
dbhost4
7+
dbhost5
8+
dbhost6
9+
dbhost7
10+
dbhost8
11+
dbhost9
12+
dbhost10
13+
dbhost11
14+
dbhost12
15+
dbhost13
16+
dbhost14
17+
dbhost15
18+
dbhost16
19+
dbhost17
20+
dbhost18
21+
dbhost19
22+
dbhost20
23+
24+
# Only used if using a VM as a storage server.
25+
# If you have a real SAN, or access your storage some other way, you don't need this.
26+
[storage_host]
27+
dbhost-storage
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
---
2+
- hosts: db2_hosts
3+
any_errors_fatal: true
4+
gather_facts: true
5+
vars_files:
6+
- vars.yaml
7+
8+
tasks:
9+
10+
- name: Run play to install Db2
11+
include_tasks: db2_install.yaml
12+
13+
- name: Run play to setup shared home on NFS server
14+
when: inventory_hostname == groups['db2_hosts'][0]
15+
include_tasks: nfs_server_shared_home.yaml
16+
17+
- name: Run play to setup shared home on NFS clients
18+
include_tasks: nfs_client_shared_home.yaml
19+
20+
- name: Copy private ssh key for root to hosts
21+
copy:
22+
src: root_id_rsa
23+
dest: /root/.ssh/id_rsa
24+
mode: '0400'
25+
26+
- name: Copy public ssh key for root to hosts
27+
copy:
28+
src: root_id_rsa.pub
29+
dest: /root/.ssh/id_rsa.pub
30+
mode: '0400'
31+
32+
- name: Update authorized_keys for root
33+
authorized_key:
34+
user: root
35+
key: "{{ lookup('file', 'root_id_rsa.pub') }}"
36+
37+
- name: Update ssh_known_hosts
38+
blockinfile:
39+
path: /etc/ssh/ssh_known_hosts
40+
create: true
41+
insertafter: EOF
42+
block: |
43+
{% for host in groups['db2_hosts'] %}
44+
{{ hostvars[host]['ansible_default_ipv4']['address'] }} {{ 'ssh-rsa' }} {{hostvars[host]['ansible_ssh_host_key_rsa_public'] }}
45+
{{ hostvars[host]['ansible_hostname'] }} {{ 'ssh-rsa' }} {{hostvars[host]['ansible_ssh_host_key_rsa_public'] }}
46+
{% endfor %}
47+
48+
- name: Create Db2 Instance
49+
when: inventory_hostname == groups['db2_hosts'][0]
50+
command:
51+
cmd: /opt/ibm/db2/instance/db2icrt -u db2fenc1 db2inst1
52+
creates: /home/db2inst1/sqllib
53+
54+
- name: Create .ssh dir for db2inst1
55+
when: inventory_hostname == groups['db2_hosts'][0]
56+
file:
57+
path: /home/db2inst1/.ssh
58+
state: directory
59+
mode: '0700'
60+
owner: db2inst1
61+
group: db2inst1
62+
63+
- name: Copy private ssh key for db2inst1 to hosts
64+
when: inventory_hostname == groups['db2_hosts'][0]
65+
copy:
66+
src: db2inst1_id_rsa
67+
dest: /home/db2inst1/.ssh/id_rsa
68+
mode: '0400'
69+
owner: db2inst1
70+
group: db2inst1
71+
72+
- name: Copy public ssh key for db2inst1 to hosts
73+
when: inventory_hostname == groups['db2_hosts'][0]
74+
copy:
75+
src: db2inst1_id_rsa.pub
76+
dest: /home/db2inst1/.ssh/id_rsa.pub
77+
mode: '0400'
78+
owner: db2inst1
79+
group: db2inst1
80+
81+
- name: Update authorized_keys for db2inst1
82+
when: inventory_hostname == groups['db2_hosts'][0]
83+
become_user: db2inst1
84+
authorized_key:
85+
user: db2inst1
86+
key: "{{ lookup('file', 'db2inst1_id_rsa.pub') }}"
87+
88+
- name: Set SELinux boolean to allow passwordless ssh when home is on NFS
89+
seboolean:
90+
name: use_nfs_home_dirs
91+
state: true
92+
persistent: true
93+
94+
- name: Create db2nodes.cfg
95+
when: inventory_hostname == groups['db2_hosts'][0]
96+
copy:
97+
dest: /home/db2inst1/sqllib/db2nodes.cfg
98+
content: |
99+
{% for item in groups['db2_hosts'] | product(range(mlns_per_host)) %}
100+
{{ loop.index - 1 }} {{ hostvars[item[0]]['ansible_hostname'] }} {{ item[1] }}
101+
{% endfor %}
102+
owner: db2inst1
103+
group: db2inst1
104+
105+
- name: Remove entries from /etc/services
106+
lineinfile:
107+
path: /etc/services
108+
search_string: 'db2inst1'
109+
state: absent
110+
111+
# TODO Should use loop over mlns_per_host below
112+
- name: Add entries to /etc/services
113+
blockinfile:
114+
path: /etc/services
115+
insertafter: EOF
116+
block: |
117+
DB2_db2inst1 20016/tcp
118+
DB2_db2inst1_1 20017/tcp
119+
DB2_db2inst1_2 20018/tcp
120+
DB2_db2inst1_3 20019/tcp
121+
DB2_db2inst1_4 20020/tcp
122+
DB2_db2inst1_5 20021/tcp
123+
DB2_db2inst1_6 20022/tcp
124+
DB2_db2inst1_7 20023/tcp
125+
DB2_db2inst1_8 20024/tcp
126+
DB2_db2inst1_END 20025/tcp
127+
db2c_db2inst1 25010/tcp
128+
129+
# Need to open all non-privileged ports as per https://www.ibm.com/docs/en/db2/12.1.0?topic=support-packet-filter-firewalls
130+
# Here we just add all our hosts to the trusted zone
131+
- name: Add firewall rule for Db2
132+
firewalld:
133+
source: "{{ vm_ip_prefix }}.0/24"
134+
zone: trusted
135+
state: enabled
136+
permanent: yes
137+
immediate: yes
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
- name: Check for Db2 Install
2+
stat:
3+
path: /opt/ibm/db2
4+
register: db2_install_path
5+
6+
- name: Upload Db2 Image
7+
unarchive:
8+
src: "{{ db2_install_image }}"
9+
dest: /root
10+
creates: /root/server
11+
when: db2_install_path.stat.exists == False
12+
13+
# For pacemaker
14+
- name: Install Db2 Prereqs
15+
dnf:
16+
name:
17+
- ksh
18+
- python3-dnf-plugin-versionlock
19+
state: present
20+
21+
- name: Install Db2
22+
command:
23+
cmd: /root/server/db2_install -n -y -p SERVER -b /opt/ibm/db2
24+
creates: /opt/ibm/db2
25+
26+
- name: Remove installer files
27+
file:
28+
path: /root/server
29+
state: absent
30+
31+
- name: Create db2inst1 user
32+
user:
33+
name: db2inst1
34+
uid: 5000
35+
create_home: false
36+
37+
- name: Create db2fenc1 user
38+
user:
39+
name: db2fenc1
40+
uid: 5001
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
---
2+
- hosts: db2_hosts
3+
any_errors_fatal: true
4+
gather_facts: true
5+
vars_files:
6+
- vars.yaml
7+
8+
tasks:
9+
10+
- name: Create filesystem on data device
11+
filesystem:
12+
dev: "{{ '/dev/' }}{{ item.key }}"
13+
fstype: xfs
14+
opts: "{{ '-L DATA%04d' % item.value.model.split('_')[1] | int }}"
15+
loop: "{{ ansible_devices|dict2items }}"
16+
loop_control:
17+
label: "{{ item.value.model }}"
18+
when: "inventory_hostname == groups['db2_hosts'][0] and item.value.model != None and item.value.model.startswith('DB2DATA_')"
19+
20+
# This is not sufficient to pickup new labels, so we run udevadm below
21+
- name: Rescan iSCSI devices to pickup LABELs
22+
open_iscsi:
23+
rescan: true
24+
25+
- name: Run command to read the new fs labels
26+
command: udevadm trigger
27+
28+
- name: Update facts for devices so LABEL data is avaialble after filesystem create
29+
setup:
30+
gather_subset: devices
31+
32+
- name: Add data device filesystems to fstab
33+
mount:
34+
path: "{{ db2data_path }}/db2inst1/{{ item.value.links.labels[0] | replace('DATA', 'NODE') }}"
35+
src: "{{ 'LABEL=' }}{{ item.value.links.labels[0] }}"
36+
fstype: xfs
37+
opts: defaults,noauto
38+
state: present
39+
loop: "{{ ansible_devices|dict2items }}"
40+
loop_control:
41+
label: "{{ item.value.model }}"
42+
when: "item.value.model != None and item.value.model.startswith('DB2DATA_')"
43+
44+
- name: Mount needed data device filesystems for each host
45+
mount:
46+
path: "{{ db2data_path }}/db2inst1/{{ 'NODE%04d' % i }}"
47+
src: "{{ 'LABEL=' }}{{ 'DATA%04d' % i }}"
48+
state: mounted
49+
fstype: xfs
50+
loop: "{{ groups['db2_hosts'] | product(range(mlns_per_host)) }}"
51+
loop_control:
52+
index_var: i
53+
when: "item[0] == inventory_hostname"
54+
55+
- name: Set permissions on db2data path
56+
file:
57+
path: "{{ db2data_path }}"
58+
owner: db2inst1
59+
group: db2inst1
60+
recurse: true
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
- hosts: db2_hosts
3+
any_errors_fatal: true
4+
gather_facts: false
5+
vars_files:
6+
- vars.yaml
7+
8+
tasks:
9+
10+
- name: Drop Db2 Instance
11+
when: inventory_hostname == groups['db2_hosts'][0]
12+
command:
13+
cmd: /opt/ibm/db2/instance/db2idrop db2inst1
14+
removes: /home/db2inst1/sqllib
15+
16+
- name: Uninstall Db2
17+
command:
18+
cmd: /opt/ibm/db2/install/db2_deinstall -a
19+
removes: /opt/ibm/db2
20+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
- name: Install NFS package
2+
dnf:
3+
name: nfs-utils
4+
state: latest
5+
6+
- name: Mount shared home
7+
mount:
8+
path: /home/db2inst1
9+
src: "{{ groups['db2_hosts'][0] }}{{':'}}{{ shared_home_export }}"
10+
fstype: nfs
11+
opts: rw,sync,hard,nofail
12+
state: mounted
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
- name: Install NFS package
2+
dnf:
3+
name: nfs-utils
4+
state: latest
5+
6+
- name: Stop NFS server
7+
systemd:
8+
name: nfs-server
9+
state: stopped
10+
11+
- name: Create filesystem on shared home
12+
filesystem:
13+
dev: "{{ shared_home_dev }}"
14+
fstype: xfs
15+
opts: "-L SHARED_HOME"
16+
17+
- name: Mount shared home export
18+
mount:
19+
path: "{{ shared_home_export }}"
20+
src: "{{ shared_home_dev }}"
21+
fstype: xfs
22+
opts: defaults,nofail
23+
state: mounted
24+
25+
# XXX db2inst1 should be created by this point
26+
- name: Set permissions on shared home export
27+
file:
28+
path: "{{ shared_home_export }}"
29+
owner: db2inst1
30+
group: db2inst1
31+
32+
- name: Initialize db2inst1 home directory
33+
copy:
34+
src: /etc/skel/
35+
dest: /home/db2inst1
36+
force: false
37+
owner: db2inst1
38+
group: db2inst1
39+
40+
- name: Generate ssh key for db2inst1
41+
user:
42+
name: db2inst1
43+
uid: 5000
44+
create_home: false
45+
generate_ssh_key: true
46+
47+
- name: Setup /etc/exports
48+
blockinfile:
49+
path: /etc/exports
50+
create: true
51+
insertafter: EOF
52+
block: |
53+
{% for host in groups['db2_hosts'] %}
54+
{{ shared_home_export }} {{ host }}{{ '(rw,no_root_squash)' }}
55+
{% endfor %}
56+
57+
- name: Add firewall rule for NFS server
58+
firewalld:
59+
state: enabled
60+
service: nfs
61+
permanent: yes
62+
immediate: yes
63+
64+
- name: Setup NFS server
65+
systemd:
66+
name: nfs-server
67+
state: restarted
68+
enabled: false

0 commit comments

Comments
 (0)