From 75e9630a587e0554924f3b7885d30aa0a25172fd Mon Sep 17 00:00:00 2001 From: Madhavan Arnisethangaraj Date: Thu, 4 Jan 2024 23:45:10 +0530 Subject: [PATCH 1/5] Adding mgmt_agent_upgrade.yaml Adding mgmt_agent_upgrade.yaml to support agent upgrade --- deployment/ansible-playbooks/README.md | 11 +- .../ansible-playbooks/mgmt_agent_upgrade.yaml | 125 ++++++++++++++++++ 2 files changed, 135 insertions(+), 1 deletion(-) create mode 100644 deployment/ansible-playbooks/mgmt_agent_upgrade.yaml diff --git a/deployment/ansible-playbooks/README.md b/deployment/ansible-playbooks/README.md index 760a7cb..38e6d1d 100644 --- a/deployment/ansible-playbooks/README.md +++ b/deployment/ansible-playbooks/README.md @@ -7,6 +7,10 @@ The current playbooks works for linux based hosts, but this can be extended to o

## Pre-requisites +- Make sure ansible (version 2.9 or above version) is installed on localhost from where the deployment is initiated +refer: https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html +- Make sure python3 (version 3.6 or above version) is installed in all target hosts and localhost from where the deployment is initiated +refer: https://docs.python.org/3/using/unix.html#getting-and-installing-the-latest-version-of-python - Make sure you have SSH capability on the target hosts and the user connecting through SSH has the capability to become root. - You need to have OCI CLI installed and OCI configuration created only on the localhost from where the deployment is initiated.
refer: https://docs.oracle.com/en-us/iaas/Content/API/SDKDocs/cliinstall.htm#Quickstart @@ -37,6 +41,11 @@ export compartment_ocid= ansible-playbook -i hosts mgmt_agent_install.yaml -kK ``` +### Upgrading agent +``` +ansible-playbook -i hosts mgmt_agent_upgrade.yaml -kK +``` + ### Uninstalling agent ``` ansible-playbook -i hosts mgmt_agent_uninstall.yaml -kK @@ -64,4 +73,4 @@ localhost : ok=12 changed=1 unreachable=0 failed=0 s

