Skip to content

Commit

Permalink
lint: for a firstful of fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rpelisse committed Sep 19, 2024
1 parent b5993b7 commit 99c6e1e
Show file tree
Hide file tree
Showing 12 changed files with 113 additions and 103 deletions.
1 change: 1 addition & 0 deletions .ansible-lint
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ enable_list:
skip_list:
- file_is_small_enough
- vars_should_not_be_used
- args[module]

warn_list:
- role_vars_start_with_role_name
Expand Down
1 change: 1 addition & 0 deletions roles/quarkus/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ quarkus_app_src_dir_remote: true
quarkus_app_user: quarkus_app
quarkus_app_validation_host: localhost
quarkus_app_workdir: '/tmp/workdir'
quarkus_app_already_deployed: False

quarkus_deploy_app_as_systemd_service_requires_privilege_escalation: True
quarkus_deploy_app: True
Expand Down
13 changes: 7 additions & 6 deletions roles/quarkus/meta/main.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
---
galaxy_info:
role_name: quarkus
namespace: middleware_automation
author: Romain Pelisse
description: Install ...
description: Automate the installation and deployement of a Quarkus application
company: Red Hat, Inc.

license: Apache License 2.0

min_ansible_version: "2.9"
min_ansible_version: "2.16"

platforms:
- name: EL
versions:
- 8

- name: EL
versions:
- "8"
- "9"
galaxy_tags:
- quarkus
- redhat
Expand Down
12 changes: 6 additions & 6 deletions roles/quarkus/tasks/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,21 @@
- name: "Load metadata on source directory"
ansible.builtin.stat:
path: "{{ quarkus_app_workdir }}"
register: source_dir
register: quarkus_source_dir

- name: "Ensure that source dir exists"
ansible.builtin.assert:
that:
- source_dir is defined and source_dir.stat is defined
- source_dir.stat.exists is defined and source_dir.stat.exists
- quarkus_source_dir is defined and quarkus_source_dir.stat is defined
- quarkus_source_dir.stat.exists is defined and quarkus_source_dir.stat.exists
quiet: True
fail_msg: "The root folder of the Quarkus project does not exits: {{ quarkus_app_workdir }}"

- name: "Build the App using Maven with JAVA_HOME: {{ quarkus_java_home }}"
become: "{{ quarkus_app_dir_requires_become }}"
become_user: "{{ quarkus_app_dir_become_user }}"
ansible.builtin.command: "{{ quarkus_build_shell_interpreter }} {{ path_to_mvn }} {{ quarkus_maven_build_opts }} package"
register: mvn_build
ansible.builtin.command: "{{ quarkus_build_shell_interpreter }} {{ quarkus_path_to_mvn }} {{ quarkus_maven_build_opts }} package"
register: quarkus_mvn_build
environment:
JAVA_HOME: "{{ quarkus_java_home }}"
args:
Expand All @@ -90,6 +90,6 @@

- name: "Display build application log"
ansible.builtin.debug:
var: "{{ mvn_build.stdout | split('\n') }}}"
var: "{{ quarkus_mvn_build.stdout | split('\n') }}}"
when:
- display_mvn_output is defined
2 changes: 1 addition & 1 deletion roles/quarkus/tasks/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
- not quarkus_app_src_dir is defined

- name: "Deploy application as a systemd service on target system."
ansible.builtin.include_tasks: deploy/service.yml
ansible.builtin.include_tasks: deploy/main.yml

- name: "Ensure firewalld configuration is appropriate (if requested)."
ansible.builtin.include_tasks: deploy/firewalld.yml
Expand Down
10 changes: 10 additions & 0 deletions roles/quarkus/tasks/deploy/app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
- name: "Deploy application to target system"
ansible.builtin.copy:
src: "{{ quarkus_app_src_dir | regex_replace('\\/$', '') }}"
dest: "{{ quarkus_path_to_folder_to_deploy }}"
owner: "{{ quarkus_app_user | default(omit) }}"
group: "{{ quarkus_app_group | default(omit) }}"
remote_src: "{{ quarkus_app_src_dir_remote }}"
mode: 0755
changed_when: "{{ quarkus_app_update | default(false) }}"
11 changes: 11 additions & 0 deletions roles/quarkus/tasks/deploy/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
- name: "Ensure Quarkus app is running as a systemd service on target"
become: "{{ quarkus_deploy_app_as_systemd_service_requires_privilege_escalation | default(True) }}"
block:
- name: "Ensure app is deployed on target (unless deployment disabled)"
ansible.builtin.include_tasks: app.yml
when:
- quarkus_app_already_deployed is defined and not quarkus_app_already_deployed

