【发布时间】:2022-08-02 19:23:25
【问题描述】:
我有一个主要的剧本,它使用include 在满足条件时调用其他剧本。这工作正常,但我需要将这些剧本执行n 次,其中n 是用户输入变量。因此,如果用户输入“5”,主 playbook 将调用 playbooks 5 次。
这是一个例子:
---
- name: main playbook
hosts: localhost
connection: local
gather_facts: False
var_files: weqwewq
tasks:
- include: 1.yml
when: x == \"aaa\"
- include: 2.yml
when: x == \"bbb\"
- include: 3.yml
when: x == \"ccc\"
- include: 4.yml
when: x == \"ddd\"
我不需要的是这个:
tasks:
- include: 1.yml
when: x == \"aaa\"
with_sequence: count= \"{{ user_input }}\"
- include: 2.yml
when: x == \"aaa+bbb\"
with_sequence: count= \"{{ user_input }}\"
- include: 3.yml
when: x == \"ccc\"
with_sequence: count= \"{{ user_input }}\"
- include: 4.yml
when: x == \"ccc+ddd\"
with_sequence: count= \"{{ user_input }}\"
而是像这样
tasks:
with_sequence: count= \"{{ user_input }}\"
- include: 1.yml
when: x == \"aaa\"
- include: 2.yml
when: x == \"aaa+bbb\"
- include: 3.yml
when: x == \"ccc\"
- include: 4.yml
when: x == \"ccc+ddd\"
但为此我得到一个错误:
\"with_sequence 不是播放的有效属性\"。
任何想法?
谢谢!