cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

https://github.com/Cisco-Observability-TME/ansible-smartagent-install

 

Introduction

Welcome, intrepid tech explorer, to the ultimate guide on deploying the Cisco AppDynamics Smart Agent across multiple hosts! In this adventure, we'll blend the magic of automation with the precision of Ansible, ensuring your monitoring infrastructure is both robust and elegant. So, buckle up, fire up your terminal, and let's dive into a journey that will turn your deployment woes into a seamless orchestration symphony.

Steps to Deploy Cisco AppDynamics Smart Agent

Step 1: Install Ansible on macOS

Before we embark on this deployment journey, we need our trusty automation tool, Ansible. Follow these steps to install Ansible on your macOS system using Homebrew:

  1. Install Homebrew (if not already installed):

 

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

 

  • Install Ansible:

 

brew install ansible

 

  • Verify the Installation:

 

ansible --version

 

You should see output indicating the installed version of Ansible.

Step 2: Prepare Your Files and Directory Structure

The project directory should contain the following files:

 

├── appdsmartagent_64_linux_24.6.0.2143.deb
├── appdsmartagent_64_linux_24.6.0.2143.rpm
├── inventory-cloud.yaml
├── inventory-local.yaml
├── inventory-multiple.yaml
├── smartagent.yaml
└── variables.yaml

 

Step 3: Understanding the Files

1. inventory-cloud.yaml, inventory-local.yaml, inventory-multiple.yaml

These inventory files list the hosts where the Smart Agent will be deployed. Each file is structured similarly:

 

all:
  hosts:
    smartagent-hosts:
      ansible_host: <IP_ADDRESS>
      ansible_username: <USERNAME>
      ansible_password: <PASSWORD>
      ansible_become: yes
      ansible_become_method: sudo
      ansible_become_password: <BECOME_PASSWORD>
      ansible_ssh_common_args: '-o StrictHostKeyChecking=no'

 

Update these placeholders with your actual host details.

Explanation of smartagent.yaml

This Ansible playbook is designed to deploy the Cisco AppDynamics Smart Agent on multiple hosts. Let's break down each section and task in detail.

Playbook Header

 

---
name: Deploy Cisco AppDynamics SmartAgent
  hosts: all
  become: yes
  vars_files:
    - variables.yaml  # Include the variable file

 

name: Describes the playbook.

hosts: Specifies that the playbook should run on all hosts defined in the inventory.

become: Indicates that the tasks should be run with elevated privileges (sudo).

vars_files: Includes external variables from the variables.yaml file.

Tasks

  1. Ensure required packages are installed (RedHat)

 

- name: Ensure required packages are installed (RedHat)
  yum:
    name:
      - yum-utils
    state: present
    update_cache: yes
  when: ansible_os_family == "RedHat"

 

  • Uses the yum module to install the yum-utils package on RedHat-based systems.
  • The task runs only if the operating system family is RedHat (when: ansible_os_family == "RedHat").
  • Ensure required packages are installed (Debian)

 

- name: Ensure required packages are installed (Debian)
  apt:
    name:
      - curl
      - debian-archive-keyring
      - apt-transport-https
      - software-properties-common
    state: present
    update_cache: yes
  when: ansible_os_family == "Debian"

 

  • Uses the apt module to install necessary packages on Debian-based systems.
  • This task is conditional based on the operating system family being Debian.
  • Ensure the directory exists

 

- name: Ensure the directory exists
  file:
    path: /opt/appdynamics/appdsmartagent
    state: directory
    mode: '0755'

 

  • Uses the file module to create the directory /opt/appdynamics/appdsmartagent with the specified permissions.
  • Check if config.ini exists

 

- name: Check if config.ini exists
  stat:
    path: /opt/appdynamics/appdsmartagent/config.ini
  register: stat_config

 

  • Uses the stat module to check for the existence of config.ini and registers the result in stat_config.
  • Create default config.ini file if it doesn't exist

 

- name: Create default config.ini file if it doesn't exist
  copy:
    dest: /opt/appdynamics/appdsmartagent/config.ini
    mode: '0644'
    content: |
      [default]
      AccountAccessKey="{{ smart_agent.account_access_key }}"
      ControllerURL="{{ smart_agent.controller_url }}"
      ControllerPort=443
      AccountName="{{ smart_agent.account_name }}"
      FMServicePort={{ smart_agent.fm_service_port }}
      EnableSSL={{ smart_agent.ssl | ternary('true', 'false') }}
  when: not stat_config.stat.exists

 

  • Uses the copy module to create a default config.ini file if it doesn't exist.
  • The content field uses Jinja2 templating to populate the configuration with variables from variables.yaml.
  • Configure Smart Agent

 

- name: Configure Smart Agent
  lineinfile:
    path: /opt/appdynamics/appdsmartagent/config.ini
    regexp: '^{{ item.key }}='
    line: "{{ item.key }}={{ item.value }}"
  loop:
    - { key: 'AccountAccessKey', value: "{{ smart_agent.account_access_key }}" }
    - { key: 'ControllerURL', value: "{{ smart_agent.controller_url }}" }
    - { key: 'AccountName', value: "{{ smart_agent.account_name }}" }
    - { key: 'FMServicePort', value: "{{ smart_agent.fm_service_port }}" }
    - { key: 'EnableSSL', value: "{{ smart_agent.ssl | ternary('true', 'false') }}" }

 

  • Uses the lineinfile module to ensure specific lines in config.ini are present and correctly configured.
  • Set the Smart Agent package path (Debian)

 

- name: Set the Smart Agent package path (Debian)
  set_fact:
    smart_agent_package: "{{ playbook_dir }}/appdsmartagent_64_linux_24.6.0.2143.deb"
  when: ansible_os_family == "Debian"

 

  • Uses the set_fact module to define the path to the Smart Agent package for Debian systems.
  • Set the Smart Agent package path (RedHat)

 

