1313 - wget
1414 - net-tools
1515 - git
16- - " {{ java_packages[ansible_distribution ] }}"
16+ - " {{ java_packages[ansible_os_family ] }}"
1717 state : present
1818
19- - name : Find Java 17 installation path
20- command : " update-alternatives --list java"
21- register : java_alternatives_output
19+ - name : Locate Java 17 executable on Debian-based systems
20+ ansible.builtin.shell : " find /usr/lib/jvm -name 'java' | grep 'java-17'"
21+ register : debian_java_path
22+ when : ansible_os_family == "Debian"
2223
23- - name : Set default Java version to Java 17
24- alternatives :
24+ - name : Locate Java 17 executable on RedHat-based systems
25+ ansible.builtin.shell : " find /usr/lib/jvm -name 'java' | grep 'java-17'"
26+ register : redhat_java_path
27+ when : ansible_os_family == "RedHat"
28+
29+ - name : Set Java 17 as the default alternative on Debian-based systems
30+ community.general.alternatives :
31+ name : java
32+ path : " {{ debian_java_path.stdout | trim }}"
33+ priority : 100
34+ when : ansible_os_family == "Debian"
35+
36+ - name : Set Java 17 as the default alternative on RedHat-based systems
37+ community.general.alternatives :
2538 name : java
26- path : " {{ java_alternatives_output.stdout_lines | select('search', 'java-17') | list | first }}"
27-
28- # - name: Download ActiveMQ Artemis
29- # get_url:
30- # url: "{{ artemis_url }}"
31- # dest: /tmp/apache-artemis-{{ artemis_version }}-bin.tar.gz
32-
33- # - name: Extract ActiveMQ Artemis
34- # unarchive:
35- # src: /tmp/apache-artemis-{{ artemis_version }}-bin.tar.gz
36- # dest: /opt
37- # remote_src: yes
38-
39- # - name: Check if Artemis installation directory exists
40- # stat:
41- # path: "{{ artemis_install_dir }}"
42- # register: artemis_install_dir_stat
43-
44- # - name: Move extracted Artemis to installation directory
45- # command: mv /opt/apache-artemis-{{ artemis_version }} {{ artemis_install_dir }}
46- # when: not artemis_install_dir_stat.stat.exists
47-
48- # - name: Create artemis group
49- # group:
50- # name: "{{ artemis_group }}"
51- # state: present
52-
53- # - name: Create artemis user and assign to group
54- # user:
55- # name: "{{ artemis_user }}"
56- # group: "{{ artemis_group }}"
57- # createhome: yes
58- # shell: /bin/bash
59- # state: present
60-
61- # - name: Change ownership of Artemis directories
62- # file:
63- # path: "{{ item }}"
64- # state: directory
65- # owner: "{{ artemis_user }}"
66- # group: "{{ artemis_group }}"
67- # recurse: yes
68- # loop:
69- # - "{{ artemis_install_dir }}"
70- # - "{{ artemis_instance_dir }}"
71-
72- # - name: Ensure log directory exists and permissions are set
73- # file:
74- # path: "{{ artemis_instance_dir }}/log"
75- # state: directory
76- # owner: "{{ artemis_user }}"
77- # group: "{{ artemis_group }}"
78- # mode: '0755'
79-
80- # - name: Ensure tmp/webapps directory exists and permissions are set
81- # file:
82- # path: "{{ artemis_instance_dir }}/tmp/webapps"
83- # state: directory
84- # owner: "{{ artemis_user }}"
85- # group: "{{ artemis_group }}"
86- # mode: '0755'
87- # recurse: yes
88-
89- # - name: Set permissions Artemis instance data directory
90- # file:
91- # path: /opt/artemis-instance/data
92- # owner: "{{ artemis_user }}"
93- # group: "{{ artemis_group }}"
94- # state: directory
95- # recurse: yes
96-
97- # - name: Create Artemis instance
98- # command: "{{ artemis_install_dir }}/bin/artemis create {{ artemis_instance_dir }} --user admin --password {{ artemis_password }} --allow-anonymous --force"
99-
100- # - name: Deploy Artemis systemd service file
101- # template:
102- # src: artemis.service.j2
103- # dest: /etc/systemd/system/artemis.service
104- # owner: root
105- # group: root
106- # mode: '0644'
107-
108- # - name: Reload systemd daemon
109- # command: systemctl daemon-reload
110-
111- # - name: Enable and start the Artemis service
112- # systemd:
113- # name: artemis
114- # enabled: yes
115- # state: started
116-
117- # - name: Update bootstrap.xml to bind to 0.0.0.0
118- # replace:
119- # path: "{{ artemis_instance_dir }}/etc/bootstrap.xml"
120- # regexp: '(<binding name="artemis" uri=")(.*)(:8161">)'
121- # replace: '\1http://0.0.0.0\3'
122-
123- # - name: Update Jolokia access to allow all origins
124- # replace:
125- # path: "{{ artemis_instance_dir }}/etc/jolokia-access.xml"
126- # regexp: '<allow-origin>.*</allow-origin>'
127- # replace: '<allow-origin>*://*</allow-origin>'
128-
129- # - name: Restart Artemis service after config changes
130- # systemd:
131- # name: artemis
132- # state: restarted
133- # enabled: yes
39+ path : " {{ redhat_java_path.stdout | trim }}"
40+ link : " /usr/bin/java"
41+ priority : 100
42+ when : ansible_os_family == "RedHat"
43+
44+ - name : Verify Java 17 installation
45+ ansible.builtin.command : java -version
46+ register : java_version
47+ ignore_errors : true
48+
49+ - name : Display Java version
50+ ansible.builtin.debug :
51+ msg : " Java installed successfully. Version: {{ java_version.stderr_lines | default([]) | union(java_version.stdout_lines | default([])) }}"
52+ when : java_version is defined
53+
54+ - name : Download ActiveMQ Artemis
55+ get_url :
56+ url : " {{ artemis_url }}"
57+ dest : /tmp/apache-artemis-{{ artemis_version }}-bin.tar.gz
58+
59+ - name : Extract ActiveMQ Artemis
60+ unarchive :
61+ src : /tmp/apache-artemis-{{ artemis_version }}-bin.tar.gz
62+ dest : /opt
63+ remote_src : yes
64+
65+ - name : Check if Artemis installation directory exists
66+ stat :
67+ path : " {{ artemis_install_dir }}"
68+ register : artemis_install_dir_stat
69+
70+ - name : Move extracted Artemis to installation directory
71+ command : mv /opt/apache-artemis-{{ artemis_version }} {{ artemis_install_dir }}
72+ when : not artemis_install_dir_stat.stat.exists
73+
74+ - name : Create artemis group
75+ group :
76+ name : " {{ artemis_group }}"
77+ state : present
78+
79+ - name : Create artemis user and assign to group
80+ user :
81+ name : " {{ artemis_user }}"
82+ group : " {{ artemis_group }}"
83+ createhome : yes
84+ shell : /bin/bash
85+ state : present
86+
87+ - name : Change ownership of Artemis directories
88+ file :
89+ path : " {{ item }}"
90+ state : directory
91+ owner : " {{ artemis_user }}"
92+ group : " {{ artemis_group }}"
93+ recurse : yes
94+ loop :
95+ - " {{ artemis_install_dir }}"
96+ - " {{ artemis_instance_dir }}"
97+
98+ - name : Ensure log directory exists and permissions are set
99+ file :
100+ path : " {{ artemis_instance_dir }}/log"
101+ state : directory
102+ owner : " {{ artemis_user }}"
103+ group : " {{ artemis_group }}"
104+ mode : ' 0755'
105+
106+ - name : Ensure tmp/webapps directory exists and permissions are set
107+ file :
108+ path : " {{ artemis_instance_dir }}/tmp/webapps"
109+ state : directory
110+ owner : " {{ artemis_user }}"
111+ group : " {{ artemis_group }}"
112+ mode : ' 0755'
113+ recurse : yes
114+
115+ - name : Set permissions Artemis instance data directory
116+ file :
117+ path : /opt/artemis-instance/data
118+ owner : " {{ artemis_user }}"
119+ group : " {{ artemis_group }}"
120+ state : directory
121+ recurse : yes
122+
123+ - name : Create Artemis instance
124+ command : " {{ artemis_install_dir }}/bin/artemis create {{ artemis_instance_dir }} --user admin --password {{ artemis_password }} --allow-anonymous --force"
125+
126+ - name : Deploy Artemis systemd service file
127+ template :
128+ src : artemis.service.j2
129+ dest : /etc/systemd/system/artemis.service
130+ owner : root
131+ group : root
132+ mode : ' 0644'
133+
134+ - name : Reload systemd daemon
135+ command : systemctl daemon-reload
136+
137+ - name : Enable and start the Artemis service
138+ systemd :
139+ name : artemis
140+ enabled : yes
141+ state : started
142+
143+ - name : Update bootstrap.xml to bind to 0.0.0.0
144+ replace :
145+ path : " {{ artemis_instance_dir }}/etc/bootstrap.xml"
146+ regexp : ' (<binding name="artemis" uri=")(.*)(:8161">)'
147+ replace : ' \1http://0.0.0.0\3'
148+
149+ - name : Update Jolokia access to allow all origins
150+ replace :
151+ path : " {{ artemis_instance_dir }}/etc/jolokia-access.xml"
152+ regexp : ' <allow-origin>.*</allow-origin>'
153+ replace : ' <allow-origin>*://*</allow-origin>'
154+
155+ - name : Restart Artemis service after config changes
156+ systemd :
157+ name : artemis
158+ state : restarted
159+ enabled : yes
0 commit comments