Skip to content

Commit

Permalink
Rework native download
Browse files Browse the repository at this point in the history
Reduce code duplication and ensure
that native bits can be optional
  • Loading branch information
rpelisse committed Apr 26, 2022
1 parent 822cce3 commit 78a9750
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 65 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ Note that if you respect the naming convention above for the file name, which is
jws_version: 5.6.0


Note: if you provide the jws_version and set tomcat_native to True, then the collection will compute the value of native_zipfile for you.

### Using RPM

Change the default install method to RPM and provide the appropriate Tomcat HOME in the playbooks:
Expand Down
1 change: 1 addition & 0 deletions roles/jws/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Role Defaults
|`tomcat_gid`| posix GID user account for service | `tomcat` |
|`tomcat_zipfile`| Tomcat archive filename | `apache-tomcat-{{ tomcat_version }}.zip` |
|`tomcat_zipfile_url`| Alternative download URL | `https://dlcdn.apache.org/tomcat/tomcat-{{ tomcat_version.split(".")[0] }}/v{{ tomcat_version }}/bin/{{ tomcat_zipfile }}` |
|`tomcat_native`| Install native bits (JWS)| False|
|`tomcat_version`| Tomcat version to download | `9.0.60` |
|`tomcat_force_install`| Whether to stop any running tomcat process and continue installation | `false` |

Expand Down
4 changes: 3 additions & 1 deletion roles/jws/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ tomcat_version: 9.0.60
tomcat_zipfile_home: "{{ tomcat_install_dir }}/apache-tomcat-{{ tomcat_version }}"
tomcat_zipfile: "apache-tomcat-{{ tomcat_version }}.zip"
tomcat_zipfile_url: "https://archive.apache.org/dist/tomcat/tomcat-{{ tomcat_version.split('.')[0] }}/v{{ tomcat_version }}/bin/{{ tomcat_zipfile }}"
# Switch to True if you want to also download native bits
tomcat_native: False

jws_version: 5.6.0
jws_home: "{{ tomcat_install_dir }}/jws-{{ jws_version.split('.')[0] }}.{{ jws_version.split('.')[1] }}/tomcat"
Expand Down Expand Up @@ -44,7 +46,7 @@ tomcat_conf_templates_web: 'templates/web.xml.j2'

tomcat_shutdown_port: '8005'

# HTTP Connector Config
# HTTP Connector config
tomcat_listen_http_port: '8080'
tomcat_listen_http_bind_address: 'localhost'
tomcat_listen_http_enabled: 'yes'
Expand Down
4 changes: 4 additions & 0 deletions roles/jws/meta/argument_specs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ argument_specs:
default: "https://dlcdn.apache.org/tomcat/tomcat-{{ tomcat_version.split('.')[0] }}/v{{ tomcat_version }}/bin/{{ tomcat_zipfile }}"
description: "Custom URL for tomcat/jws archive download"
type: "str"
tomcat_native:
default: False
description: "Specify if native bits are required (JWS)"
type: "bool"
tomcat_user:
# line 7 of jws/defaults/main.yml
default: "tomcat"
Expand Down
52 changes: 52 additions & 0 deletions roles/jws/tasks/install/fetch_zipfile_from_rhn_and_deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
- name: Check arguments
assert:
that:
- zipfile is defined
- zipfile_url is defined
- zipfile_url | length > 0
- path_to_zipfile is defined
quiet: true
fail_msg: "You need to provide"

- name: "Check download archive path: {{ path_to_zipfile }}"
ansible.builtin.stat:
path: "{{ path_to_zipfile }}"
register: archive_path

- name: Check local download archive path
ansible.builtin.stat:
path: "{{ lookup('env', 'PWD') }}"
register: local_path
delegate_to: localhost

- name: "Check downloaded archive local_path.stat.path }}/{{ zipfile }}"
ansible.builtin.stat:
path: "{{ local_path.stat.path }}/{{ zipfile }}"
register: local_archive_path
delegate_to: localhost

- name: "Install JWS with zipfile from RHN: {{ zipfile_url }}"
redhat_csp_download:
url: "{{ zipfile_url }}"
dest: "{{ zipfile }}"
username: "{{ tomcat.rhn.username }}"
password: "{{ tomcat.rhn.password }}"
delegate_to: localhost
register: new_version_downloaded
when:
- not archive_path.stat.exists

