Ansible 不可能的错误';重试次数';不是TaskInclude的有效属性

Ansible 不可能的错误';重试次数';不是TaskInclude的有效属性,ansible,ps,retry-logic,until-loop,Ansible,Ps,Retry Logic,Until Loop,我的要求是运行脚本stop all多次(5次重试),直到ps-fu user1 | wc-l的输出小于2 我为此写了以下ansible剧本: cat stop.yml - hosts: dest_nodes tasks: - name: Start service include_tasks: "{{ playbook-dir }}/inner.yml" retries: 5 delay: 4 until:

我的要求是运行脚本
stop all
多次(5次重试),直到
ps-fu user1 | wc-l
的输出小于2

我为此写了以下ansible剧本:

cat stop.yml

  - hosts: dest_nodes
    tasks:
      - name: Start service
        include_tasks: "{{ playbook-dir }}/inner.yml"
        retries: 5
        delay: 4
        until: stopprocesscount.stdout is version('2', '<')


cat inner.yml

      - name: Start service
          shell: ~/stop-all
          register: stopprocess

      - name: Start service
          shell: ps -fu user1 |wc -l
          register: stopprocesscount

您能提出建议吗?

首先,更正
inner.yml
中任务的缩进。其次,从
stop.yml
中删除
重试
延迟
直到
,并将它们移动到特定任务,因为它们是任务级参数

因为您需要基于另一个任务重试一个任务,所以您可以将脚本和命令组合起来,并提取wc-l命令的结果,如下所示:

由于stdout_行将包含字符串列表,而version需要int,因此需要进行转换

inner.yml


并非所有任务属性都适用于所有任务(此处为TaskInclude task)

没有明确的文档,例如兼容性矩阵,但是这里的错误消息非常清楚“不是有效的属性”

举例来说:

不能循环块:
“with\u items”不是块的有效属性


无法异步TaskInclude,请参阅。

更正internal.yml不能解决问题。我继续得到相同的错误。添加了完整的解决方案谢谢,我将在接下来的4小时内测试此解决方案,如果它有效,我将接受答案。
ERROR! 'retries' is not a valid attribute for a TaskInclude

The error appears to be in '/app/playbook/stop.yml': line 19, column 9, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:


      - name: Start service
        ^ here
  - name: Start service
    shell: ~/stop-all; ps -fu user1 | wc -l
    register: stopprocesscount
    retries: 5
    delay: 4
    until: stopprocesscount.stdout_lines[stopprocesscount.stdout_lines | length - 1] | int  is version('2', '<')
  - hosts: dest_nodes
    tasks:
      - name: Start service
        include_tasks: "{{ playbook-dir }}/inner.yml"