您可以使用此任务检查应用程序是否已在运行。如果运行,它将中止播放本。
- name: Check if service is running by querying the application port
wait_for:
port: 22
timeout: 10
state: stopped
msg: "Port 22 is accessible, application is already installed and running"
register: service_status
基本上,您使用的模块
state: stopped
Ansible希望端口停止监听
timeout
秒。如果端口保持运行10秒(由于没有人停止已安装的应用程序,端口将保持运行),Ansible将退出并出错。
将端口更改为23,您将看到Playbook将继续下一步:
tasks:
- name: Check if service is running by querying the application port
wait_for:
port: 23
timeout: 10
state: stopped
msg: "Port 23 is accessible, application is already installed and running"
register: service_status
- name: print
debug:
var: service_status
你不需要
register
子句,只是为我的测试添加的。
希望有帮助