- name: "Ensure app is running as a service on target"
ansible.builtin.include_tasks: service.yml
95 changes: 41 additions & 54 deletions roles/quarkus/tasks/deploy/service.yml
Original file line number Diff line number Diff line change
@@ -1,58 +1,45 @@
---
- name: "Ensure Quarkus app is running as a systemd service on target"
become: "{{ quarkus_deploy_app_as_systemd_service_requires_privilege_escalation | default(True) }}"
block:
- name: "Deploy application to target system"
ansible.builtin.copy:
src: "{{ quarkus_app_src_dir | regex_replace('\\/$', '') }}"
dest: "{{ quarkus_path_to_folder_to_deploy }}"
owner: "{{ quarkus_app_user | default(omit) }}"
group: "{{ quarkus_app_group | default(omit) }}"
remote_src: "{{ quarkus_app_src_dir_remote }}"
mode: 0755
changed_when: "{{ quarkus_app_update | default(false) }}"
- name: "Ensure environment file for service is deployed ({{ quarkus_deploy_systemd_service_env_conf }}"
ansible.builtin.template:
src: "{{ quarkus_deploy_systemd_service_env_template }}"
dest: "{{ quarkus_deploy_systemd_service_env_conf }}"
owner: "{{ quarkus_app_user | default(omit) }}"
group: "{{ quarkus_app_group | default(omit) }}"
mode: 0640
notify:
- 'Restart Quarkus App'
when:
- quarkus_deploy_systemd_service_env_template is defined
- quarkus_deploy_systemd_service_env_template | length > 0

- name: "Ensure environment file for service {{ quarkus_app_service_name }} is deployed ({{ quarkus_deploy_systemd_service_env_conf }}"
ansible.builtin.template:
src: "{{ quarkus_deploy_systemd_service_env_template }}"
dest: "{{ quarkus_deploy_systemd_service_env_conf }}"
owner: "{{ quarkus_app_user | default(omit) }}"
group: "{{ quarkus_app_group | default(omit) }}"
mode: 0640
notify:
- 'Restart Quarkus App'
when:
- quarkus_deploy_systemd_service_env_template is defined
- quarkus_deploy_systemd_service_env_template | length > 0
- name: "Ensure Systemd configuration for Quarkus app is deployed"
ansible.builtin.template:
src: "{{ quarkus_systemd_service_template }}"
dest: "{{ quarkus_systemd_home }}/{{ quarkus_app_service_name }}.service"
owner: "{{ quarkus_app_user | default(omit) }}"
group: "{{ quarkus_app_group | default(omit) }}"
mode: 0640
register: quarkus_deploy_systemd_service_config
notify:
- "Perform daemon-reload"
vars:
service_user: "{{ quarkus_app_user | default(omit) }}"
service_group: "{{ quarkus_app_group | default(omit) }}"
when:
- quarkus_app_service_name is defined

- name: "Ensure Systemd configuration for Quarkus app is deployed"
ansible.builtin.template:
src: "{{ quarkus_systemd_service_template }}"
dest: "{{ quarkus_systemd_home }}/{{ quarkus_app_service_name }}.service"
owner: "{{ quarkus_app_user | default(omit) }}"
group: "{{ quarkus_app_group | default(omit) }}"
mode: 0640
register: quarkus_deploy_systemd_service_config
notify:
- "Perform daemon-reload"
vars:
service_user: "{{ quarkus_app_user | default(omit) }}"
service_group: "{{ quarkus_app_group | default(omit) }}"
when:
- quarkus_app_service_name is defined
- name: "Perform daemon-reload immediatly if systemd config was changed."
ansible.builtin.meta: flush_handlers
when:
- quarkus_app_service_name is defined
- quarkus_deploy_systemd_service_config is defined
- quarkus_deploy_systemd_service_config.changed is defined
- quarkus_deploy_systemd_service_config.changed

- name: "Perform daemon-reload immediatly if systemd config was changed."
ansible.builtin.meta: flush_handlers
when:
- quarkus_app_service_name is defined
- quarkus_deploy_systemd_service_config is defined
- quarkus_deploy_systemd_service_config.changed is defined
- quarkus_deploy_systemd_service_config.changed