## Copyright -Copyright (c) 2022 Oracle and/or its affiliates. \ No newline at end of file +Copyright (c) 2022 Oracle and/or its affiliates. diff --git a/deployment/ansible-playbooks/mgmt_agent_upgrade.yaml b/deployment/ansible-playbooks/mgmt_agent_upgrade.yaml new file mode 100644 index 0000000..ae236c4 --- /dev/null +++ b/deployment/ansible-playbooks/mgmt_agent_upgrade.yaml @@ -0,0 +1,125 @@ +# Copyright (c) 2021, 2024 Oracle and/or its affiliates. All rights reserved. +# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl. +# +--- + +# validations +- hosts: target_hosts + vars: + # common vars + tasks: + - name: collect facts about system services + service_facts: + + - name: Check if the mgmt_agent service is already installed + fail: + msg: "Management Agent is not installed in the host, hence upgrade is not required" + when: "'mgmt_agent.service' not in services" + + - name: Check if the mgmt_agent service is in running state + fail: + msg: "Management Agent installed in the host is not in running state" + when: "'mgmt_agent.service' not in services or ansible_facts.services['mgmt_agent.service'].state != 'running'" + +# workflows +- hosts: localhost + collections: + - oracle.oci + tasks: + - name: Check pre-requisites + fail: + msg: "Environment variable {{item}} not set. Please declare an environment variable with an appropriate value for the sample to work." + when: item not in ansible_env + with_items: + - "compartment_ocid" + + - name: Create a directory if it does not exist + ansible.builtin.file: + path: "./{{remote_mgmt_agent_scratch_dir}}" + state: directory + mode: '0755' + + - name: List Management Agent Images + oci_management_agent_image_facts: + compartment_id: "{{compartment_ocid}}" + install_type: AGENT + register: image_result + - set_fact: + object_url: "{{ item.object_url | split('/')}}" + namespace: "{{[4]|map('extract', item.object_url.split('/')) | join()}}" + bucket_name: "{{[6]|map('extract', item.object_url.split('/')) | join ()}}" + object_name: "{{[8,9,10]|map('extract', item.object_url.split('/')) | join('/')}}" + image_version: "{{ item.version }}" + + with_items: "{{image_result.management_agent_images}}" + when: + - item.platform_name == "Linux-x86_64" + - item.package_type == "RPM" + - debug: + msg: "Extracted the agent image details as follows Namespace: {{namespace}} Bucket: {{bucket_name}} Object name: {{object_name}} Agent Image Version : {{image_version}}" + + - name: Download Agent RPM object + oci_object_storage_object: + # required + namespace_name: "{{namespace}}" + bucket_name: "{{bucket_name}}" + object_name: "{{object_name}}" + dest: "./{{remote_mgmt_agent_scratch_dir}}/oracle.mgmt_agent.rpm" + tags: download_agent + +- hosts: target_hosts + vars: + # common vars + tasks: + - name: Check if upgrade operation is applicable for Management Agent + become: yes + ansible.builtin.shell: /opt/oracle/mgmt_agent/agent_inst/bin/agentcore version + register: agent_version + - set_fact: + host_agent_version: "{{ agent_version.stdout_lines }}" + - debug: + msg: "Management Agent Version : {{host_agent_version[0]}} Agent Image Version : {{hostvars['localhost']['image_version']}}" + - fail: + msg: "Management Agent is up-to-date with latest version of software available in production" + when: "host_agent_version[0] >= hostvars['localhost']['image_version']" + + - name: Transfer all Management Agent files over to the hosts + become: yes + become_user: root + copy: + src: "./{{remote_mgmt_agent_scratch_dir}}" + dest: "{{remote_mgmt_agent_scratch_parent}}" + owner: root + group: root + mode: '0644' + + - name: Upgrade the Management Agent + become: yes + become_user: root + shell: + "rpm -U {{remote_mgmt_agent_scratch_path}}/oracle.mgmt_agent.rpm" + tags: upgrade-agent + + - name: Collect facts about system services + service_facts: + + - name: Check if the mgmt_agent service is in running state + fail: + msg: "mgmt_agent is not in running state" + when: "'mgmt_agent.service' not in services or ansible_facts.services['mgmt_agent.service'].state != 'running'" + + - name: Cleanup Management Agent binary copied to the target host + become: yes + become_user: root + file: + path: "{{remote_mgmt_agent_scratch_path}}" + state: absent + +- hosts: localhost + collections: + - oracle.oci + tasks: + - name: Cleanup Management Agent binary downloaded in localhost + file: + path: "./{{remote_mgmt_agent_scratch_dir}}" + state: absent \ No newline at end of file From 0a97833c1e7ce114b7f597c95267fb3be97759c2 Mon Sep 17 00:00:00 2001 From: Madhavan Arnisethangaraj Date: Thu, 4 Jan 2024 23:48:15 +0530 Subject: [PATCH 2/5] Update README.md Update README.md --- deployment/ansible-playbooks/README.md | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/deployment/ansible-playbooks/README.md b/deployment/ansible-playbooks/README.md index 38e6d1d..8098452 100644 --- a/deployment/ansible-playbooks/README.md +++ b/deployment/ansible-playbooks/README.md @@ -4,10 +4,9 @@ This provides the automated agent deployment on multiple target hosts, where monitoring is required.
Following sections will walk you through the pre-requisites, configuration and executing the playbooks.
The current playbooks works for linux based hosts, but this can be extended to other operating systems as well. -

