- name: Create Dirs for rs disk
file:
name: "{{ /rs{{ items }}"
state: directory
with_sequence: start=1 end={{ disk_group[inventory_hostname]['rs'] | length }}
when: disk_group[inventory_hostname]['rs'] is defined
当“ when”子句为false时,“ with_sequence”中未定义如何避免可变的错误。
事实上,使用ignore_errors可以做到这一点,但我确实认为这不是一个好主意。
答案 0 :(得分:0)
您可能想尝试 include_tasks
的此示例> cat task.yml
- debug: var=item
with_sequence: start=1 end={{ rs|length }}
> cat playbook.yml
- hosts: localhost
vars:
# rs: test
tasks:
- include_tasks: task.yml
when: rs is defined