Not a customer? Click the 'Start a free trial' link to begin a 30-day SaaS trial of our product and to join our community.
Existing Cisco AppDynamics customers should click the 'Sign In' button to authenticate to access the community
on 07-30-2024 04:23 PM
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.
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:
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.
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
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.
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.
---
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.
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"
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"
Ensure the directory exists
- name: Ensure the directory exists
file:
path: /opt/appdynamics/appdsmartagent
state: directory
mode: '0755'
Check if config.ini exists
- name: Check if config.ini exists
stat:
path: /opt/appdynamics/appdsmartagent/config.ini
register: 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
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') }}" }
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"
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)
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)
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"
Install Smart Agent package (Debian)
- name: Install Smart Agent package (Debian)
command: dpkg -i /tmp/{{ smart_agent_package | basename }}
when: ansible_os_family == "Debian"
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"
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"
Restart Smart Agent service
- name: Restart Smart Agent service
service:
name: smartagent
state: restarted
Clean up temporary files
- name: Clean up temporary files
file:
path: "/tmp/{{ smart_agent_package | basename }}"
state: absent
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'
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:
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".
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.
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!
Thank you! Your submission has been received!
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form