Introduction

Ansible is an easy-to-use configuration management tool. Designed for multi-tier application deployment, this configuration management and provisioning tool uses SSH to connect to the servers and run the configured tasks. 

Prerequisites

  • An Ansible server, where Ansible is installed on one of the servers.
  • SSH installed on all the target resources and the resources must communicate with the Ansible server.
  • Public keys of all the target resources are shared with the Ansible server. To share the the publice keys, log into the target resources on the Ansible server.
  • The OpsRamp URL is allowed on the Ansible server to download all the latest version of the agent package.
  • The resource user must have sudo permissions.

Installing agents

Prerequisite

Before you install an agent with Ansible, add the device details in /etc/ansible/hosts in the following format:

[Category] 
<device IP> ansible_user=<user> ansible_password=<userpassword>

Example

[OpsRampAgents]
10.10.10.10 ansible_user=root ansible_password=password123

Procedure

Step 1: Download Ansible

You can download Ansible from the OpsRamp console. To download Ansible and extract files:

  1. Go to Setup > Downloads > Agent.
  2. Select a client from the drop-down list and then select the connection type direct or proxy.
  3. Click Download on the Ansible Agent Deployment tile.
  4. Copy the downloaded file to /etc/ansible/roles/ or /etc/ansible/ and extract it.
  5. Navigate to the opsrampagent folder to run playbooks.

Step 2: Install agent using Ansible

If a resource already has an agent, you can either reinstall an agent or skip such resources.

Scenario 1 : Install the agent without uninstalling the existing agents.

You have multiple resources. Some of the resources already have agent installed and you want to skip agent installation. Some resources need agent installation.

Solution:
You can install the latest version of the agent on those resources that do not have an agent installed and skip installation on those resources that already have an agent installed. Run the following commands accordingly:
Root Agent installation

ansible-playbook agent-install-uninstall.yml -e  "hostlist=<devicelist>"  -f <number of forks>

Example

ansible-playbook agent-install-uninstall.yml -e "hostlist=OpsrampAgents" -f 10

Non-Root Agent installation

  • With default OpsRamp user

    ansible-playbook agent-install-uninstall.yml -e "hostlist=<devicelist>" -e "isnonroot=<yes/y>" -f <number of forks>
    

    Example

    ansible-playbook agent-install-uninstall.yml -e "hostlist=OpsrampAgents" -e "isnonroot=yes" -f 10
    
  • With specific/custom user

    ansible-playbook agent-install-uninstall.yml -e "hostlist=<devicelist>" -e "isnonroot=<yes/y>" -e "agentuser=<username>" -f <number of forks>
    

    Example

    ansible-playbook agent-install-uninstall.yml -e "hostlist=OpsrampAgents" -e "isnonroot=yes" -e "agentuser=dsr" -f 10
    

Scenario 2 : Reinstall the agent

You have multiple resources. Some of the resources already have agent installed and you want to reinstall agent. Some resources need agent installation.

Solution:
You can install the latest version of the agent on those resources that do not have an agent installed and reinstall on those resources that already have an agent installed. The existing agent is uninstalled and the latest version of the agent is installed. Run the following command accordingly:

Root Agent installation

ansible-playbook agent-install-uninstall.yml -e "hostlist=<devicelist>"  -e "reinstall=yes" -f <number of forks>

Example

ansible-playbook agent-install-uninstall.yml -e "hostlist=OpsrampAgents"  -e "reinstall=yes" -f 10

Non-Root Agent installation

  • With default OpsRamp user
    ansible-playbook agent-install-uninstall.yml -e "hostlist=<devicelist>" -e "reinstall=yes" "isnonroot=<yes/y>" -f <number of forks>
    

    Example

    ansible-playbook agent-install-uninstall.yml -e "hostlist=OpsrampAgents" -e "reinstall=yes" -e "isnonroot=yes" -f 10 
    
  • With specific/custom user
    ansible-playbook agent-install-uninstall.yml -e "hostlist=<devicelist>" -e "reinstall=yes" "isnonroot=<yes/y>" -e "agentuser=<username>" -f <number of forks>
    

    Example

    ansible-playbook agent-install-uninstall.yml -e "hostlist=OpsrampAgents" -e "reinstall=yes" -e "isnonroot=yes" -e "agentuser=dsr" -f 10
    

Uninstalling agents

To uninstall agents from all the target resources:

Prerequisite

Add all the resource details in the inventory file: /etc/ansible/hosts using the following:

[Category]
<device IP> ansible_user=<user> ansible_password=<userpassword>

Example

[OpsRampAgents] 
10.10.10.10 ansible_user=root ansible_password=password123

Procedure

Run the following command to uninstall the agent:

ansible-playbook agent-install-uninstall.yml -e "hostlist=<devicelist>" -e "executionType=uninstall" -f <number of forks>

Example

ansible-playbook agent-install-uninstall.yml -e "hostlist=OpsRampAgents" -e    "executionType=uninstall" -f 10

Migrating agents

You can migrate agents on target resources from proxy to direct and vice versa.

Prerequisite

Before you start migrating the agents, use the following command to specify the resource details to the inventory file:

[Category]  
<device IP> ansible_user=<user> ansible_password=<userpassword>

Example

[OpsRampAgents] 
 10.10.10.10 ansible_user=root ansible_password=password123