## Pre-requisites -- Make sure ansible (version 2.9 or above version) is installed on localhost from where the deployment is initiated +- Make sure ansible (version 2.9 or above version) is installed on localhost from where the deployment is initiated. refer: https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html - Make sure python3 (version 3.6 or above version) is installed in all target hosts and localhost from where the deployment is initiated refer: https://docs.python.org/3/using/unix.html#getting-and-installing-the-latest-version-of-python @@ -17,7 +16,6 @@ refer: https://docs.oracle.com/en-us/iaas/Content/API/SDKDocs/cliinstall.htm#Qui - You need ansible collection to execute playbooks and configured with OCI CLI on the localhost from where the deployment is initiated.
refer: https://docs.oracle.com/en-us/iaas/Content/API/SDKDocs/ansiblegetstarted.htm#Getting_Started_with_Oracle_Cloud_Infrastructure_and_Ansible -

## Configuration ### Hosts file @@ -56,8 +54,6 @@ Note: - SSH password: The ssh user password
- BECOME password[defaults to SSH password]: The password to become the root user. - -

## Verifying the execution of playbooks - At the end of each playbook run, you should be able to see something similar like this for a successful execution @@ -70,7 +66,6 @@ localhost : ok=12 changed=1 unreachable=0 failed=0 s - Go to oracle cloud - Observability & Management - Management Agents - Agents - select the compartment and verify the installed agents -

## Copyright Copyright (c) 2022 Oracle and/or its affiliates. From a9b214f182de1530978eb62d6b6fe4b5547f8a94 Mon Sep 17 00:00:00 2001 From: Madhavan Arnisethangaraj Date: Thu, 4 Jan 2024 23:49:50 +0530 Subject: [PATCH 3/5] Update README.md Update README.md --- deployment/ansible-playbooks/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deployment/ansible-playbooks/README.md b/deployment/ansible-playbooks/README.md index 8098452..ba51587 100644 --- a/deployment/ansible-playbooks/README.md +++ b/deployment/ansible-playbooks/README.md @@ -6,7 +6,7 @@ Following sections will walk you through the pre-requisites, configuration and e The current playbooks works for linux based hosts, but this can be extended to other operating systems as well.

## Pre-requisites -- Make sure ansible (version 2.9 or above version) is installed on localhost from where the deployment is initiated. +- Make sure ansible (version 2.9 or above version) is installed on localhost from where the deployment is to be initiated. refer: https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html - Make sure python3 (version 3.6 or above version) is installed in all target hosts and localhost from where the deployment is initiated refer: https://docs.python.org/3/using/unix.html#getting-and-installing-the-latest-version-of-python From 87c801dab4bba006d5f8e4ae028aaf267328caed Mon Sep 17 00:00:00 2001 From: Madhavan Arnisethangaraj Date: Thu, 4 Jan 2024 23:50:35 +0530 Subject: [PATCH 4/5] Update README.md Update README.md --- deployment/ansible-playbooks/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deployment/ansible-playbooks/README.md b/deployment/ansible-playbooks/README.md index ba51587..6c095f4 100644 --- a/deployment/ansible-playbooks/README.md +++ b/deployment/ansible-playbooks/README.md @@ -6,7 +6,7 @@ Following sections will walk you through the pre-requisites, configuration and e The current playbooks works for linux based hosts, but this can be extended to other operating systems as well.

