Replace an old OMC gateway server

There are three primary ways for cloud agents running on VMs to communicate with Oracle Management cloud:

1. Direct communication: When external communication to *.oraclecloud.com is allowed.
2. Proxy: When a proxy server is defined during the time of installation.
3. Gateway: When communication to Oracle Management Cloud is open via one or, more gateway servers/s and cloud agents rely on these gateway servers.

There can be times when a gateway server need to replaced. This can be because of many reasons, such as, accidental decommissioning, operating system or, hardware corruption etc. Now, installing or, re-installing a gateway is not that difficult. Please refer to this post for related instructions.

Now, once a new gateway server has been installed and registered to Oracle Management Cloud, you still need to update the your cloud agents to use the new gateway instead. Particularly in a multi-cloud agent environment, this task could quickly become tedious. You can use the below method to quickly update and the configuration of cloud agents running on multiple VMs.

Update gateway in existing cloud agents

Below is a simple ansible playbook to update gateway in existing cloud agents. The latest code is maintained in the git repository.

---
- hosts: all
  gather_facts: no
  vars:
    omc_user: "svc-omc"
    omc_install_path: "/opt/omc/agent/agent_inst/bin"
    gatewayurls: "https://<gatewayhost1>.<domain>.com:<gateway_port>/emd/gateway,https://<gatewayhost1>.<domain>.com:<gateway_port>/emd/gateway"

  tasks:
    - name: Update OMC Gateway URLs
      shell:
        chdir: "{{ omc_install_path }}"
        cmd: |
          sh ./omcli setproperty agent -name gatewayUrls -value "{{ gatewayurls }}"
      become: yes
      become_user: "{{omc_user}}"

    - name: Restart OMC agent
      shell:
        chdir: "{{ omc_install_path }}"
        cmd: |
          sh ./omcli stop agent && sh ./omcli start agent
      become: yes
      become_user: "{{omc_user}}"

Update the values for gatewayurls, omc_user and omc_install_path variables and execute the playbook.

ansible-playbook Update_OMC_Gateway.yml -i /var/lib/jenkins/library/ansible/inventories -l <server_name_to_limit_execution>
-bash-4.2$ ansible-playbook Update_OMC_Gateway.yml -i /var/lib/jenkins/library/ansible/inventories -l itnoesis1.itnoesis.com,itnoesis2.itnoesis.com

PLAY [all] ****************************************************************************************************************************************
Thursday 10 September 2020  14:45:57 -0500 (0:00:00.115)       0:00:00.115 ****

TASK [Update OMC Gateway URLs] ********************************************************************************************************************
changed: [itnoesis1.itnoesis.com]
changed: [itnoesis2.itnoesis.com]
Thursday 10 September 2020  14:46:05 -0500 (0:00:08.502)       0:00:08.618 ****

TASK [Restart OMC agent] **************************************************************************************************************************
changed: [itnoesis1.itnoesis.com]
changed: [itnoesis2.itnoesis.com]

PLAY RECAP ****************************************************************************************************************************************
itnoesis1.itnoesis.com : ok=2    changed=2    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
itnoesis2.itnoesis.com : ok=2    changed=2    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

Thursday 10 September 2020  14:46:24 -0500 (0:00:18.729)       0:00:27.347 ****
===============================================================================
Restart OMC agent ------------------------------------------------------------------------------------------------------------------------- 18.73s
Update OMC gateway URLs -------------------------------------------------------------------------------------------------------------------- 8.50s
Playbook run took 0 days, 0 hours, 0 minutes, 27 seconds