Enable OS Management Service Agent on OCI Instances
Tags: oci, cloud, cloudskills, osmanagement
Published: 2021-11-16 20:26:54

The Oracle Cloud Infrastructure OS Management service allows you to manage and monitor updates and patches for the operating system environments on your Oracle Cloud instances, including instances managed by the OS ManagementOracle Autonomous Linux service. OS Management also provides options for discovering and monitoring resources on your instances.

This agent is not enabled by default during instance creation, and some pre-requisites needs to be in place:

**1.-Create a dynamic group that will be used select all the instances from a compartment**

**A dynamic group** is basically the same as a user group for instances as the principal, it is used to assign permissions to an instances so it can make API calls to OCI Resources, similar to a **Instance profile on AWS**
![Dynamic-groups](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/arfmemk3klb8p1ot0zdd.png)
 

**Note: for testing there is one created for Sandbox compartment**

The name of the Dynamic group is> **OSManagementAgent**

![dynamic-group-creation](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s7fusujykrcadoy1ouk7.png)
 
**2.-For an instance to be registered with the OS Management service, you must create policies that allow instances to use OS Management.**
 First of all you will need to create a policy to enable permission for the tenancy.

![policy-creation](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lzga6tgmb6hbgenu8tgd.png)

**3. Add a policy inside the Compartment to enable the dynamic group from step 1 to access OS management features**

For this example, we use the Sandbox compartment :
![statement-for-the-policy](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i99ufyopuo7cws38f3e0.png)
 
**4. NETWORKING Requirement: you need that your VCN has access to the Service VCN**
In this case you need an entry inside the routing table similar to this 
![adding entry on routing table](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xvpugplsq4jzq1x33yrd.png)

More information on service gateway [HERE](https://docs.oracle.com/en-us/iaas/Content/Network/Tasks/servicegateway.htm)

This are the main requirements, now we can proceed with instance creation or agent configuration.

**************************************************************

###Enable Cloud OS Management Agent 

**1.-Click on show advanced options**
**2.-Select both agent OS Management Service Agent and Management Agent**
![Select-OS-AGENT](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dqhmdgrwfusgbhygsx3j.png)

if The pre-requisites are in place you should see the agent running

If the agent is not running, or **the instance was creating without enabling the os management service agent**

you will see something like this on the OS Management

**Burger Menu (Up and left) >> Compute >> Instances >> Instance details  >>  OS Management**

![os-management-failing](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gc31bukpyeunl4999gg8.png)

In this case, you need to follow the documentation for installing the agent 

[Getting Started with OS Management ](https://docs.oracle.com/en-us/iaas/os-management/osms/osms-getstarted.htm)
But basically the steps are as follow:

```
#determine if oracle linux agent is installed
sudo yum info oracle-cloud-agent
$if not
sudo yum install -y oracle-cloud-agent
```

**Note** For Oracle Linux 8 instances that were launched before October 2021 (running Oracle Cloud Agent 1.15.0 or earlier), the OS Management Service Agent plugin is disabled by default. The OS Management Service Agent plugin for disabled Oracle Linux 8 instances remain disabled after being updated to Oracle Cloud Agent 1.16.0. in this case you will need to follow the following tutorial:

You can also follow this video from Oracle Learning: 
[Getting Started with OS Management for Linux on Oracle Cloud Infrastructure](https://www.youtube.com/watch?v=7qmy5VusYKA)

************************************************************
###OS Management agent verification 

After the correct configuration you will need to restart the agent and verify the correct configuration:

Connect to your Instance using ssh

run the following command to restart the agent

```
[opc@TEST-instance-ernestol ~]$ sudo systemctl restart oracle-cloud-agent.service
[opc@TEST-instance-ernestol ~]$ sudo status restart oracle-cloud-agent.service
```
Run the following commands to verify that the agent are installed and running

```
[opc@TEST-instance-ernestol ~]$ rpm -q oracle-cloud-agent
oracle-cloud-agent-1.16.0-6051.el8.x86_64

[opc@TEST-instance-ernestol ~]$ systemctl is-enabled oracle-cloud-agent && systemctl is-active oracle-cloud-agent
enabled
active
```
if everything seems correct you will see the following under the OS Management section in the instance detail

![OS-MANAGEMENT-ENABLED](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rq2mi7340np4cgy0qxj5.png)