- name: "Ensure Quarkus app service is running."
ansible.builtin.service:
name: "{{ quarkus_app_service_name }}"
state: started
enabled: true
when:
- quarkus_app_service_name is defined
- name: "Ensure Quarkus app service is running as service {{ quarkus_app_service_name }}"
ansible.builtin.service:
name: "{{ quarkus_app_service_name }}"
state: started
enabled: true
when:
- quarkus_app_service_name is defined
14 changes: 7 additions & 7 deletions roles/quarkus/tasks/java.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
- name: "Ensure that builder host {{ quarkus_builder_host }} has appropriate JDK installed: {{ quarkus_java_package_version }}"
- name: "Ensure that builder host has the appropriate JDK installed: {{ quarkus_java_package_version }}"
ansible.builtin.dnf:
name: "{{ quarkus_java_package_version }}"
state: present
Expand All @@ -11,17 +11,17 @@
- name: "Ensure that JAVA_HOME exists: {{ quarkus_java_home }}"
ansible.builtin.include_tasks: path_exists.yml
vars:
path_to_file: "{{ quarkus_java_home }}"
file_isdir: "{{ quarkus_java_home_isdir }}"
file_islnk: "{{ quarkus_java_home_islnk }}"
quarkus_path_to_file: "{{ quarkus_java_home }}"
quarkus_file_isdir: "{{ quarkus_java_home_isdir }}"
quarkus_file_islnk: "{{ quarkus_java_home_islnk }}"

- name: "Ensure that exists and is executable"
ansible.builtin.include_tasks: path_exists.yml
loop:
- javac
- java
loop_control:
loop_var: java_utility
loop_var: quarkus_java_utility
vars:
path_to_file: "{{ quarkus_java_home }}/bin/{{ java_utility }}"
file_isexec: True
quarkus_path_to_file: "{{ quarkus_java_home }}/bin/{{ quarkus_java_utility }}"
quarkus_file_isexec: True
21 changes: 10 additions & 11 deletions roles/quarkus/tasks/mvn.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@

- name: "Set full path to mvnw"
ansible.builtin.set_fact:
path_to_mvn: "{{ quarkus_app_workdir }}/{{ quarkus_app_source_folder | default('') }}/mvnw"
quarkus_path_to_mvn: "{{ quarkus_app_workdir }}/{{ quarkus_app_source_folder | default('') }}/mvnw"

- name: "Ensure that path to the mvn binary has been defined"
ansible.builtin.assert:
that:
- path_to_mvn is defined and path_to_mvn | length > 0
- quarkus_path_to_mvn is defined and quarkus_path_to_mvn | length > 0
fail_msg: "Path to mvn is NOT defined or null or pointing to an unexisting file"

- name: "App build uses Maven directly (not mvnw)"
Expand All @@ -32,12 +32,12 @@
quiet: True
fail_msg: "Can't ensure Maven is properly installed on quarkus_builder_host if quarkus_maven_download_url is not provided"

- name: "Install Maven from {{ quarkus_maven_download_url }} on builder host [{{ quarkus_builder_host }}]"
- name: "Install Maven on builder host from {{ quarkus_builder_host }}"
become: "{{ quarkus_maven_homedir_requires_privileges }}"
become_user: "{{ quarkus_maven_homedir_user }}"
delegate_to: "{{ quarkus_builder_host }}"
block:
- name: "Ensure parent dir for Maven archive exists."
- name: "Ensure parent dir for Maven archive exists on builder host: {{ quarkus_maven_homedir }}"
ansible.builtin.file:
path: "{{ quarkus_maven_homedir }}"
state: directory
Expand All @@ -46,7 +46,6 @@
mode: 0755

- name: "Retrieve, if needed, archive from {{ quarkus_maven_download_url }}"

ansible.builtin.unarchive:
src: "{{ quarkus_maven_download_url }}"
dest: "{{ quarkus_maven_homedir }}"
Expand All @@ -55,17 +54,17 @@

- name: "Set full path to mvnw"
ansible.builtin.set_fact:
path_to_mvn: "{{ quarkus_maven_homedir }}/{{ quarkus_maven_homedir_name }}/bin/mvn"
quarkus_path_to_mvn: "{{ quarkus_maven_homedir }}/{{ quarkus_maven_homedir_name }}/bin/mvn"

