Skip to content

Commit

Permalink
sap_ha_install_anydb_ibmdb2: change cat in shell to set fact lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
sean-freeman committed Jul 16, 2024
1 parent 4be33ae commit 296a498
Showing 1 changed file with 10 additions and 17 deletions.
27 changes: 10 additions & 17 deletions roles/sap_ha_install_anydb_ibmdb2/tasks/passwordless_ssh.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,23 +75,16 @@
register: __sap_ha_install_anydb_ibmdb2_secondary_ssh_fingerprint
when: sap_ha_install_anydb_ibmdb2_hostname_secondary == inventory_hostname_short

# Reasons for noqa:
# - no-changed-when: Shell if logic to handle SSH Keys between hosts to align with IBM Db2 documentation
- name: SAP HA AnyDB - IBM Db2 HADR - Get contents of SSH Public Key for SAP AnyDB Primary node # noqa no-changed-when
ansible.builtin.shell: |
cat /root/.ssh/anydb_ibmdb2_hadr_{{ inventory_hostname_short }}.pub
register: __sap_ha_install_anydb_ibmdb2_primary_pubkey
- name: SAP HA AnyDB - IBM Db2 HADR - Get contents of SSH Public Key for SAP AnyDB Primary
ansible.builtin.set_fact:
__sap_ha_install_anydb_ibmdb2_primary_pubkey: "{{ lookup('ansible.builtin.file', '/root/.ssh/anydb_ibmdb2_hadr_' + inventory_hostname_short + '.pub') }}"
when: sap_ha_install_anydb_ibmdb2_hostname_primary == inventory_hostname_short

# Reasons for noqa:
# - no-changed-when: Shell if logic to handle SSH Keys between hosts to align with IBM Db2 documentation
- name: SAP HA AnyDB - IBM Db2 HADR - Get contents of SSH Public Key for SAP AnyDB Secondary node # noqa no-changed-when
ansible.builtin.shell: |
cat /root/.ssh/anydb_ibmdb2_hadr_{{ inventory_hostname_short }}.pub
register: __sap_ha_install_anydb_ibmdb2_secondary_pubkey
- name: SAP HA AnyDB - IBM Db2 HADR - Get contents of SSH Public Key for SAP AnyDB Secondary node
ansible.builtin.set_fact:
__sap_ha_install_anydb_ibmdb2_secondary_pubkey: "{{ lookup('ansible.builtin.file', '/root/.ssh/anydb_ibmdb2_hadr_' + inventory_hostname_short + '.pub') }}"
when: sap_ha_install_anydb_ibmdb2_hostname_secondary == inventory_hostname_short


- name: SAP HA AnyDB - IBM Db2 HADR - Inject SAP AnyDB Secondary node SSH Fingerprint to SSH known_hosts file on SAP AnyDB Primary node - root user
ansible.builtin.lineinfile:
backup: true
Expand Down Expand Up @@ -122,7 +115,7 @@
path: /root/.ssh/authorized_keys
owner: root
group: root
line: "{{ hostvars[sap_ha_install_anydb_ibmdb2_hostname_secondary].__sap_ha_install_anydb_ibmdb2_secondary_pubkey.stdout }}"
line: "{{ hostvars[sap_ha_install_anydb_ibmdb2_hostname_secondary].__sap_ha_install_anydb_ibmdb2_secondary_pubkey }}"
when: sap_ha_install_anydb_ibmdb2_hostname_primary == inventory_hostname_short

- name: SAP HA AnyDB - IBM Db2 HADR - Inject SSH Public Key to SSH authorized_keys file on SAP AnyDB Primary node - IBM Db2 Database Administrator
Expand All @@ -133,7 +126,7 @@
path: /db2/db2{{ sap_ha_install_anydb_ibmdb2_sid | lower }}/.ssh/authorized_keys
owner: db2{{ sap_ha_install_anydb_ibmdb2_sid | lower }}
group: db{{ sap_ha_install_anydb_ibmdb2_sid | lower }}adm
line: "{{ hostvars[sap_ha_install_anydb_ibmdb2_hostname_secondary].__sap_ha_install_anydb_ibmdb2_secondary_pubkey.stdout }}"
line: "{{ hostvars[sap_ha_install_anydb_ibmdb2_hostname_secondary].__sap_ha_install_anydb_ibmdb2_secondary_pubkey }}"
when: sap_ha_install_anydb_ibmdb2_hostname_primary == inventory_hostname_short

# Avoid use of default id_rsa file or SSH Agent (ssh-add)
Expand Down Expand Up @@ -195,7 +188,7 @@
path: /root/.ssh/authorized_keys
owner: root
group: root
line: "{{ hostvars[sap_ha_install_anydb_ibmdb2_hostname_primary].__sap_ha_install_anydb_ibmdb2_primary_pubkey.stdout }}"
line: "{{ hostvars[sap_ha_install_anydb_ibmdb2_hostname_primary].__sap_ha_install_anydb_ibmdb2_primary_pubkey }}"
when: sap_ha_install_anydb_ibmdb2_hostname_secondary == inventory_hostname_short

- name: SAP HA AnyDB - IBM Db2 HADR - Inject SSH Public Key to SSH authorized_keys file on SAP AnyDB Secondary node (authentication method publickey) - IBM Db2 Database Administrator
Expand All @@ -206,7 +199,7 @@
path: /db2/db2{{ sap_ha_install_anydb_ibmdb2_sid | lower }}/.ssh/authorized_keys
owner: db2{{ sap_ha_install_anydb_ibmdb2_sid | lower }}
group: db{{ sap_ha_install_anydb_ibmdb2_sid | lower }}adm
line: "{{ hostvars[sap_ha_install_anydb_ibmdb2_hostname_primary].__sap_ha_install_anydb_ibmdb2_primary_pubkey.stdout }}"
line: "{{ hostvars[sap_ha_install_anydb_ibmdb2_hostname_primary].__sap_ha_install_anydb_ibmdb2_primary_pubkey }}"
when: sap_ha_install_anydb_ibmdb2_hostname_secondary == inventory_hostname_short

# Avoid use of default id_rsa file or SSH Agent (ssh-add)
Expand Down

0 comments on commit 296a498

Please sign in to comment.