Skip to content

Commit

Permalink
Ansible zip based (#42)
Browse files Browse the repository at this point in the history
* Adding mgmt_agent_upgrade.yaml

Adding mgmt_agent_upgrade.yaml to support agent upgrade

* Update README.md

Update README.md

* Update README.md

Update README.md

* Update README.md

Update README.md

* Ansible support for zip based binary
  • Loading branch information
marniset authored Nov 5, 2024
1 parent 7a2714f commit d41916a
Show file tree
Hide file tree
Showing 3 changed files with 445 additions and 0 deletions.
183 changes: 183 additions & 0 deletions deployment/ansible-playbooks/mgmt_agent_zip_install.yaml
Original file line number Diff line number Diff line change
@@ -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 = [{\"<key1>\":\"<value1>\"}, {\"<key2>\":\"<value2>\"}]\n
#DefinedTags = [{\"namespace1\":{\"<key1>\":\"<value1>\"}}, {\"namespace2\":{\"<key2>\":\"<value2>\"}}]\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
130 changes: 130 additions & 0 deletions deployment/ansible-playbooks/mgmt_agent_zip_uninstall.yaml
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit d41916a

Please sign in to comment.