ansible - 错误!“重试”不是 TaskInclude 的有效属性
问题描述
我的要求是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
但是,运行剧本时出现以下错误。
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
你能建议吗?
解决方案
首先,更正中任务的缩进inner.yml
。其次,删除retries
和delay
fromuntil
并将stop.yml
它们移动到特定任务,因为这些是任务级参数。
由于您需要基于另一个任务重试一个任务,您可以将脚本和命令结合起来,提取 wc -l 命令的结果,如下所示:
由于 stdout_lines 将包含字符串列表和版本需要 int 因此转换。
内部.yml
- 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', '<')
停止.yml
- hosts: dest_nodes
tasks:
- name: Start service
include_tasks: "{{ playbook-dir }}/inner.yml"
推荐阅读
- user-interface - 如何限制列内多个文本字段的宽度?用 SizedBox 包裹后者不起作用
- vue.js - Vuetify v-tabs 长时间切换标签
- azure - Azure 数据工厂 Rest API 分页问题
- bazel - Bazel 编译有很多不同的目标,哪些是坏的?
- postgresql - 我正在尝试使用 lpad SQL 函数,但它抛出 lpad(text) 不存在
- java - Java 打印值列表
- windows - Doom Emacs 在 Windows 10 上启动缓慢并闪烁
- swift - 添加 APNSSwift 依赖项。但它不工作
- php - 如何避免在 Symfony Messenger 中处理来自“子”类的消息?
- python - noobie 遍历列表以显示系列