- name: Set the Smart Agent package path (RedHat)
  set_fact:
    smart_agent_package: "{{ playbook_dir }}/appdsmartagent_64_linux_24.6.0.2143.rpm"
  when: ansible_os_family == "RedHat"

 

Defines the path to the Smart Agent package for RedHat systems.

  • Fail if Smart Agent package not found (Debian)

 

- name: Fail if Smart Agent package not found (Debian)
  fail:
    msg: "Smart Agent package not found for Debian."
  when: ansible_os_family == "Debian" and not (smart_agent_package is defined and smart_agent_package is file)

 

  • Uses the fail module to halt execution if the Smart Agent package is not found for Debian systems.
  • Fail if Smart Agent package not found (RedHat)

 

- name: Fail if Smart Agent package not found (RedHat)
  fail:
    msg: "Smart Agent package not found for RedHat."
  when: ansible_os_family == "RedHat" and not (smart_agent_package is defined and smart_agent_package is file)

 

  • Halts execution if the Smart Agent package is not found for RedHat systems.
  • Copy Smart Agent package to target (Debian)

 

- name: Copy Smart Agent package to target (Debian)
  copy:
    src: "{{ smart_agent_package }}"
    dest: "/tmp/{{ smart_agent_package | basename }}"
  when: ansible_os_family == "Debian"

 

  • Uses the copy module to transfer the Smart Agent package to the target host for Debian systems.
  • Install Smart Agent package (Debian)

 

- name: Install Smart Agent package (Debian)
  command: dpkg -i /tmp/{{ smart_agent_package | basename }}
  when: ansible_os_family == "Debian"

 

  • Uses the command module to install the Smart Agent package on Debian systems.
  • Copy Smart Agent package to target (RedHat)

 

- name: Copy Smart Agent package to target (RedHat)
  copy:
    src: "{{ smart_agent_package }}"
    dest: "/tmp/{{ smart_agent_package | basename }}"
  when: ansible_os_family == "RedHat"

 

  • Transfers the Smart Agent package to the target host for RedHat systems.
  • Install Smart Agent package (RedHat)

 

- name: Install Smart Agent package (RedHat)
  yum:
    name: "/tmp/{{ smart_agent_package | basename }}"
    state: present
    disable_gpg_check: yes
  when: ansible_os_family == "RedHat"

 

  • Uses the yum module to install the Smart Agent package on RedHat systems.
  • Restart Smart Agent service

 

- name: Restart Smart Agent service
  service:
    name: smartagent
    state: restarted

 

  • Uses the service module to restart the Smart Agent service to apply the new configuration.
  • Clean up temporary files

 

- name: Clean up temporary files
  file:
    path: "/tmp/{{ smart_agent_package | basename }}"
    state: absent

 

  • Uses the file module to remove the temporary Smart Agent package files from the target hosts.

3. variables.yaml

This file contains the variables used in the playbook:

 

smart_agent:
  controller_url: 'tme.saas.appdynamics.com'
  account_name: 'ACCOUNT NAME'
  account_access_key: 'ACCESS KEY'
  fm_service_port: '443'
  ssl: true
smart_agent_package_debian: 'appdsmartagent_64_linux_24.6.0.2143.deb'
smart_agent_package_redhat: 'appdsmartagent_64_linux_24.6.0.2143.rpm'

 

Explaining the Variables File

In Ansible, variables are used to store values that can be reused throughout your playbooks, roles, and tasks. They help make your playbooks more flexible and easier to maintain by allowing you to define values in one place and reference them wherever needed. Variables can be defined in several places, including:

  1. Playbooks: Directly within the playbook file.
  2. Inventory files: Associated with hosts or groups of hosts.
  3. Variable files: Separate YAML files that are included in playbooks.
  4. Roles: Within the defaults and vars directories of a role.
  5. Command line: Passed as extra variables when running the playbook.

Variables can be referenced using the Jinja2 templating syntax, which is denoted by double curly braces {{ }}.

The provided variables file is a YAML file that contains a set of variables used in an Ansible playbook. Here is a breakdown of the variables defined in the file:

 

smart_agent:
  controller_url: 'tme.saas.appdynamics.com'
  account_name: 'ACCOUNT NAME'
  account_access_key: 'ACCESS CODE HERE'
  fm_service_port: '443'
  ssl: true
smart_agent_package_debian: 'appdsmartagent_64_linux_24.6.0.2143.deb'
smart_agent_package_redhat: 'appdsmartagent_64_linux_24.6.0.2143.rpm'

 

  • smart_agent: This is a dictionary (or hash) containing several key-value pairs related to the configuration of a "smart agent".

    • controller_url: The URL of the controller.
    • account_name: The name of the account.
    • account_access_key: The access key for the account.
    • fm_service_port: The port number for the service.
    • ssl: A boolean indicating whether SSL is used.
  • smart_agent_package_debian: The filename of the Debian package for the smart agent.

  • smart_agent_package_redhat: The filename of the Red Hat package for the smart agent.

Step 4: Execute the Playbook

To deploy the Smart Agent, run the following command from your project directory:

 

ansible-playbook -i inventory-cloud.yaml smartagent.yaml

 

Replace inventory-cloud.yaml with the appropriate inventory file for your setup.

And there you have it! With these steps, you're now equipped to deploy the Cisco AppDynamics Smart Agent to multiple hosts with ease. Happy deploying!

Version history
Last update:
‎07-30-2024 04:23 PM
Updated by:
On-Demand Webinar
Discover new Splunk integrations and AI innovations for Cisco AppDynamics.


Register Now!

Observe and Explore
Dive into our Community Blog for the Latest Insights and Updates!


Read the blog here