Ansible with_items 如果定义了 item [英] Ansible with_items if item is defined
本文介绍了Ansible with_items 如果定义了 item的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Ansible 1.9.4.
Ansible 1.9.4.
脚本应该只在定义了某些变量的主机上执行某些任务.它正常工作,但它不适用于 with_items
语句.
The script should execute some task only on hosts where some variable is defined. It works fine normally, but it doesn't work with the with_items
statement.
- debug: var=symlinks
when: symlinks is defined
- name: Create other symlinks
file: src={{ item.src }} dest={{ item.dest }} state=link
with_items: "{{ symlinks }}"
when: symlinks is defined
但我明白了:
TASK: [app/symlinks | debug var=symlinks] *********************
skipping: [another-host-yet]
TASK: [app/symlinks | Create other symlinks] ******************
fatal: [another-host-yet] => with_items expects a list or a set
也许我做错了什么?
推荐答案
with_items: "{{ symlinks | default([]) }}"
这篇关于Ansible with_items 如果定义了 item的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文