我正在虚拟机上安装karaf,并且在我的安装过程中,我想验证karaf实例是否已经在运行,并且在端口打开时停止安装过程并退出正确的执行。 目前它以其他方式
- name: Wait for my-service to start wait_for: port={{karaf_port}} timeout=30 msg: "Port 8101 is not accessible."I am installing karaf on VM and in my installation process i want to verify if karaf instance is already running and it stop installation process and exit from ansible execution if port is open. currently its doing other way
- name: Wait for my-service to start wait_for: port={{karaf_port}} timeout=30 msg: "Port 8101 is not accessible."最满意答案
您可以使用此任务来检查应用程序是否已在运行。 如果运行,它会中止剧本。
- 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的模块,并且有理由期望端口以某种方式停止监听timeout秒数。 如果端口保持10秒钟(它会保持不变,因为没有人停止已经安装的应用程序),否则会导致错误退出。
改变端口为23,你会看到剧本将继续下一步:
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条款,只是为我的测试添加。
希望能帮助到你
You could use this task to check if the application is already running. If running, it will abort the playbook.
- 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_statusBasically, you are using the module with state: stopped, and ansible expects the port to somehow stop listening for timeoutseconds. if port stays up for 10 seconds (it will stay up since nobody stops the already installed application), ansible will exit with error.
change port to 23, you will see playbook would continue to next step:
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_statusyou dont need the register clause, just added for my test.
hope it helps
更多推荐
发布评论