-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding ansible playbook support to upgrade Management Agent (#29)
* 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
- Loading branch information
Showing
2 changed files
with
135 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |