Skip to content

Commit

Permalink
Add molecule config for tomcat role
Browse files Browse the repository at this point in the history
  • Loading branch information
p-j-smith committed Mar 24, 2024
1 parent f2bc548 commit 056a7a3
Show file tree
Hide file tree
Showing 7 changed files with 156 additions and 0 deletions.
53 changes: 53 additions & 0 deletions roles/tomcat/molecule/centos7/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
# test this scenario from the roles/tomcat directory with the command
# molecule --base-config ../../molecule_configs/centos7_base_config.yml test --scenario centos7
platforms:
- name: tomcat9_server
hostname: molecule.tomcat9.local
image: ${MOLECULE_DOCKER_IMAGE:-geerlingguy/docker-centos7-ansible:latest}
required: true
command: ""
cgroupns_mode: host
privileged: true
pre_build_image: ${MOLECULE_PRE_BUILD_IMAGE:-true}
volumes:
- ./tomcat9-data:/storage/molecule/tomcat9
keep_volumes: false
groups:
- all
- molecule
- centos7
- tomcat9
docker_networks:
- name: molecule
ipam_config:
- subnet: 192.168.56.0/24
gateway: 192.168.56.1
networks:
- name: molecule
ipv4_address: 192.168.56.2

- name: tomcat10_server
hostname: molecule.tomcat10.local
image: ${MOLECULE_DOCKER_IMAGE:-geerlingguy/docker-centos7-ansible:latest}
required: true
command: ""
cgroupns_mode: host
privileged: true
pre_build_image: ${MOLECULE_PRE_BUILD_IMAGE:-true}
volumes:
- ./tomcat10-data:/storage/molecule/tomcat10
keep_volumes: false
groups:
- all
- molecule
- centos7
- tomcat10
docker_networks:
- name: molecule
ipam_config:
- subnet: 192.168.56.0/24
gateway: 192.168.56.1
networks:
- name: molecule
ipv4_address: 192.168.56.3
7 changes: 7 additions & 0 deletions roles/tomcat/molecule/resources/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
- name: Install Tomcat
hosts: all
become: true
gather_facts: true
roles:
- role: mirsg.infrastructure.tomcat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
tomcat_version: 10.1.19
12 changes: 12 additions & 0 deletions roles/tomcat/molecule/resources/prepare.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
- name: Prepare - install sudo and Java
hosts: all
gather_facts: true
pre_tasks:
- name: Install sudo
ansible.builtin.package:
name: sudo
state: present
roles:
- role: mirsg.infrastructure.install_java
java_package: "{{ 'java-11-openjdk' if 'tomcat10' in group_names else 'java-1.8.0-openjdk'}}"
31 changes: 31 additions & 0 deletions roles/tomcat/molecule/resources/verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
- name: Verify correct tomcat version is installed and running
hosts: all
tasks:
- name: Get status of all services
ansible.builtin.service_facts:

- name: Check tomcat is enabled and running
ansible.builtin.assert:
that:
- ansible_facts.services["tomcat.service"].state == "running"
- ansible_facts.services["tomcat.service"].status == "enabled"

- name: Check installed Tomcat version
ansible.builtin.shell: |
set -o pipefail
./version.sh | grep -oP '(?<=Apache Tomcat/)([0-9]+\.?)+'
args:
chdir: "/usr/share/tomcat/bin"
register: tomcat_check_version

- name: Print version
ansible.builtin.debug:
var: tomcat_check_version.stdout

- name: Check Tomcat version is correct
ansible.builtin.assert:
that:
- tomcat_check_version.stdout.split(".")[0] is version(expected_version)
vars:
expected_version: "{{ '10' if 'tomcat10' in group_names else '9' }}"
50 changes: 50 additions & 0 deletions roles/tomcat/molecule/rocky9/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
# test this scenario from the roles/tomcat directory with the command
# molecule --base-config ../../molecule_configs/rocky9_base_config.yml test --scenario rocky9
platforms:
- name: tomcat9_server
hostname: molecule.tomcat9.local
image: rockylinux/rockylinux:9-ubi-init
required: true
command: ""
cgroupns_mode: host
privileged: true
pre_build_image: ${MOLECULE_PRE_BUILD_IMAGE:-true}
volumes:
- ./tomcat9-data:/storage/molecule/tomcat9
- /sys/fs/cgroup:/sys/fs/cgroup:rw
keep_volumes: false
groups:
- all
- molecule
- rocky9
- tomcat9
docker_networks:
- name: molecule
ipam_config:
- subnet: 192.168.56.0/24
gateway: 192.168.56.1
networks:
- name: molecule
ipv4_address: 192.168.56.2

- name: tomcat10_server
hostname: molecule.tomcat10.local
image: rockylinux/rockylinux:9-ubi-init
required: true
command: ""
cgroupns_mode: host
privileged: true
pre_build_image: ${MOLECULE_PRE_BUILD_IMAGE:-true}
volumes:
- ./tomcat10-data:/storage/molecule/tomcat10
- /sys/fs/cgroup:/sys/fs/cgroup:rw
keep_volumes: false
groups:
- all
- molecule
- rocky9
- tomcat10
networks:
- name: molecule
ipv4_address: 192.168.56.3

0 comments on commit 056a7a3

Please sign in to comment.