Skip to content

Commit d41916a

Browse files
authored
Ansible zip based (#42)
* 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
1 parent 7a2714f commit d41916a

File tree

3 files changed

+445
-0
lines changed

3 files changed

+445
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
# Copyright (c) 2021, 2022 Oracle and/or its affiliates. All rights reserved.
2+
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
3+
#
4+
---
5+
6+
# validations
7+
- hosts: target_hosts
8+
vars:
9+
# common vars
10+
tasks:
11+
- name: collect facts about system services
12+
service_facts:
13+
14+
- name: Check if the mgmt_agent service is already installed
15+
fail:
16+
msg: "mgmt_agent is already installed"
17+
when: "'mgmt_agent.service' in services"
18+
19+
- name: check java executable is present on remote host
20+
become: yes
21+
become_user: root
22+
command:
23+
"which java"
24+
register: java_result
25+
tags: check-java-exists
26+
- debug:
27+
msg="{{java_result.stdout_lines}}"
28+
verbosity=1
29+
30+
- name: Checking Java version
31+
shell: "java -version 2>&1 | awk -F '\"' '/version/ {print $2}' | head -c3"
32+
register: java_version
33+
- debug:
34+
msg="{{java_version.stdout_lines[0]}}"
35+
verbosity=1
36+
37+
- name: Check if Java Version is greater than 1.8
38+
fail:
39+
msg: "Java version is less than 1.8, Exiting.."
40+
when: java_version.stdout_lines[0]|float < 1.8
41+
42+
# workflows
43+
- hosts: localhost
44+
collections:
45+
- oracle.oci
46+
tasks:
47+
- name: Check pre-requisites
48+
fail:
49+
msg: "Environment variable {{item}} not set. Please declare an environment variable with an appropriate value for the sample to work."
50+
when: item not in ansible_env
51+
with_items:
52+
- "compartment_ocid"
53+
54+
- name: Create a directory if it does not exist
55+
ansible.builtin.file:
56+
path: "./{{remote_mgmt_agent_scratch_dir}}"
57+
state: directory
58+
mode: '0755'
59+
60+
- name: Create management_agent_install_key
61+
oci_management_agent_install_key:
62+
# required
63+
compartment_id: "{{compartment_ocid}}"
64+
display_name: "{{mgmt_agent_install_key_name}}"
65+
# optional
66+
#allowed_key_install_count: 56
67+
#time_expires: time_expires_example
68+
is_unlimited: true
69+
register: key_result
70+
- debug:
71+
msg="{{key_result.management_agent_install_key}}"
72+
- set_fact:
73+
management_agent_install_key: "{{key_result.management_agent_install_key.key}}"
74+
75+
- name: Creating management agent input.rsp file
76+
copy:
77+
content: "######################################################################## \n
78+
# Please refer the following Management Agent Installation Guide for more details. \n
79+
# \n
80+
# https://docs.cloud.oracle.com/iaas/management-agents/index.html \n
81+
#\n
82+
# Since this file has sensitive information, please make sure that after \n
83+
# executing setup.sh you either delete this file or store it in a secure \n
84+
# location. \n
85+
# \n
86+
######################################################################## \n
87+
ManagementAgentInstallKey = {{management_agent_install_key}} \n
88+
AgentDisplayName = \n
89+
#Please uncomment the below tags properties and provide values as needed \n
90+
#FreeFormTags = [{\"<key1>\":\"<value1>\"}, {\"<key2>\":\"<value2>\"}]\n
91+
#DefinedTags = [{\"namespace1\":{\"<key1>\":\"<value1>\"}}, {\"namespace2\":{\"<key2>\":\"<value2>\"}}]\n
92+
ProxyHost = \n
93+
ProxyPort = \n
94+
ProxyUser = \n
95+
ProxyPassword = \n
96+
ProxyRealm = \n
97+
CredentialWalletPassword = \n
98+
#Service.plugin.appmgmt.download=true \n
99+
#Service.plugin.jms.download=true \n
100+
#Service.plugin.dbaas.download=true \n
101+
Service.plugin.logan.download=true
102+
#Service.plugin.opsiHost.download=true \n
103+
#Service.plugin.jm.download=true"
104+
dest: "./{{remote_mgmt_agent_scratch_dir}}/input.rsp"
105+
106+
- name: List management agent images
107+
oci_management_agent_image_facts:
108+
compartment_id: "{{compartment_ocid}}"
109+
install_type: AGENT
110+
register: image_result
111+
- set_fact:
112+
object_url: "{{ item.object_url | split('/')}}"
113+
namespace: "{{[4]|map('extract', item.object_url.split('/')) | join()}}"
114+
bucket_name: "{{[6]|map('extract', item.object_url.split('/')) | join ()}}"
115+
object_name: "{{[8,9,10]|map('extract', item.object_url.split('/')) | join('/')}}"
116+
117+
with_items: "{{image_result.management_agent_images}}"
118+
when:
119+
- item.platform_name == "Linux-x86_64"
120+
- item.package_type == "ZIP"
121+
- debug:
122+
msg: "Extracted the agent image details as follows Namespace: {{namespace}} Bucket: {{bucket_name}} Object name: {{object_name}}"
123+
124+
- name: Download Agent ZIP object
125+
oci_object_storage_object:
126+
# required
127+
namespace_name: "{{namespace}}"
128+
bucket_name: "{{bucket_name}}"
129+
object_name: "{{object_name}}"
130+
dest: "./{{remote_mgmt_agent_scratch_dir}}/oracle.mgmt_agent.zip"
131+
tags: download_agent
132+
133+
- hosts: target_hosts
134+
vars:
135+
# common vars
136+
tasks:
137+
- name: Transfer all Management Agent files over to the hosts
138+
become: yes
139+
become_user: root
140+
copy:
141+
src: "./{{remote_mgmt_agent_scratch_dir}}"
142+
dest: "{{remote_mgmt_agent_scratch_parent}}"
143+
owner: root
144+
group: root
145+
mode: '0644'
146+
147+
- name: Unarchive a Management Agent zip on the remote machine
148+
ansible.builtin.unarchive:
149+
src: "{{remote_mgmt_agent_scratch_path}}/oracle.mgmt_agent.zip"
150+
dest: "{{remote_mgmt_agent_scratch_path}}/"
151+
remote_src: yes
152+
become: yes
153+
154+
- name: Install the Management Agent zip
155+
become: yes
156+
become_user: root
157+
shell:
158+
"/bin/bash {{remote_mgmt_agent_scratch_path}}/mgmt_agent/installer.sh {{remote_mgmt_agent_scratch_path}}/input.rsp"
159+
tags: install-agent
160+
161+
- name: collect facts about system services
162+
service_facts:
163+
164+
- name: Check if the mgmt_agent service is in running state
165+
fail:
166+
msg: "mgmt_agent is not in running state"
167+
when: "'mgmt_agent.service' not in services or ansible_facts.services['mgmt_agent.service'].state != 'running'"
168+
169+
- name: Cleanup management agent scratch
170+
become: yes
171+
become_user: root
172+
file:
173+
path: "{{remote_mgmt_agent_scratch_path}}"
174+
state: absent
175+
176+
- hosts: localhost
177+
collections:
178+
- oracle.oci
179+
tasks:
180+
- name: Cleanup management agent scratch
181+
file:
182+
path: "./{{remote_mgmt_agent_scratch_dir}}"
183+
state: absent
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# Copyright (c) 2021, 2022 Oracle and/or its affiliates. All rights reserved.
2+
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
3+
#
4+
---
5+
6+
# validations
7+
- hosts: target_hosts
8+
vars:
9+
# common vars
10+
tasks:
11+
- name: collect facts about system services
12+
service_facts:
13+
14+
- name: Check if the mgmt_agent service is already installed
15+
fail:
16+
msg: "Management Agent service is not installed in the host, hence uninstall is not required"
17+
when: "'mgmt_agent.service' not in services"
18+
19+
- name: Checking if Management Agent installed is of Package type is 'ZIP'
20+
become: yes
21+
ansible.builtin.shell: cat /opt/oracle/mgmt_agent/agent_inst/config/security/resource/agent.package | grep -q packageType=ZIP
22+
register: agent_packageType
23+
- fail:
24+
msg: "Error : Management Agent installed is NOT of package type ZIP"
25+
when: agent_packageType.rc != 0
26+
27+
# workflows
28+
- hosts: localhost
29+
collections:
30+
- oracle.oci
31+
tasks:
32+
- name: Check pre-requisites
33+
fail:
34+
msg: "Environment variable {{item}} not set. Please declare an environment variable with an appropriate value for the sample to work."
35+
when: item not in ansible_env
36+
with_items:
37+
- "compartment_ocid"
38+
39+
- name: Create a directory if it does not exist
40+
ansible.builtin.file:
41+
path: "./{{remote_mgmt_agent_scratch_dir}}"
42+
state: directory
43+
mode: '0755'
44+
45+
- name: List management agent images
46+
oci_management_agent_image_facts:
47+
compartment_id: "{{compartment_ocid}}"
48+
install_type: AGENT
49+
register: image_result
50+
- set_fact:
51+
object_url: "{{ item.object_url | split('/')}}"
52+
namespace: "{{[4]|map('extract', item.object_url.split('/')) | join()}}"
53+
bucket_name: "{{[6]|map('extract', item.object_url.split('/')) | join ()}}"
54+
object_name: "{{[8,9,10]|map('extract', item.object_url.split('/')) | join('/')}}"
55+
56+
with_items: "{{image_result.management_agent_images}}"
57+
when:
58+
- item.platform_name == "Linux-x86_64"
59+
- item.package_type == "ZIP"
60+
- debug:
61+
msg: "Extracted the agent image details as follows Namespace: {{namespace}} Bucket: {{bucket_name}} Object name: {{object_name}}"
62+
63+
- name: Download Agent ZIP Object
64+
oci_object_storage_object:
65+
# required
66+
namespace_name: "{{namespace}}"
67+
bucket_name: "{{bucket_name}}"
68+
object_name: "{{object_name}}"
69+
dest: "./{{remote_mgmt_agent_scratch_dir}}/oracle.mgmt_agent.zip"
70+
tags: download_agent
71+
72+
- hosts: target_hosts
73+
vars:
74+
# common vars
75+
tasks:
76+
- name: Checking if Management Agent installed is of Package type is 'ZIP'
77+
become: yes
78+
ansible.builtin.shell: cat /opt/oracle/mgmt_agent/agent_inst/config/security/resource/agent.package | grep -q packageType=ZIP
79+
register: agent_packageType
80+
- fail:
81+
msg: "Management Agent installed is NOT of package type ZIP"
82+
when: agent_packageType.rc != 0
83+
84+
- name: Transfer all Management Agent files over to the hosts
85+
become: yes
86+
become_user: root
87+
copy:
88+
src: "./{{remote_mgmt_agent_scratch_dir}}"
89+
dest: "{{remote_mgmt_agent_scratch_parent}}"
90+
owner: root
91+
group: root
92+
mode: '0644'
93+
94+
- name: Unarchive a Management Agent zip on the remote machine
95+
ansible.builtin.unarchive:
96+
src: "{{remote_mgmt_agent_scratch_path}}/oracle.mgmt_agent.zip"
97+
dest: "{{remote_mgmt_agent_scratch_path}}/"
98+
remote_src: yes
99+
become: yes
100+
101+
- name: Remove the Management Agent which was installed using zip based binary
102+
become: yes
103+
become_user: root
104+
shell:
105+
"/bin/bash {{remote_mgmt_agent_scratch_path}}/mgmt_agent/uninstaller.sh"
106+
tags: uninstall-agent
107+
108+
- name: collect facts about system services
109+
service_facts:
110+
111+
- name: Check if the mgmt_agent service does not exist
112+
fail:
113+
msg: "Management Agent uninstall failed. Error : mgmt_agent service exists even after uninstall"
114+
when: "'mgmt_agent.service' in services"
115+
116+
- name: Cleanup management agent scratch
117+
become: yes
118+
become_user: root
119+
file:
120+
path: "{{remote_mgmt_agent_scratch_path}}"
121+
state: absent
122+
123+
- hosts: localhost
124+
collections:
125+
- oracle.oci
126+
tasks:
127+
- name: Cleanup management agent scratch
128+
file:
129+
path: "./{{remote_mgmt_agent_scratch_dir}}"
130+
state: absent

0 commit comments

Comments
 (0)