如何在Ansible剧本中等待tomcat服务器启动

问题描述 投票:0回答:1

这可能是一个很奇怪的问题,我已经尝试过搜索,但是找不到我想要的东西。我有一个下面的剧本,它启动tomcat并检查状态。我该如何设定条件,等待剧本完成后才能上线。我研究了wait_for模块,但无法放入剧本中。

---
 - name: Starting tomcat service on remote host
   shell: "svcadm enable tomcat"
   ignore_errors: true

 - pause:
     seconds: 10

 - name: Check the State of tomcat service on the remote host
   shell: "svcs tomcat"
   register: tomcat_status

 - set_fact:
     tomcat_state: "{{ tomcat_status.stdout_lines.1.split().0 }}"

tomcat_state的值应为“ online”,告诉我们tomcat已经启动。

我们在这里有什么可以做的,或者可以采用其他方法吗?感谢有人可以提供一些意见

ansible ansible-inventory
1个回答
0
投票
- name: wait for completion
  wait_for:
      port: <your_port>
      delay: 60
      timeout: 500

以这种方式,此任务等待60秒,然后检查指定端口上是否有问题,并尝试500s

© www.soinside.com 2019 - 2024. All rights reserved.