如何使用 Ansible wait_for 检查多行命令状态?

How to use Ansible wait_for to check a command status with multiple lines?

A​​nsible 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

可以使用retries/until方法:

- command: gitlab-ctl status
  register: cmd_res
  retries: 5
  until: cmd_res.stdout_lines | reject('search','^run') | list | count == 0

我们从输出中删除任何以 run 开头的行并计算它们。只有当没有这样的行时才进行下一个任务。