I am writing a script for automation deployment and I have come across a weird scenario.
When i stop tomcat using command svcadm disable tomcat it can go to 2 states - maintenence OR disabled. When it goes into disabled state then it means tomcat has been stopped gracefully but when it goes into maintenence state it means it hasn't been stopped properly and I have to run the svcadm disable tomcat again to make it in disabled state.
Below is my playbook main.yml for role stopping tomcat - Here 1st I am stopping the tomcat so when the first task occurs, it gracefully starts stopping but remains in online state for some time (few seconds). So I am trying to check the status of tomcat using svcs tomcat whether it's in disabled state OR maintenence state. The OR condition with until is not working here.
- name: Stopping tomcat Service on remote host
shell: "svcadm disable tomcat"
ignore_errors: true
- name: Verifying tomcat service status to make sure it is in disabled state.
shell: "svcs tomcat"
register: result
until: result.stdout_lines.1.split().0 == "disabled" or result.stdout_lines.1.split().0 == "maintenance"
retries: 10
delay: 10
- shell: "svcadm disable tomcat"
when: (tomcat_status.stdout_lines.1.split().0) == "maintenance"
I am not sure if it is the correct approach here but is there any other better way to achieve this task?
The thing is after running the scvadm disable tomcat command, tomcat could be in any of the 3 states - online OR maintenence OR disabled.
I can't process further until my tomcat goes into disabled mode.
Let me know if anyone can advice on this please.