- name: "Load metadata on {{ path_to_mvn }}"
- name: "Load metadata on {{ quarkus_path_to_mvn }}"
delegate_to: "{{ quarkus_builder_host }}"
ansible.builtin.stat:
path: "{{ path_to_mvn }}"
register: stat_path_to_mvn
path: "{{ quarkus_path_to_mvn }}"
register: quarkus_stat_path_to_mvn

- name: "Ensure that path to the mvn binary points to an existing file"
ansible.builtin.assert:
that:
- stat_path_to_mvn is defined and stat_path_to_mvn.stat is defined
- stat_path_to_mvn.stat.exists is defined and stat_path_to_mvn.stat.exists
- quarkus_stat_path_to_mvn is defined and quarkus_stat_path_to_mvn.stat is defined
- quarkus_stat_path_to_mvn.stat.exists is defined and quarkus_stat_path_to_mvn.stat.exists
fail_msg: "Path to mvn points to an unexisting file"
34 changes: 17 additions & 17 deletions roles/quarkus/tasks/path_exists.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,46 @@
- name: "Ensure required parameters are provided."
ansible.builtin.assert:
that:
- path_to_file is defined and path_to_file | length > 0
- quarkus_path_to_file is defined and quarkus_path_to_file | length > 0
quiet: True
fail_msg: "No variable named path_to_file provided."
fail_msg: "No variable named quarkus_path_to_file provided."

- name: "Load metadata on {{ path_to_file }}."
- name: "Load metadata on {{ quarkus_path_to_file }}."
ansible.builtin.stat:
path: "{{ path_to_file }}"
register: file_stat
path: "{{ quarkus_path_to_file }}"
register: quarkus_file_stat

- name: "Ensure that following file exists: {{ path_to_file }}"
- name: "Ensure that following file exists: {{ quarkus_path_to_file }}"
ansible.builtin.assert:
that:
- file_stat is defined and file_stat.stat is defined and file_stat.stat.exists is defined and file_stat.stat.exists
- quarkus_file_stat is defined and quarkus_file_stat.stat is defined and quarkus_file_stat.stat.exists is defined and quarkus_file_stat.stat.exists
quiet: True
fail_msg: "The file {{ path_to_file }} does not exist."
fail_msg: "The file {{ quarkus_path_to_file }} does not exist."

- name: "Ensure that file is a directory (if requested)."
ansible.builtin.assert:
that:
- file_stat is defined and file_stat.stat is defined
- file_stat.stat.isdir is defined and file_stat.stat.isdir
- quarkus_file_stat is defined and quarkus_file_stat.stat is defined
- quarkus_file_stat.stat.isdir is defined and quarkus_file_stat.stat.isdir
quiet: True
fail_msg: "The file {{ path_to_file }} is NOT a directory."
fail_msg: "The file {{ quarkus_path_to_file }} is NOT a directory."
when:
- file_isdir is defined and file_isdir

- name: "Ensure that file is a link (if requested)."
ansible.builtin.assert:
that:
- file_stat is defined and file_stat.stat is defined
- file_stat.stat.islnk is defined and file_stat.stat.islnk
- quarkus_file_stat is defined and quarkus_file_stat.stat is defined
- quarkus_file_stat.stat.islnk is defined and quarkus_file_stat.stat.islnk
quiet: True
fail_msg: "The file {{ path_to_file }} is NOT a link."
fail_msg: "The file {{ quarkus_path_to_file }} is NOT a link."
when:
- file_islnk is defined and file_islnk
- quarkus_file_islnk is defined and quarkus_file_islnk

- name: "Ensure that the file is executable (if requested)."
ansible.builtin.assert:
that:
- file_stat is defined and file_stat.stat is defined
- file_stat.stat.executable is defined and file_stat.stat.executable
- quarkus_file_stat is defined and quarkus_file_stat.stat is defined
- quarkus_file_stat.stat.executable is defined and quarkus_file_stat.stat.executable
when:
- file_isexec is defined and file_isexec
2 changes: 1 addition & 1 deletion roles/quarkus/tasks/validate_deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
- name: "Ensure that webapp is reachable"
ansible.builtin.uri:
url: "http://{{ quarkus_app_validation_host }}:{{ quarkus_app_port }}/{{ item.path }}"
status_code: "{{ item.status_code | default(200) }}"
status_code: "{{ item.status_code | default(200) | int }}"
changed_when: false
loop: "{{ quarkus_app_validation_paths }}"
when:
Expand Down

0 comments on commit 99c6e1e

Please sign in to comment.