The following sections provide the example use cases for the Java Agent Ansible roles:
Install Java Agent on Linux or Windows
Example 1: Ansible® role used to install Java Agent on Windows or Linux without any application instrumentation:
--- - hosts: all tasks: - name: Include variables for the controller settings # Include all yaml files under the vars directory include_vars: dir: vars extensions: - 'yaml' - 'yml' - include_role: name: appdynamics.agents.java vars: agent_version: 21.1.0 agent_type: java agent_action: upgrade # can be upgrade/install/rollback/uninstall, defaults to upgrade when unspecified application_name: "IoT_API" # agent default application tier_name: "java_tier" # agent default tier
Example 2: Ansible role for installing Java Agent with changing Java startup script and performing restart:
--- - hosts: single-java-host tasks: - name: Include variables for the controller settings # Include all yaml files under the vars directory include_vars: dir: vars extensions: - 'yaml' - 'yml' - import_role: name: appdynamics.agents.java public: yes vars: agent_version: 21.1.0 agent_type: java application_name: "BIGFLY" # agent default application tier_name: "java_tier" # agent default tier - name: Edit startup script with new java startup variables lineinfile: path: /opt/application/startAll.sh # Line to Search/Match against regexp: '^(.*)(-jar.*$)' # Line to Replace with line: '\1 -javaagent:{{ java_agent_dest_folder_linux }}/javaagent.jar -Dappdynamics.agent.nodeName=application-1 \2' backup: yes backrefs: yes state: present notify: RestartingApp - name: Allow appuser write to appd logs folder user: name: appuser groups: - appdynamics append: yes become: yes handlers: - name: RestartingApp command: '/opt/application/stopAll.sh && /opt/application/startAll.sh' args: chdir: '/opt/application/'
Instrument JBoss/Wildfly
The features of this role are:
- Java Agent installation for Linux
- Instrument Jboss/Wildfly
- Automatic applications restart (if
systemd
service is present) - Java Agent start verification
Example 1: Install Java Agent and instrument one or more applications.
--- - hosts: all tasks: - name: Include variables for the controller settings # Include all yaml files under the vars directory include_vars: dir: vars extensions: - 'yaml' - 'yml' - include_role: name: appdynamics.agents.java # use java role variables in the following instrumentation tasks when public: yes public: yes vars: agent_version: 21.1.0 agent_type: java - include_role: name: appdynamics.agents.instrument_jboss vars: # instrument jboss: application_name: "IoT_API2" tier_name: "Jboss" jboss_service: wildfly app_user: wildfly restart_app: yes jboss_config: /opt/wildfly/bin/standalone.sh
Example 2: This role ensures that all instrumented applications have access to the Java Agent logs directory.
In some cases, when the application PID user is not local on the Linux host, it cannot be added to the AppDynamics group. In such a case, you can let the application user own the Java Agent directory instead.
--- - hosts: all tasks: - name: Include variables for the controller settings # Include all yaml files under the vars directory include_vars: dir: vars extensions: - 'yaml' - 'yml' - include_role: name: appdynamics.agents.java # use java role variables in the following instrumentation tasks when public: yes public: yes vars: agent_version: 21.1.0 agent_type: java # single app mode: Can skip appdynamics user creation and own java-agent directory by app user (wildfly in this case) create_appdynamics_user: no agent_dir_permission: user: wildfly group: wildfly - include_role: name: appdynamics.agents.instrument_jboss vars: # instrument jboss: application_name: "IoT_API2" tier_name: "Jboss" jboss_service: wildfly app_user: wildfly restart_app: yes jboss_config: /opt/wildfly/bin/standalone.sh
JBoss Instrumentation Variables
Variable | Description | Required | Default |
---|---|---|---|
app_user | User that runs this application. It must be provided, so write permissions are given to the java-agent logs directory | Y | jboss |
jboss_service | Systemd service that should be restarted if restart_app is set to 'yes' | N | |
restart_app | Set to 'yes' to automatically restart instrumented service | N | no |
backup | Whether original config file should be backed up before any changes | N | False |
jboss_config | Jboss/Wildfly config to instrument. Provide a path to jboss standalone.sh | Y | /opt/wildfly/bin/standalone.sh |
Instrument Apache Tomcat
The features of this role are:
- Java Agent installation for Linux
- Instrumentation of Apache Tomcat
- Automatic applications restart (if
systemd
service is present) - Java Agent start verification
Example 1: Install Java Agent and instrument one or more applications.
--- - hosts: all tasks: - name: Include variables for the controller settings # Include all yaml files under the vars directory include_vars: dir: vars extensions: - 'yaml' - 'yml' - include_role: name: appdynamics.agents.java # use java role variables in the following instrumentation tasks when public: yes public: yes vars: agent_version: 21.1.0 agent_type: java - include_role: name: appdynamics.agents.instrument_tomcat vars: # instrument tomcat: tomcat_service: tomcat9 application_name: "IoT_API22" tier_name: "Tomcat" app_user: tomcat restart_app: yes tomcat_config: /usr/share/tomcat9/bin/setenv.sh
Example 2: To ensure all instrumented applications have access to the Java Agent logs directory.
In some cases, when the application PID user is not local on the Linux host, it cannot be added to the AppDynamics group. In such a case, you can let the application user own the Java Agent directory instead.
--- - hosts: all tasks: - name: Include variables for the controller settings # Include all yaml files under the vars directory include_vars: dir: vars extensions: - 'yaml' - 'yml' - include_role: name: appdynamics.agents.java # use java role variables in the following instrumentation tasks when public: yes public: yes vars: agent_version: 21.1.0 agent_type: java # single app mode: Can skip appdynamics user creation and own java-agent directory by app user (tomcat in this case) create_appdynamics_user: no agent_dir_permission: user: tomcat group: tomcat - include_role: name: appdynamics.agents.instrument_tomcat vars: # instrument tomcat: tomcat_service: tomcat9 application_name: "IoT_API22" tier_name: "Tomcat" app_user: tomcat restart_app: yes tomcat_config: /usr/share/tomcat9/bin/setenv.sh
Tomcat Instrumentation Variables
Variable | Description | Required | Default |
---|---|---|---|
app_user | The user that runs this application. It must be provided, so write permissions are given to the java-agent logs directory | Y | tomcat |
tomcat_service | Systemd service that should be restated if restart_app is set to 'yes' | N | |
add_service_override | If enabled, adds systemd override file to explicitly allow write permissions to AppDynamics java-agent dir. Required for tomcat9 installed on ubuntu20.04 | N | yes |
restart_app | Set to 'yes' to automatically restart instrumented service | N | no |
backup | Whether the original config file should be backed up before any changes | N | no |
tomcat_config | Choose which tomcat configuration file to modify. You must set the full path to the setenv.sh file, for example, <CATALINA_HOME>/bin/setenv.sh . If Tomcat is installed with yum on RHEL distributions, this file is not invoked by the startup script. In that case, it can be set to /etc/tomcat/conf.d/appdynamics.conf instead. | Y |
Ansible® is a registered trademark of Red Hat, Inc. in the United States and other countries.
Add Comment