|
9 | 9 | tags: |
10 | 10 | - assert |
11 | 11 |
|
| 12 | +- name: Warn if old style password variable is used |
| 13 | + ansible.builtin.debug: |
| 14 | + msg: '[WARNING]: do not use rman_password in oracle_databases, use dbpasswords[rman_tnsname][rman_user] instead!' |
| 15 | + # make warning red, but continue |
| 16 | + failed_when: true |
| 17 | + # noqa ignore-errors |
| 18 | + ignore_errors: true |
| 19 | + when: item.rman_password is defined |
| 20 | + with_items: |
| 21 | + - "{{ oracle_databases }}" |
| 22 | + loop_control: |
| 23 | + label: "{{ item.oracle_db_name | default('') }}" |
| 24 | + |
12 | 25 | # autofs is configured in a special way to mount the shares with needed parameters |
13 | 26 | - name: configure autofs for RMAN |
14 | 27 | ansible.builtin.lineinfile: |
15 | | - dest=/etc/auto.master |
16 | | - regexp="^{{ rmanautofsmount }} " |
17 | | - line="{{ rmanautofsmount }} /etc/auto.net --timeout=60 rw,hard,rsize=32768,wsize=32768,proto=tcp,nfsvers=3" |
| 28 | + dest: "/etc/auto.master" |
| 29 | + regexp: "^{{ rmanautofsmount }} " |
| 30 | + line: "{{ rmanautofsmount }} /etc/auto.net --timeout=60 rw,hard,rsize=32768,wsize=32768,proto=tcp,nfsvers=3" |
18 | 31 | when: rmanautofs |
19 | 32 | tags: autofs |
20 | 33 |
|
21 | 34 | - name: Create Mountpoint |
22 | | - ansible.builtin.file: dest={{ rmanautofsmount }} state=directory mode=0755 |
| 35 | + ansible.builtin.file: |
| 36 | + dest: "{{ rmanautofsmount }}" |
| 37 | + state: directory |
| 38 | + mode: '0755' |
23 | 39 | when: rmanautofs |
24 | 40 | tags: autofs |
25 | 41 |
|
26 | 42 | - name: Restart autofs |
27 | | - ansible.builtin.service: name=autofs enabled=yes state=restarted |
| 43 | + ansible.builtin.service: |
| 44 | + name: autofs |
| 45 | + enabled: true |
| 46 | + state: restarted |
28 | 47 | when: rmanautofs |
29 | 48 | tags: autofs |
30 | 49 |
|
31 | 50 | - name: Create bin-Directory for rman_backup |
32 | | - ansible.builtin.file: path={{ oracle_base }}/bin state=directory mode=0755 |
| 51 | + ansible.builtin.file: |
| 52 | + path: "{{ oracle_base }}/bin" |
| 53 | + state: directory |
| 54 | + mode: '0755' |
33 | 55 | tags: |
34 | 56 | - rmancopy |
35 | 57 |
|
36 | 58 | - name: Create log-Directory for cron output |
37 | | - ansible.builtin.file: path={{ rman_cron_logdir }} state=directory mode=0755 owner={{ oracle_user }} |
| 59 | + ansible.builtin.file: |
| 60 | + path: "{{ rman_cron_logdir }}" |
| 61 | + state: directory |
| 62 | + mode: '0755' |
| 63 | + owner: "{{ oracle_user }}" |
38 | 64 | tags: |
39 | 65 | - rmancron |
40 | 66 | - rmancopy |
41 | 67 |
|
42 | 68 | # dummy with_together for item.0.db_name in default/main.yml |
43 | 69 | - name: Create Directory for rman-scripts |
44 | | - ansible.builtin.file: path={{ rman_script_dir }} state=directory mode=0755 owner={{ oracle_user }} |
| 70 | + ansible.builtin.file: |
| 71 | + path: "{{ rman_script_dir }}" |
| 72 | + state: directory |
| 73 | + mode: '0755' |
| 74 | + owner: "{{ oracle_user }}" |
45 | 75 | with_together: |
46 | 76 | - "{{ oracle_databases }}" |
47 | 77 | - "" |
|
52 | 82 |
|
53 | 83 | # dummy with_together for item.0.db_name in default/main.yml |
54 | 84 | - name: Create Directory for rman-logfiles |
55 | | - ansible.builtin.file: path={{ rman_log_dir }} state=directory mode=0755 owner={{ oracle_user }} |
| 85 | + ansible.builtin.file: |
| 86 | + path: "{{ rman_log_dir }}" |
| 87 | + state: "directory" |
| 88 | + mode: '0755' |
| 89 | + owner: "{{ oracle_user }}" |
56 | 90 | with_together: |
57 | 91 | - "{{ oracle_databases }}" |
58 | 92 | - "" |
|
62 | 96 | - rmancopy |
63 | 97 |
|
64 | 98 | - name: copy rman_backup.sh |
65 | | - ansible.builtin.copy: dest={{ oracle_base }}/bin src=rman_backup.sh backup=yes mode=755 |
| 99 | + ansible.builtin.copy: |
| 100 | + dest: "{{ oracle_base }}/bin" |
| 101 | + src: "rman_backup.sh" |
| 102 | + backup: true |
| 103 | + mode: '0755' |
66 | 104 | tags: |
67 | 105 | - rmancopy |
68 | 106 |
|
69 | 107 | # rman_script_dir: {{oracle_admin_db}}/rman/ |
70 | 108 | - name: copy RMAN scipts |
71 | | - ansible.builtin.template: dest={{ rman_script_dir }}/{{ item.1.name }}.rman src={{ item.1.name }}.rman.j2 backup=yes mode=644 owner={{ oracle_user }} |
| 109 | + ansible.builtin.template: |
| 110 | + dest: "{{ rman_script_dir }}/{{ item.1.name }}.rman" |
| 111 | + src: "{{ item.1.name }}.rman.j2" |
| 112 | + backup: true |
| 113 | + mode: '0644' |
| 114 | + owner: "{{ oracle_user }}" |
72 | 115 | with_subelements: |
73 | 116 | - "{{ oracle_databases }}" |
74 | 117 | - rman_jobs |
|
79 | 122 | - rmancopy |
80 | 123 |
|
81 | 124 | - name: Create directory for TNS_ADMIN |
82 | | - ansible.builtin.file: dest={{ rman_tns_admin }} state=directory owner={{ oracle_user }} mode=0755 |
| 125 | + ansible.builtin.file: |
| 126 | + dest: "{{ rman_tns_admin }}" |
| 127 | + state: directory |
| 128 | + owner: "{{ oracle_user }}" |
| 129 | + mode: '0755' |
83 | 130 | with_items: |
84 | | - - "{{ oracle_databases }}" |
85 | | - when: item.rman_tnsalias is defined |
| 131 | + - "{{ oracle_databases | selectattr('rman_tnsalias','defined') | map(attribute='oracle_db_name') }}" |
86 | 132 | tags: |
87 | 133 | - tns |
88 | 134 |
|
89 | | -- name: copy sqlnet.ora for wallet |
90 | | - ansible.builtin.template: src=sqlnet.ora.j2 dest={{ rman_tns_admin }}/sqlnet.ora owner={{ oracle_user }} mode=0644 |
| 135 | +- name: Template sqlnet.ora for rman catalog wallet |
| 136 | + ansible.builtin.template: |
| 137 | + src: "sqlnet.ora.j2" |
| 138 | + dest: "{{ rman_tns_admin }}/sqlnet.ora" |
| 139 | + owner: "{{ oracle_user }}" |
| 140 | + mode: '0644' |
91 | 141 | with_items: |
92 | | - - "{{ oracle_databases }}" |
93 | | - when: item.rman_tnsalias is defined |
| 142 | + - "{{ oracle_databases | selectattr('rman_tnsalias','defined') | selectattr('rman_wallet','defined') }}" |
| 143 | + loop_control: |
| 144 | + label: "{{ item.oracle_db_name | default('') }}" |
| 145 | + when: item.rman_wallet |
94 | 146 | tags: |
95 | 147 | - tns |
96 | 148 |
|
97 | | -- name: copy tnsnames.ora for catalog |
98 | | - ansible.builtin.template: src=tnsnames.ora.j2 dest={{ rman_tns_admin }}/tnsnames.ora owner={{ oracle_user }} mode=644 backup=true |
99 | | - with_items: |
| 149 | +- name: Template tnsnames.ora for rman catalog |
| 150 | + ansible.builtin.blockinfile: |
| 151 | + block: "{{ lookup('template', '../../oradb_manage_db/templates/tnsnames' + oracle_tnsnames_config[tnsinst.tnsname]['tnstemplate'] | default('') + '.ora.j2') }}" |
| 152 | + path: "{{ rman_tns_admin }}/tnsnames.ora" |
| 153 | + backup: true |
| 154 | + create: true |
| 155 | + group: "{{ oracle_group }}" |
| 156 | + owner: "{{ oracle_user }}" |
| 157 | + state: present |
| 158 | + mode: 0644 |
| 159 | + insertafter: "EOF" |
| 160 | + marker: "# {mark} Ansible managed for {{ tnsinst.tnsname }}" |
| 161 | + vars: |
| 162 | + dbh: "{{ item.0 }}" |
| 163 | + tnsinst: "{{ item.1 }}" |
| 164 | + with_nested: |
100 | 165 | - "{{ oracle_databases }}" |
101 | | - when: item.rman_tnsalias is defined |
| 166 | + - "{{ tnsnames_installed }}" |
| 167 | + loop_control: |
| 168 | + label: "{{ dbh.oracle_db_name | default('') }} -> {{ tnsinst.tnsname | default('') }}" |
| 169 | + when: |
| 170 | + - dbh.rman_tnsalias is defined |
| 171 | + - dbh.home == tnsinst.home |
| 172 | + - tnsinst.tnsname == dbh.rman_tnsalias |
102 | 173 | tags: |
103 | 174 | - tns |
104 | 175 |
|
105 | 176 | - name: Wallet create |
106 | | - ansible.builtin.shell: "test -d {{ rman_wallet_loc }} || echo -e '{{ rman_wallet_password }}\n{{ rman_wallet_password }}' | {{ oracle_home_db }}/bin/mkstore -create -nologo -wrl {{ rman_wallet_loc }}" |
107 | | - # noqa risky-shell-pipe yaml |
| 177 | + ansible.builtin.shell: |
| 178 | + cmd: 'echo -e "$stdin" | {{ oracle_home_db }}/bin/mkstore -create -nologo -wrl "{{ rman_wallet_loc }}"' |
| 179 | + creates: "{{ rman_wallet_loc }}/ewallet.p12" |
108 | 180 | become: true |
109 | 181 | become_user: "{{ oracle_user }}" |
| 182 | + environment: |
| 183 | + stdin: "{{ rman_wallet_password }}\n{{ rman_wallet_password }}" |
110 | 184 | with_items: |
111 | | - - "{{ oracle_databases }}" |
112 | | - when: item.rman_tnsalias is defined |
| 185 | + - "{{ oracle_databases | selectattr('rman_tnsalias','defined') | selectattr('rman_wallet','defined') }}" |
| 186 | + loop_control: |
| 187 | + label: "{{ item.oracle_db_name | default('') }}" |
| 188 | + when: item.rman_wallet |
113 | 189 | tags: |
114 | 190 | - wallet |
| 191 | + register: wallet_created |
| 192 | + |
| 193 | +- name: List wallet contents |
| 194 | + ansible.builtin.shell: |
| 195 | + cmd: 'echo "$stdin" | {{ oracle_home_db }}/bin/mkstore -listCredential -nologo -wrl "{{ rman_wallet_loc }}"' |
| 196 | + become: true |
| 197 | + become_user: "{{ oracle_user }}" |
| 198 | + environment: |
| 199 | + stdin: "{{ rman_wallet_password }}" |
| 200 | + with_items: |
| 201 | + - "{{ oracle_databases | selectattr('rman_tnsalias','defined') | selectattr('rman_wallet','defined') }}" |
| 202 | + when: |
| 203 | + - item.rman_wallet |
| 204 | + - not wallet_created.changed |
| 205 | + changed_when: false # does not change anything in System |
| 206 | + loop_control: |
| 207 | + label: "{{ item.oracle_db_name | default('') }}" |
| 208 | + tags: |
| 209 | + - wallet |
| 210 | + register: wallet_contents |
115 | 211 |
|
116 | | -# no_log => secure password against logfiles |
117 | | -# ignore errors during createCredential when entry is existing |
118 | 212 | - name: Wallet createCredential |
119 | | - ansible.builtin.shell: "echo -e '{{ rman_wallet_password }}' | {{ oracle_home_db }}/bin/mkstore -wrl {{ rman_wallet_loc }} -nologo -createCredential {{ item.rman_tnsalias }} {{ item.rman_user }} {{ item.rman_password }}; exit 0" |
120 | | - # noqa yaml risky-shell-pipe |
| 213 | + ansible.builtin.shell: |
| 214 | + cmd: 'echo "$stdin" | {{ oracle_home_db }}/bin/mkstore -wrl "{{ rman_wallet_loc }}" -nologo -createCredential "$rman_tnsalias" "$rman_user" "$rman_password"' |
121 | 215 | become: true |
122 | 216 | become_user: "{{ oracle_user }}" |
123 | | - no_log: true |
| 217 | + environment: |
| 218 | + stdin: "{{ rman_wallet_password }}" |
| 219 | + rman_tnsalias: "{{ item.rman_tnsalias }}" |
| 220 | + rman_user: "{{ item.rman_user }}" |
| 221 | + rman_password: "{{ dbpasswords[item.rman_tnsalias][item.rman_user] | default(item.rman_password) }}" |
124 | 222 | with_items: |
125 | | - - "{{ oracle_databases }}" |
126 | | - when: item.rman_tnsalias is defined and item.rman_user is defined and item.rman_password is defined |
| 223 | + - "{{ oracle_databases | selectattr('rman_tnsalias','defined') | selectattr('rman_wallet','defined') }}" |
| 224 | + when: |
| 225 | + - item.rman_wallet |
| 226 | + - "wallet_created.changed or ((': ' + item.rman_tnsalias + ' ' + item.rman_user) not in (wallet_contents.results[loopidx].stdout | default('')))" |
| 227 | + loop_control: |
| 228 | + label: "{{ item.oracle_db_name | default('') }}" |
| 229 | + index_var: loopidx |
| 230 | + register: wallet_credential_added |
| 231 | + tags: |
| 232 | + - wallet |
| 233 | + |
| 234 | +- name: Wallet modifyCredential to ensure password is up to date |
| 235 | + ansible.builtin.shell: |
| 236 | + cmd: 'echo "$stdin" | {{ oracle_home_db }}/bin/mkstore -wrl "{{ rman_wallet_loc }}" -nologo -modifyCredential "$rman_tnsalias" "$rman_user" "$rman_password"' |
| 237 | + become: true |
| 238 | + become_user: "{{ oracle_user }}" |
| 239 | + changed_when: false # no simple way to figure out whether this changed the password or not, does not matter. |
| 240 | + environment: |
| 241 | + stdin: "{{ rman_wallet_password }}" |
| 242 | + rman_tnsalias: "{{ item.rman_tnsalias }}" |
| 243 | + rman_user: "{{ item.rman_user }}" |
| 244 | + rman_password: "{{ dbpasswords[item.rman_tnsalias][item.rman_user] | default(item.rman_password) }}" |
| 245 | + with_items: |
| 246 | + - "{{ oracle_databases | selectattr('rman_tnsalias','defined') | selectattr('rman_wallet','defined') }}" |
| 247 | + when: |
| 248 | + - item.rman_wallet |
| 249 | + - not wallet_created.changed |
| 250 | + - not wallet_credential_added.changed |
| 251 | + loop_control: |
| 252 | + label: "{{ item.oracle_db_name | default('') }}" |
127 | 253 | tags: |
128 | 254 | - wallet |
129 | 255 |
|
|
133 | 259 | # The task is only execute once on master_node when GI is installed! |
134 | 260 | # no catalog connection, because setting initial parameters with catalog takes much more time |
135 | 261 | - name: Execute RMAN-Script at playbook |
| 262 | + # noqa risky-shell-pipe |
136 | 263 | ansible.builtin.shell: "{{ oracle_base }}/bin/rman_backup.sh -a {{ item.1.name }} -s {{ item.0.oracle_db_instance_name | default(item.0.oracle_db_name) }} -r {{ rman_script_dir }} -l {{ rman_log_dir }} | tee -a {{ rman_cron_logdir }}/rman_{{ item.1.name }}.log" |
137 | | - # noqa risky-shell-pipe yaml |
138 | 264 | environment: |
139 | 265 | PATH: /bin:/usr/bin |
140 | 266 | become: true |
|
146 | 272 | - skip_missing: true |
147 | 273 | loop_control: |
148 | 274 | label: "oracle_db_name {{ item.0.oracle_db_name | default('') }} job {{ item.1.name | default('') }}" |
149 | | - when: item.1.immediate is defined and item.1.immediate |
150 | | - and ( (configure_cluster and inventory_hostname == cluster_master) |
151 | | - or not configure_cluster |
152 | | - ) |
| 275 | + when: |
| 276 | + - item.1.immediate is defined |
| 277 | + - item.1.immediate |
| 278 | + - "((configure_cluster and inventory_hostname == cluster_master) or not configure_cluster )" |
153 | 279 | tags: |
154 | 280 | - rmanexecute |
155 | 281 |
|
156 | | -- ansible.builtin.debug: msg={{ item.results.stdout_lines | default("") }} # noqa unnamed-task |
| 282 | +- name: RMAN-Script at playbook output # noqa no-handler |
| 283 | + ansible.builtin.debug: |
| 284 | + msg: "{{ item.stdout_lines }}" |
157 | 285 | with_items: |
158 | | - - "{{ rmanexecimmediate }}" |
| 286 | + - "{{ rmanexecimmediate.results }}" |
| 287 | + when: item.changed |
159 | 288 | loop_control: |
160 | | - label: "" |
161 | | - when: rmanexecimmediate is defined |
| 289 | + label: "oracle_db_name {{ item.item[0].oracle_db_name | default(' ') }} job {{ item.item[1].name | default('') }}" |
162 | 290 | tags: |
163 | 291 | - rmanexecute |
164 | 292 |
|
165 | | -- name: Add Environment variables to /ec/cron.d |
| 293 | +- name: Add Environment variables to /etc/cron.d |
166 | 294 | ansible.builtin.cron: |
167 | 295 | cron_file: "{{ rman_cronfile }}" |
168 | 296 | user: "{{ oracle_user }}" |
|
206 | 334 | - rmancron |
207 | 335 |
|
208 | 336 | - name: Create directory for mk-job |
209 | | - ansible.builtin.file: dest=/var/lib/check_mk_agent/job/{{ oracle_user }} state=directory owner={{ oracle_user }} mode=0755 |
| 337 | + ansible.builtin.file: |
| 338 | + dest: "/var/lib/check_mk_agent/job/{{ oracle_user }}" |
| 339 | + state: directory |
| 340 | + owner: "{{ oracle_user }}" |
| 341 | + mode: '0755' |
210 | 342 | when: rman_cron_mkjob |
211 | 343 | tags: rmancron |
0 commit comments