|
| 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 |
0 commit comments