This guide provides a full Ansible playbook to install Apache ActiveMQ Classic with distro-aware package handling and baseline service configuration for Debian 10+, Ubuntu LTS, and RHEL 9+ compatible systems.
- name: Install Apache ActiveMQ Classic
hosts: activemq
become: true
vars:
activemq_version: "6.2.1"
activemq_download_url: "https://dlcdn.apache.org/activemq/activemq-classic/{{ activemq_version }}/apache-activemq-{{ activemq_version }}-bin.tar.gz"
activemq_install_dir: /opt/activemq
activemq_user: activemq
activemq_group: activemq
tasks:
- name: Install Java (Debian/Ubuntu)
apt:
name:
- openjdk-17-jdk
state: present
update_cache: true
when: ansible_os_family == "Debian"
- name: Install Java (RHEL family)
dnf:
name:
- java-17-openjdk-devel
state: present
when: ansible_os_family == "RedHat"
- name: Create ActiveMQ group
group:
name: "{{ activemq_group }}"
state: present
- name: Create ActiveMQ user
user:
name: "{{ activemq_user }}"
group: "{{ activemq_group }}"
shell: /usr/sbin/nologin
system: yes
create_home: no
- name: Download ActiveMQ
get_url:
url: "{{ activemq_download_url }}"
dest: /tmp/apache-activemq-{{ activemq_version }}-bin.tar.gz
mode: '0644'
become_user: "{{ activemq_user }}"
- name: Extract ActiveMQ
unarchive:
src: /tmp/apache-activemq-{{ activemq_version }}-bin.tar.gz
dest: "{{ activemq_install_dir }}"
remote_src: yes
owner: "{{ activemq_user }}"
group: "{{ activemq_group }}"
- name: Create systemd service
copy:
dest: /etc/systemd/system/activemq.service
mode: '0644'
content: |
[Unit]
Description=Apache ActiveMQ
After=network.target
[Service]
Type=forking
User={{ activemq_user }}
Group={{ activemq_group }}
ExecStart={{ activemq_install_dir }}/apache-activemq-{{ activemq_version }}/bin/activemq start
ExecStop={{ activemq_install_dir }}/apache-activemq-{{ activemq_version }}/bin/activemq stop
Restart=on-failure
[Install]
WantedBy=multi-user.target
- name: Reload systemd
systemd:
daemon_reload: yes
- name: Enable and start ActiveMQ
systemd:
name: activemq
state: started
enabled: yes
- name: Verify ActiveMQ is running
command: "{{ activemq_install_dir }}/apache-activemq-{{ activemq_version }}/bin/activemq status"
register: activemq_status
changed_when: false
failed_when: false
- name: Show ActiveMQ status
debug:
var: activemq_status.stdout
| Variable | Default | Description |
|---|---|---|
activemq_version |
6.2.1 |
ActiveMQ version to install |
activemq_install_dir |
/opt/activemq |
Installation directory |
activemq_user |
activemq |
System user for ActiveMQ |
activemq_group |
activemq |
System group for ActiveMQ |
We develop tailored automation solutions for:
Let’s discuss your requirements: office@linux-server-admin.com | Contact