Procedure

Migrating proxy agents to direct agents

To migrate proxy agents to direct agents, run the following command:

ansible-playbook agentmigration.yml -e "hostlist=<devicelist>" -e "migrationType=direct"

Example

ansible-playbook agentmigration.yml -e "hostlist=OpsRampAgents" -e "migrationType=direct"

Migrating direct agents to proxy agents

Direct agents can be migrated to proxy agents with or without authentication.

  • Migrating without authentication
    Run the following command to migrate direct agents to proxy agents:
    ansible-playbook agentmigration.yml -e "hostlist=<devicelist>" -e "migrationType=proxy" -e "proxyServer=<proxyIP/ProxyServer>" -e "proxyPort=<port number>" -e "proxyProto=<http/https>" -f <number of forks>
    

    Example

    ansible-playbook agentmigration.yml -e "hostlist=OpsRampAgents" -e "migrationType=proxy" -e "proxyServer=10.32.32.32" -e "proxyPort=3128" -e "proxyProto=http" -f 10
    
  • Migrating with authentication
    Run the following command to migrate direct agents to proxy agents:
    ansible-playbook agentmigration.yml -e "hostlist=<devicelist>" -e "migrationType=proxy" -e "proxyServer=<proxyIP/ProxyServer>" -e "proxyPort=<port number>" -e "proxyProto=http/https>" -e "proxyUser=<user name>" -e 'proxyPassword=<user password>' -f <number of forks>
    

    Example

    ansible-playbook agentmigration.yml -e "hostlist=OpsRampAgents" -e "migrationType=proxy" -e "proxyServer=10.32.32.32" -e "proxyPort=3128" -e "proxyProto=http" -e "proxyUser=user name" -e 'proxyPassword=password' -f 10
    

Updating agents

You can update agents on all target resources.

Prerequisite

Before you start updating the agents, use the following command to specify the resource details to the inventory file:

[Category] 
<device IP> ansible_user=<user> ansible_password=<userpassword>

Example

[OpsRampAgents]
10.10.10.10 ansible_user=root ansible_password=password123

Procedure

Run the following command to update agents on target resources:

ansible-playbook agentupdate.yml -e "hostlist=<devicelist>" -f <number of forks>

Example

ansible-playbook agentupdate.yml -e "hostlist=OpsRampAgents" -f 10

Ansible Vault/Encryption process

If you want to use encrypted inventory files for different procedures, then include the flag –ask-vault in the respective command. The command then directs you to the credentials.

For more information about how to secure an inventory file using encryption, refer to the Ansible documenttion on Encrypting content with Ansible Vault.

Sample commands with encrypted inventory file

If you want to  use encrypted inventory files for different procedures, include the flag --ask-vault in the respective command. The command then directs you to the credentials.

Installation commands

Scenario 1 : Install the agent without uninstalling the existing agents.
For Root Agent installation

ansible-playbook agent-install-uninstall.yml -e "hostlist=<devicelist>" -f <number of forks> --ask-vault

Non-root Agent installation

  • With default OpsRamp user

    ansible-playbook agent-install-uninstall.yml -e "hostlist=<devicelist>" -e "isnonroot=yes" -f <number of forks> --ask-vault
    
  • With specific/custom user

    ansible-playbook agent-install-uninstall.yml -e "hostlist=<devicelist>" -e "isnonroot=yes" -e "agentuser=dsr" -f <number of forks> --ask-vault
    

Scenario 2 : Reinstall the agent
Root Agent installation

ansible-playbook agent-install-uninstall.yml -e "hostlist=<devicelist>"  -e "reinstall=yes" -f <number of forks> --ask-vault

Non-root Agent installation

  • With default OpsRamp user
    ansible-playbook agent-install-uninstall.yml -e "hostlist=<devicelist>" -e "reinstall=yes" -e "isnonroot=yes" -f <number of forks> --ask-vault
    
  • With specific/custom user
    ansible-playbook agent-install-uninstall.yml -e "hostlist=<devicelist>" -e "reinstall=yes" -e "isnonroot=yes" -e "agentuser=dsr" -f <number of forks> --ask-vault
    

Uninstallation commands

ansible-playbook agent-install-uninstall.yml -e "hostlist=<devicelist>" -e "executionType=uninstall" -f <number of forks> --ask-vault

Migration commands

  • Proxy to Direct

    ansible-playbook agentmigration.yml -e "hostlist=<devicelist>" -e "migrationType=direct" --ask-vault
    
  • Direct to Proxy

    ansible-playbook agentmigration.yml -e "hostlist=<devicelist>" -e "migrationType=proxy" -e "proxyServer=<proxyIP/ProxyServer>" -e "proxyPort=<port number>" -e "proxyProto=http/https>" -e "proxyUser=<user name>" -e 'proxyPassword=<user password>' -f <number of forks> --ask-vault
    
    ansible-playbook agentmigration.yml -e "hostlist=<devicelist>" -e "migrationType=proxy" -e "proxyServer=<proxyIP/ProxyServer>" -e "proxyPort=<port number>" -e "proxyProto=<http/https>" -f <number of forks> --ask-vault
    

Update commands

ansible-playbook agentupdate.yml -e "hostlist=<devicelist>" -f <number of forks> --ask-vault

External references

Ansible Documentation