## Pre-requisites -- Make sure ansible (version 2.9 or above version) is installed on localhost from where the deployment is to be initiated. +- Make sure ansible (version 2.9 or above version) is installed on localhost from where the deployment is to be initiated. refer: https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html - Make sure python3 (version 3.6 or above version) is installed in all target hosts and localhost from where the deployment is initiated refer: https://docs.python.org/3/using/unix.html#getting-and-installing-the-latest-version-of-python From b19e6d77d674efbdf8359f6383154fa460a61773 Mon Sep 17 00:00:00 2001 From: Madhavan Arnisethangaraj Date: Tue, 5 Nov 2024 17:17:32 +0530 Subject: [PATCH 5/5] Ansible support for zip based binary --- .../mgmt_agent_zip_install.yaml | 183 ++++++++++++++++++ .../mgmt_agent_zip_uninstall.yaml | 130 +++++++++++++ .../mgmt_agent_zip_upgrade.yaml | 132 +++++++++++++ 3 files changed, 445 insertions(+) create mode 100644 deployment/ansible-playbooks/mgmt_agent_zip_install.yaml create mode 100644 deployment/ansible-playbooks/mgmt_agent_zip_uninstall.yaml create mode 100644 deployment/ansible-playbooks/mgmt_agent_zip_upgrade.yaml diff --git a/deployment/ansible-playbooks/mgmt_agent_zip_install.yaml b/deployment/ansible-playbooks/mgmt_agent_zip_install.yaml new file mode 100644 index 0000000..514603a --- /dev/null +++ b/deployment/ansible-playbooks/mgmt_agent_zip_install.yaml @@ -0,0 +1,183 @@ +# Copyright (c) 2021, 2022 Oracle and/or its affiliates. All rights reserved. +# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl. +# +--- + +# validations +- hosts: target_hosts + vars: + # common vars + tasks: + - name: collect facts about system services + service_facts: + + - name: Check if the mgmt_agent service is already installed + fail: + msg: "mgmt_agent is already installed" + when: "'mgmt_agent.service' in services" + + - name: check java executable is present on remote host + become: yes + become_user: root + command: + "which java" + register: java_result + tags: check-java-exists + - debug: + msg="{{java_result.stdout_lines}}" + verbosity=1 + + - name: Checking Java version + shell: "java -version 2>&1 | awk -F '\"' '/version/ {print $2}' | head -c3" + register: java_version + - debug: + msg="{{java_version.stdout_lines[0]}}" + verbosity=1 + + - name: Check if Java Version is greater than 1.8 + fail: + msg: "Java version is less than 1.8, Exiting.." + when: java_version.stdout_lines[0]|float < 1.8 + +# workflows +- hosts: localhost + collections: + - oracle.oci + tasks: + - name: Check pre-requisites + fail: + msg: "Environment variable {{item}} not set. Please declare an environment variable with an appropriate value for the sample to work." + when: item not in ansible_env + with_items: + - "compartment_ocid" + + - name: Create a directory if it does not exist + ansible.builtin.file: + path: "./{{remote_mgmt_agent_scratch_dir}}" + state: directory + mode: '0755' + + - name: Create management_agent_install_key + oci_management_agent_install_key: + # required + compartment_id: "{{compartment_ocid}}" + display_name: "{{mgmt_agent_install_key_name}}" + # optional + #allowed_key_install_count: 56 + #time_expires: time_expires_example + is_unlimited: true + register: key_result + - debug: + msg="{{key_result.management_agent_install_key}}" + - set_fact: + management_agent_install_key: "{{key_result.management_agent_install_key.key}}" + + - name: Creating management agent input.rsp file + copy: + content: "######################################################################## \n + # Please refer the following Management Agent Installation Guide for more details. \n + # \n + # https://docs.cloud.oracle.com/iaas/management-agents/index.html \n + #\n + # Since this file has sensitive information, please make sure that after \n + # executing setup.sh you either delete this file or store it in a secure \n + # location. \n + # \n + ######################################################################## \n + ManagementAgentInstallKey = {{management_agent_install_key}} \n + AgentDisplayName = \n + #Please uncomment the below tags properties and provide values as needed \n + #FreeFormTags = [{\"\":\"\"}, {\"\":\"\"}]\n + #DefinedTags = [{\"namespace1\":{\"\":\"\"}}, {\"namespace2\":{\"\":\"\"}}]\n + ProxyHost = \n + ProxyPort = \n + ProxyUser = \n + ProxyPassword = \n + ProxyRealm = \n + CredentialWalletPassword = \n + #Service.plugin.appmgmt.download=true \n + #Service.plugin.jms.download=true \n + #Service.plugin.dbaas.download=true \n + Service.plugin.logan.download=true + #Service.plugin.opsiHost.download=true \n + #Service.plugin.jm.download=true" + dest: "./{{remote_mgmt_agent_scratch_dir}}/input.rsp" + + - name: List management agent images + oci_management_agent_image_facts: + compartment_id: "{{compartment_ocid}}" + install_type: AGENT + register: image_result + - set_fact: + object_url: "{{ item.object_url | split('/')}}" + namespace: "{{[4]|map('extract', item.object_url.split('/')) | join()}}" + bucket_name: "{{[6]|map('extract', item.object_url.split('/')) | join ()}}" + object_name: "{{[8,9,10]|map('extract', item.object_url.split('/')) | join('/')}}" + + with_items: "{{image_result.management_agent_images}}" + when: + - item.platform_name == "Linux-x86_64" + - item.package_type == "ZIP" + - debug: + msg: "Extracted the agent image details as follows Namespace: {{namespace}} Bucket: {{bucket_name}} Object name: {{object_name}}" + + - name: Download Agent ZIP object + oci_object_storage_object: + # required + namespace_name: "{{namespace}}" + bucket_name: "{{bucket_name}}" + object_name: "{{object_name}}" + dest: "./{{remote_mgmt_agent_scratch_dir}}/oracle.mgmt_agent.zip" + tags: download_agent + +- hosts: target_hosts + vars: + # common vars + tasks: + - name: Transfer all Management Agent files over to the hosts + become: yes + become_user: root + copy: + src: "./{{remote_mgmt_agent_scratch_dir}}" + dest: "{{remote_mgmt_agent_scratch_parent}}" + owner: root + group: root + mode: '0644' + + - name: Unarchive a Management Agent zip on the remote machine + ansible.builtin.unarchive: + src: "{{remote_mgmt_agent_scratch_path}}/oracle.mgmt_agent.zip" + dest: "{{remote_mgmt_agent_scratch_path}}/" + remote_src: yes + become: yes + + - name: Install the Management Agent zip + become: yes + become_user: root + shell: + "/bin/bash {{remote_mgmt_agent_scratch_path}}/mgmt_agent/installer.sh {{remote_mgmt_agent_scratch_path}}/input.rsp" + tags: install-agent + + - name: collect facts about system services + service_facts: + + - name: Check if the mgmt_agent service is in running state + fail: + msg: "mgmt_agent is not in running state" + when: "'mgmt_agent.service' not in services or ansible_facts.services['mgmt_agent.service'].state != 'running'" + + - name: Cleanup management agent scratch + become: yes + become_user: root + file: + path: "{{remote_mgmt_agent_scratch_path}}" + state: absent + +- hosts: localhost + collections: + - oracle.oci + tasks: + - name: Cleanup management agent scratch + file: + path: "./{{remote_mgmt_agent_scratch_dir}}" + state: absent diff --git a/deployment/ansible-playbooks/mgmt_agent_zip_uninstall.yaml b/deployment/ansible-playbooks/mgmt_agent_zip_uninstall.yaml new file mode 100644 index 0000000..8bdc6e8 --- /dev/null +++ b/deployment/ansible-playbooks/mgmt_agent_zip_uninstall.yaml @@ -0,0 +1,130 @@ +# Copyright (c) 2021, 2022 Oracle and/or its affiliates. All rights reserved. +# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl. +# +--- + +# validations +- hosts: target_hosts + vars: + # common vars + tasks: + - name: collect facts about system services + service_facts: + + - name: Check if the mgmt_agent service is already installed + fail: + msg: "Management Agent service is not installed in the host, hence uninstall is not required" + when: "'mgmt_agent.service' not in services" + + - name: Checking if Management Agent installed is of Package type is 'ZIP' + become: yes + ansible.builtin.shell: cat /opt/oracle/mgmt_agent/agent_inst/config/security/resource/agent.package | grep -q packageType=ZIP + register: agent_packageType + - fail: + msg: "Error : Management Agent installed is NOT of package type ZIP" + when: agent_packageType.rc != 0 + +# workflows +- hosts: localhost + collections: + - oracle.oci + tasks: + - name: Check pre-requisites + fail: + msg: "Environment variable {{item}} not set. Please declare an environment variable with an appropriate value for the sample to work." + when: item not in ansible_env + with_items: + - "compartment_ocid" + + - name: Create a directory if it does not exist + ansible.builtin.file: + path: "./{{remote_mgmt_agent_scratch_dir}}" + state: directory + mode: '0755' + + - name: List management agent images + oci_management_agent_image_facts: + compartment_id: "{{compartment_ocid}}" + install_type: AGENT + register: image_result + - set_fact: + object_url: "{{ item.object_url | split('/')}}" + namespace: "{{[4]|map('extract', item.object_url.split('/')) | join()}}" + bucket_name: "{{[6]|map('extract', item.object_url.split('/')) | join ()}}" + object_name: "{{[8,9,10]|map('extract', item.object_url.split('/')) | join('/')}}" + + with_items: "{{image_result.management_agent_images}}" + when: + - item.platform_name == "Linux-x86_64" + - item.package_type == "ZIP" + - debug: + msg: "Extracted the agent image details as follows Namespace: {{namespace}} Bucket: {{bucket_name}} Object name: {{object_name}}" + + - name: Download Agent ZIP Object + oci_object_storage_object: + # required + namespace_name: "{{namespace}}" + bucket_name: "{{bucket_name}}" + object_name: "{{object_name}}" + dest: "./{{remote_mgmt_agent_scratch_dir}}/oracle.mgmt_agent.zip" + tags: download_agent + +- hosts: target_hosts + vars: + # common vars + tasks: + - name: Checking if Management Agent installed is of Package type is 'ZIP' + become: yes + ansible.builtin.shell: cat /opt/oracle/mgmt_agent/agent_inst/config/security/resource/agent.package | grep -q packageType=ZIP + register: agent_packageType + - fail: + msg: "Management Agent installed is NOT of package type ZIP" + when: agent_packageType.rc != 0 + + - name: Transfer all Management Agent files over to the hosts + become: yes + become_user: root + copy: + src: "./{{remote_mgmt_agent_scratch_dir}}" + dest: "{{remote_mgmt_agent_scratch_parent}}" + owner: root + group: root + mode: '0644' + + - name: Unarchive a Management Agent zip on the remote machine + ansible.builtin.unarchive: + src: "{{remote_mgmt_agent_scratch_path}}/oracle.mgmt_agent.zip" + dest: "{{remote_mgmt_agent_scratch_path}}/" + remote_src: yes + become: yes + + - name: Remove the Management Agent which was installed using zip based binary + become: yes + become_user: root + shell: + "/bin/bash {{remote_mgmt_agent_scratch_path}}/mgmt_agent/uninstaller.sh" + tags: uninstall-agent + + - name: collect facts about system services + service_facts: + + - name: Check if the mgmt_agent service does not exist + fail: + msg: "Management Agent uninstall failed. Error : mgmt_agent service exists even after uninstall" + when: "'mgmt_agent.service' in services" + + - name: Cleanup management agent scratch + become: yes + become_user: root + file: + path: "{{remote_mgmt_agent_scratch_path}}" + state: absent + +- hosts: localhost + collections: + - oracle.oci + tasks: + - name: Cleanup management agent scratch + file: + path: "./{{remote_mgmt_agent_scratch_dir}}" + state: absent \ No newline at end of file diff --git a/deployment/ansible-playbooks/mgmt_agent_zip_upgrade.yaml b/deployment/ansible-playbooks/mgmt_agent_zip_upgrade.yaml new file mode 100644 index 0000000..fcde056 --- /dev/null +++ b/deployment/ansible-playbooks/mgmt_agent_zip_upgrade.yaml @@ -0,0 +1,132 @@ +# Copyright (c) 2021, 2024 Oracle and/or its affiliates. All rights reserved. +# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl. +# +--- + +# validations +- hosts: target_hosts + vars: + # common vars + tasks: + - name: collect facts about system services + service_facts: + + - name: Check if the mgmt_agent service is already installed + fail: + msg: "Management Agent is not installed in the host, hence upgrade is not required" + when: "'mgmt_agent.service' not in services" + + - name: Check if the mgmt_agent service is in running state + fail: + msg: "Management Agent installed in the host is not in running state" + when: "'mgmt_agent.service' not in services or ansible_facts.services['mgmt_agent.service'].state != 'running'" + +# workflows +- hosts: localhost + collections: + - oracle.oci + tasks: + - name: Check pre-requisites + fail: + msg: "Environment variable {{item}} not set. Please declare an environment variable with an appropriate value for the sample to work." + when: item not in ansible_env + with_items: + - "compartment_ocid" + + - name: Create a directory if it does not exist + ansible.builtin.file: + path: "./{{remote_mgmt_agent_scratch_dir}}" + state: directory + mode: '0755' + + - name: List Management Agent Images + oci_management_agent_image_facts: + compartment_id: "{{compartment_ocid}}" + install_type: AGENT + register: image_result + - set_fact: + object_url: "{{ item.object_url | split('/')}}" + namespace: "{{[4]|map('extract', item.object_url.split('/')) | join()}}" + bucket_name: "{{[6]|map('extract', item.object_url.split('/')) | join ()}}" + object_name: "{{[8,9,10]|map('extract', item.object_url.split('/')) | join('/')}}" + image_version: "{{ item.version }}" + + with_items: "{{image_result.management_agent_images}}" + when: + - item.platform_name == "Linux-x86_64" + - item.package_type == "ZIP" + - debug: + msg: "Extracted the agent image details as follows Namespace: {{namespace}} Bucket: {{bucket_name}} Object name: {{object_name}} Agent Image Version : {{image_version}}" + + - name: Download Agent ZIP object + oci_object_storage_object: + # required + namespace_name: "{{namespace}}" + bucket_name: "{{bucket_name}}" + object_name: "{{object_name}}" + dest: "./{{remote_mgmt_agent_scratch_dir}}/oracle.mgmt_agent.zip" + tags: download_agent + +- hosts: target_hosts + vars: + # common vars + tasks: + - name: Check if upgrade operation is applicable for Management Agent + become: yes + ansible.builtin.shell: /opt/oracle/mgmt_agent/agent_inst/bin/agentcore version + register: agent_version + - set_fact: + host_agent_version: "{{ agent_version.stdout_lines }}" + - debug: + msg: "Management Agent Version : {{host_agent_version[0]}} Agent Image Version : {{hostvars['localhost']['image_version']}}" + - fail: + msg: "Management Agent is up-to-date with latest version of software available in production" + when: "host_agent_version[0] >= hostvars['localhost']['image_version']" + + - name: Transfer all Management Agent files over to the hosts + become: yes + become_user: root + copy: + src: "./{{remote_mgmt_agent_scratch_dir}}" + dest: "{{remote_mgmt_agent_scratch_parent}}" + owner: root + group: root + mode: '0644' + + - name: Unarchive a Management Agent zip on the remote machine + ansible.builtin.unarchive: + src: "{{remote_mgmt_agent_scratch_path}}/oracle.mgmt_agent.zip" + dest: "{{remote_mgmt_agent_scratch_path}}/" + remote_src: yes + become: yes + + - name: Upgrade the Management Agent + become: yes + become_user: root + shell: + "/bin/bash {{remote_mgmt_agent_scratch_path}}/mgmt_agent/installer.sh -u" + tags: upgrade-agent + + - name: Collect facts about system services + service_facts: + + - name: Check if the mgmt_agent service is in running state + fail: + msg: "mgmt_agent is not in running state" + when: "'mgmt_agent.service' not in services or ansible_facts.services['mgmt_agent.service'].state != 'running'" + + - name: Cleanup Management Agent binary copied to the target host + become: yes + become_user: root + file: + path: "{{remote_mgmt_agent_scratch_path}}" + state: absent + +- hosts: localhost + collections: + - oracle.oci + tasks: + - name: Cleanup Management Agent binary downloaded in localhost + file: + path: "./{{remote_mgmt_agent_scratch_dir}}" + state: absent \ No newline at end of file