本文介绍了如果定义了项目,则为with_items的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

也许我做错了什么?抱歉,我的英语水平

Maybe I am doing something wrong? sorry for my english

推荐答案

with_items: "{{ symlinks | default([]) }}"

这篇关于如果定义了项目,则为with_items的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 06:58