- name: "Copy archives to target nodes: {{ tomcat_install_dir }}/{{ zipfile }}"
ansible.builtin.copy:
src: "{{ local_path.stat.path }}/{{ zipfile }}"
dest: "{{ tomcat_install_dir }}/{{ zipfile }}"
owner: "{{ tomcat.user }}"
group: "{{ tomcat.group }}"
mode: 0640
register: new_version_downloaded
when:
- not archive_path.stat.exists
- local_archive_path.stat is defined
- local_archive_path.stat.exists
become: yes
84 changes: 20 additions & 64 deletions roles/jws/tasks/install/rhn.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,74 +9,30 @@

- set_fact:
tomcat_zipfile: "jws-{{ jws_version }}-application-server.zip"
native_zipfile: "jws-{{ jws_version }}-application-server-RHEL{{ ansible_facts['distribution_major_version'] }}-x86_64.zip"
when:
- jws_version is defined

- name: Check download archive path
ansible.builtin.stat:
path: "{{ tomcat_install_dir }}/{{ tomcat_zipfile }}"
register: archive_path

- name: Check download archive path
ansible.builtin.stat:
path: "{{ tomcat_install_dir }}/{{ native_zipfile }}"
register: native_archive_path

- name: Check local download archive path
ansible.builtin.stat:
path: "{{ lookup('env', 'PWD') }}"
register: local_path
delegate_to: localhost

- name: Check downloaded archive
ansible.builtin.stat:
path: "{{ local_path.stat.path }}/{{ tomcat_zipfile }}"
register: local_archive_path
delegate_to: localhost

- name: Check downloaded native archive
ansible.builtin.stat:
path: "{{ local_path.stat.path }}/{{ native_zipfile }}"
register: local_native_archive_path
delegate_to: localhost

- name: "Install JWS with zipfile from RHN: {{ tomcat.rhn.server_zipfile_url }}"
redhat_csp_download:
url: "{{ tomcat.rhn.server_zipfile_url }}"
dest: "{{ tomcat_zipfile }}"
username: "{{ tomcat.rhn.username }}"
password: "{{ tomcat.rhn.password }}"
delegate_to: localhost
register: new_version_downloaded
- set_fact:
native_zipfile: "jws-{{ jws_version }}-application-server-RHEL{{ ansible_facts['distribution_major_version'] }}-x86_64.zip"
when:
- not archive_path.stat.exists

- name: "Install JWS native dependencies with zipfile from RHN: {{ tomcat.rhn.native_zipfile_url }}"
redhat_csp_download:
url: "{{ tomcat.rhn.native_zipfile_url }}"
dest: "{{ native_zipfile }}"
username: "{{ tomcat.rhn.username }}"
password: "{{ tomcat.rhn.password }}"
delegate_to: localhost
- tomcat_native is defined
- not native_zipfile is defined
- jws_version is defined
- ansible_facts is defined
- ansible_facts['distribution_major_version'] is defined

- include_tasks: fetch_zipfile_from_rhn_and_deploy.yml
vars:
zipfile: "{{ tomcat_zipfile }}"
zipfile_url: "{{ tomcat.rhn.server_zipfile_url }}"
path_to_zipfile: "{{ tomcat_install_dir }}/{{ tomcat_zipfile }}"
when:
- not native_archive_path.stat.exists
- native_zipfile_url is defined
- native_zipfile_url | length > 0
- tomcat_zipfile is defined

- name: Copy archives to target nodes
ansible.builtin.copy:
src: "{{ local_path.stat.path }}/{{ item }}"
dest: "{{ tomcat_install_dir }}/{{ item }}"
owner: "{{ tomcat.user }}"
group: "{{ tomcat.group }}"
mode: 0640
register: new_version_downloaded
loop:
- "{{ tomcat_zipfile }}"
- "{{ native_zipfile }}"
- include_tasks: fetch_zipfile_from_rhn_and_deploy.yml
vars:
zipfile: "{{ native_zipfile }}"
zipfile_url: "{{ tomcat.rhn.server_zipfile_url }}"
path_to_zipfile: "{{ tomcat_install_dir }}/{{ tomcat_zipfile }}"
when:
- not archive_path.stat.exists or not native_archive_path.stat.exists
- local_archive_path.stat is defined
- local_archive_path.stat.exists
become: yes
- native_zipfile is defined

0 comments on commit 78a9750

Please sign in to comment.