Skip to content

Commit

Permalink
Move validation logic to verify.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
rpelisse committed Mar 21, 2022
1 parent 372a43c commit c702899
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 51 deletions.
9 changes: 1 addition & 8 deletions molecule/default/converge.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,2 @@
---
- name: Converge
hosts: all
vars:
tomcat_install_dir: /opt
tasks:
- name: "Include tomcat"
include_role:
name: "jws"
- import_playbook: ../../playbook.yml
4 changes: 3 additions & 1 deletion molecule/default/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ platforms:
provisioner:
name: ansible
playbooks:
converge: ../../playbook.yml
prepare: prepare.yml
converge: converge.yml
verify: verify.yml
env:
CATALINA_HOME: "/opt/apache-tomcat-9.0.50"
inventory:
Expand Down
7 changes: 7 additions & 0 deletions molecule/default/prepare.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
- name: Prepare
hosts: all
tasks:
- name: Display Ansible version
debug:
msg: "Ansible version is {{ ansible_version.full }}"
34 changes: 34 additions & 0 deletions molecule/default/verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
- name: Verify
hosts: instance
vars:
tomcat_listen_http_bind_address: 127.0.0.1
tomcat_listen_http_port: 8080
tasks:
- name: Populate service facts
ansible.builtin.service_facts:

- name: Check if service is started
assert:
that:
- ansible_facts is defined
- ansible_facts.services is defined
- ansible_facts.services['tomcat.service'] is defined
- ansible_facts.services['tomcat.service']['state'] is defined
- ansible_facts.services["tomcat.service"]['state'] == 'running'
quiet: true
fail_msg: "Service is not started."

- name: Slurp the content of catalina.out
ansible.builtin.slurp:
src: /opt/apache-tomcat-9.0.50/logs/catalina.out
register: catalina_out

- name: Print the content of catalina.out
ansible.builtin.debug:
msg: "{{ catalina_out['content'] | b64decode | length }}"

- name: "Ensure Tomcat is started and listen to appropriate port"
wait_for:
host: "{{ tomcat_listen_http_bind_address }}"
port: "{{ tomcat_listen_http_port }}"
42 changes: 0 additions & 42 deletions playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,45 +47,3 @@
dest: "{{ tomcat_zipfile }}"
when:
- tomcat_download_url is defined

post_tasks:

- command: systemctl status tomcat
register: tc_status
changed_when: False

- debug:
msg: "{{ tc_status.stdout }}"

- name: Find out what the remote machine's mounts are
ansible.builtin.slurp:
src: /opt/apache-tomcat-9.0.50/logs/catalina.out
register: catalina_out

- name: Print catalina.out
ansible.builtin.debug:
msg: "{{ catalina_out['content'] | b64decode | length }}"

- name: collect facts about system services
service_facts:
register: services_state

- name: show current role configuration
debug:
msg: "{{ services_state.ansible_facts }}"

- set_fact:
services_list: "{{ services_state.ansible_facts.services }}"

- name: Check that Tomcat service is running
assert:
that:
- services_list is defined
- services_list['tomcat.service'] is defined
- services_list['tomcat.service'].state is defined
- services_list['tomcat.service'].state == "running"

- name: "Ensure Tomcat is started and listen to appropriate port"
wait_for:
host: "{{ tomcat_listen_http_bind_address }}"
port: "8080"

0 comments on commit c702899

Please sign in to comment.