Skip to content

Commit 9589515

Browse files
Dba 814 tnsname (#480)
* Fix get OEM server name wrap issue and pass OEM secret variable * Adjust jq command for Oem account id
1 parent a239d39 commit 9589515

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

playbooks/oracle_backup/get_facts.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,15 @@
3333
- name: Set Emcli Catalog Host Name Command
3434
set_fact:
3535
emcli_commands: |
36-
{{ emcli }} get_targets -noheader -targets="%:oracle_oms" | awk '{print $NF}' | cut -d: -f1
36+
{{ emcli }} get_targets -noheader -targets="%:oracle_oms" | awk '{print $NF}' | cut -d: -f1 | head -1
3737
3838
- name: Get Catalog Host Name
3939
ansible.builtin.command: >
4040
/u02/stage/get_facts_script.sh
4141
environment:
4242
ACCOUNT_NAME: "{{ account_name }}"
4343
ASSUME_ROLE_NAME: "{{ assume_role_name }}"
44+
OEM_SECRET: "{{ secretsmanager_passwords['emrep'].secret }}"
4445
EMCLI_COMMANDS: "{{ emcli_commands }}"
4546
register: getcataloghostname
4647
changed_when: false
@@ -63,7 +64,7 @@
6364
environment:
6465
ACCOUNT_NAME: "{{ account_name }}"
6566
ASSUME_ROLE_NAME: "{{ assume_role_name }}"
66-
CATALOG_SECRET: "{{ secretsmanager_passwords['catalog'].secret }}"
67+
OEM_SECRET: "{{ secretsmanager_passwords['emrep'].secret }}"
6768
EMCLI_COMMANDS: "{{ emcli_commands }}"
6869
register: getslackchannel
6970
changed_when: false

playbooks/oracle_backup/templates/get_facts_script.sh.j2

+8-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
. ~/.bash_profile
44

5-
OEM_ACCOUNT_ID=$(aws ssm get-parameters --with-decryption --name account_ids | jq --arg ACCOUNT_NAME ${ACCOUNT_NAME} -r 'with_entries(if (.key|test($ACCOUNT_NAME)) then ( {key: .key, value: .value}) else empty end)' | jq -r 'to_entries|.[0].value')
5+
OEM_ACCOUNT_ID=$(aws ssm get-parameters --with-decryption --name account_ids | jq -r .Parameters[].Value | jq --arg ACCOUNT_NAME ${ACCOUNT_NAME} -r 'with_entries(if (.key|test($ACCOUNT_NAME)) then ( {key: .key, value: .value}) else empty end)' | jq -r 'to_entries|.[0].value')
66
OEM_SECRET_ARN="arn:aws:secretsmanager:eu-west-2:${OEM_ACCOUNT_ID}:secret:${OEM_SECRET}"
77
ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
88
OEM_ROLE_ARN="arn:aws:iam::${ACCOUNT_ID}:role/${ASSUME_ROLE_NAME}"
@@ -11,12 +11,13 @@ export AWS_ACCESS_KEY_ID=$(echo "${CREDS}" | tail -1 | cut -f1)
1111
export AWS_SECRET_ACCESS_KEY=$(echo "${CREDS}" | tail -1 | cut -f2)
1212
export AWS_SESSION_TOKEN=$(echo "${CREDS}" | tail -1 | cut -f3)
1313

14-
SYSMAN_PASSWORD=$(aws secretsmanager get-secret-value --secret-id "${OEM_SECRET_ARN}" --query SecretString --output text | jq -r .sysman)
15-
export PATH=$PATH:/u01/app/oracle/product/oem-agent/agent_{{ OEM_AGENT_VERSION }}/oracle_common/jdk/jre/bin
16-
{{ emcli }} sync 1>/dev/null 2>&1 || ( {{ emcli }} login -username=sysman -password=${SYSMAN_PASSWORD} -force && {{ emcli }} sync ) 1>/dev/null 2>&1
17-
18-
[[ ! -z "${EMCLI_COMMANDS}" ]] && eval ${EMCLI_COMMANDS}
19-
if [[ "${STEP}" == "CONNECT_CATALOG" ]]
14+
if [[ ! -z "${EMCLI_COMMANDS}" ]]
15+
then
16+
SYSMAN_PASSWORD=$(aws secretsmanager get-secret-value --secret-id "${OEM_SECRET_ARN}" --query SecretString --output text | jq -r .sysman)
17+
export PATH=$PATH:/u01/app/oracle/product/oem-agent/agent_{{ OEM_AGENT_VERSION }}/oracle_common/jdk/jre/bin
18+
{{ emcli }} sync 1>/dev/null 2>&1 || ( {{ emcli }} login -username=sysman -password=${SYSMAN_PASSWORD} -force && {{ emcli }} sync ) 1>/dev/null 2>&1
19+
eval ${EMCLI_COMMANDS}
20+
elif [[ "${STEP}" == "CONNECT_CATALOG" ]]
2021
then
2122
RCVCATOWNER_PASSWORD=$(aws secretsmanager get-secret-value --secret-id "arn:aws:secretsmanager:eu-west-2:${OEM_ACCOUNT_ID}:secret:${CATALOG_SECRET}" --query SecretString --output text | jq -r .rcvcatowner)
2223
sqlplus -s /nolog << EOF

0 commit comments

Comments
 (0)