Skip to content

Commit 8ebb803

Browse files
committed
now using ansible stat to check for file existence on localhost. using "become: true" only where necesssary
1 parent 64f9cb6 commit 8ebb803

File tree

2 files changed

+42
-20
lines changed

2 files changed

+42
-20
lines changed

Diff for: check-oracle.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ do
115115
;;
116116

117117
--ahf-install)
118-
ORACLE_SID='NOOP'
118+
: ${ORACLE_SID=:'NOOP'}
119119
AHF_UNINSTALL=1
120120
AHF_INSTALL=1
121121
INSTALL_ENABLED=1
@@ -190,7 +190,7 @@ fi
190190
}
191191

192192
# fail early if the AFH file format is incorrect and/or the file does not exist.
193-
[[ -n "$AHF_LOCATION" ]] && {
193+
[[ -n "$AHF_LOCATION" ]] || [[ $AHF_INSTALL -eq 1 ]] && {
194194

195195
[[ ! "$AHF_LOCATION" =~ $AHF_LOCATION_PARAM ]] && {
196196
echo "Incorrect parameter provided for AHF_LOCATION: $AHF_LOCATION"

Diff for: check-oracle.yml

+40-18
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# check-oracle.yml
1616
- name: "ORAchk: uninstall, install or run"
1717
hosts: all
18-
become: true
18+
become: false
1919
gather_facts: false
2020
roles:
2121
- role: check-oracle
@@ -28,6 +28,7 @@
2828
register: ahfctl_script
2929

3030
- name: Uninstall AHF
31+
become: true
3132
shell: yes 'Y' | "{{ AHFCTL_PATH }}" uninstall
3233
when: (uninstall_ahf | bool) and ahfctl_script.stat.exists
3334
ignore_errors: true
@@ -52,65 +53,82 @@
5253
local_ahf_path: "/tmp/{{ AHF_LOCATION | basename }}"
5354
block:
5455

56+
# leave these here for testing
57+
# this has been a problem area
58+
#- name: Local AHF File
59+
#debug:
60+
#msg: "AHF File Source: {{ local_ahf_path }}"
61+
62+
#- name: Remote AHF File Dest
63+
#debug:
64+
#msg: "AHF File Dest: {{ ahf_extract_path }}/{{ AHF_LOCATION | basename }}"
65+
5566
- name: Download AHF file from Google Storage to the ansible control node.
5667
local_action:
5768
module: command
5869
cmd: "gsutil cp {{ AHF_LOCATION }} {{ local_ahf_path }}"
5970
register: gsutil_result
6071
changed_when: gsutil_result.rc == 0
6172

62-
- name: Check if {{ local_ahf_path }} is a zip file
63-
local_action:
64-
module: command
65-
cmd: unzip -l "{{ local_ahf_path }}"
66-
register: zip_check
67-
until: zip_check.rc == 0
68-
retries: 3 # Adjust the number of retries
69-
delay: 1 # Delay between retries
70-
failed_when: zip_check.rc != 0
71-
ignore_errors: true
73+
- name: Check if {{ local_ahf_path }} exists
74+
stat:
75+
path: "{{ local_ahf_path }}"
76+
register: file_status_check
77+
delegate_to: localhost
78+
79+
- name: File Status
80+
debug:
81+
msg: "file exists"
82+
when: file_status_check.stat.exists
83+
84+
- name: Fail if the file does not exist
85+
fail:
86+
msg: "File {{ local_ahf_path }} does not exist."
87+
when: not file_status_check.stat.exists
7288

7389
- name: Copy AHF file to remote host if it is a zip file.
90+
become: true
7491
copy:
7592
src: "{{ local_ahf_path }}"
7693
dest: "{{ ahf_extract_path }}/{{ AHF_LOCATION | basename }}"
77-
when: zip_check.rc == 0
94+
when: file_status_check.stat.exists == 0
7895

7996
- name: remove local AHF file.
8097
file:
8198
path: "{{ local_ahf_path }}"
8299
state: absent
83-
84-
rescue:
85-
- name: remove local AHF file on failure.
86-
file:
87-
path: "{{ local_ahf_path }}"
88-
state: absent
100+
delegate_to: localhost
89101

90102
- name: Unzip AHF file
103+
become: true
91104
unarchive:
92105
src: "{{ ahf_extract_path }}/{{ AHF_LOCATION | basename }}"
93106
dest: "{{ ahf_extract_path }}"
94107
remote_src: true
95108

96109
- name: Verify AHF setup signature
110+
become: true
97111
shell: openssl dgst -sha256 -verify ./oracle-tfa.pub -signature ./ahf_setup.dat ./ahf_setup
98112
args:
99113
chdir: "{{ ahf_extract_path }}"
100114

101115
- name: Ensure perl is installed
116+
become: true
102117
package:
103118
name: perl
104119
state: present
105120

106121
- name: Run AHF setup
122+
become: true
107123
shell: yes 'Y' | ./ahf_setup -extract -notfasetup
108124
args:
109125
chdir: "{{ ahf_extract_path }}"
110126
when: ( not ( uninstall_ahf | bool ) ) and ( not ( run_orachk | bool ) )
111127

112128
- block:
129+
113130
- name: Copy login.sql file to target system
131+
become: true
114132
copy:
115133
src: roles/check-oracle/files/login.sql
116134
dest: "{{ orachk_script_dir }}/login.sql"
@@ -119,6 +137,7 @@
119137
mode: '0600'
120138

121139
- name: Copy orachk-quicktest.sh for expedited testing
140+
become: true
122141
copy:
123142
src: roles/check-oracle/files/orachk-quicktest.sh
124143
dest: "{{ ORACHK_BASE }}/orachk/orachk-quicktest.sh"
@@ -128,6 +147,7 @@
128147
when: ( expedited_testing | bool )
129148

130149
- name: Configure Expedited Testing
150+
become: true
131151
shell: cd "{{ ORACHK_BASE }}/orachk/" && [[ ! -r orachk.orig ]] && mv orachk orachk.orig && ln -s orachk-quicktest.sh orachk
132152
when: ( expedited_testing | bool )
133153

@@ -182,6 +202,7 @@
182202
TMPFILE: "{{ lookup('pipe','mktemp') }}"
183203

184204
- name: Run ORAchk
205+
become: true
185206
shell: "ORACLE_PATH={{ orachk_script_dir }} SQLPATH={{ orachk_script_dir }} {{ ORACHK_BASE }}/orachk/orachk -s -dbconfig {{ ORACLE_HOME }}%{{ ORACLE_SID }} -showpass -profile dba | tee {{ TMPFILE }}"
186207
environment:
187208
ORACLE_SID: "{{ ORACLE_SID }}"
@@ -225,6 +246,7 @@
225246
register: fetch_result
226247

227248
- name: Deconfigure Expedited Testing
249+
become: true
228250
shell: cd "{{ ORACHK_BASE }}/orachk/" && [[ -r orachk.orig ]] && rm -f orachk && mv orachk.orig orachk && rm -f orachk-quicktest.sh
229251
when: ( expedited_testing | bool )
230252

0 commit comments

Comments
 (0)