Ansible v2.4.0.0
我正在安装Gitlab-CE,我在Ansible任务中运行以下命令。正如您所看到的,某些流程已经停止,但它们最终会出现。
# gitlab-ctl status
run: gitlab-workhorse: 0s, normally up
run: logrotate: 1s, normally up
down: nginx: 0s, normally up
down: postgresql: 1s, normally up
run: redis: 0s, normally up
run: sidekiq: 0s, normally up
run: unicorn: 0s, normally up
如何编写Ansible wait_for任务来检查所有服务何时处于运行状态? IOW我只想在看到这个
时继续下一个任务# gitlab-ctl status
run: gitlab-workhorse: 0s, normally up
run: logrotate: 1s, normally up
run: nginx: 0s, normally up
run: postgresql: 1s, normally up
run: redis: 0s, normally up
run: sidekiq: 0s, normally up
run: unicorn: 0s, normally up
答案 0 :(得分:9)
您可以使用retries
/ until
方法:
- command: gitlab-ctl status
register: cmd_res
retries: 5
until: cmd_res.stdout_lines | reject('search','^run') | list | count == 0
我们从以run
开头的输出中删除任何一行并计算它们。只有当没有这样的行时,才继续执行下一个任务。