我对Ansible很新,我似乎无法使用“with_items”迭代路径中的项目。
下面是示例代码,用于浏览路径中的某些文件并将配置应用于Juniper路由器。
---
- name: Get Juniper Device Facts
hosts: "junos_devices"
gather_facts: false
connection: local
tasks:
- name: Update prefix-lists
junos_config:
src: prefix-lists/{{item}}
with_items: "/home/python/prefix-lists/*"
我得到的错误是:
failed: [192.168.216.66] (item=/home/python/prefix-lists/*) => {"changed": false, "failed": true, "item": "/home/python/prefix-lists/*", "msg": "path specified in src not found"}
有谁知道我为什么不能这样做?
答案 0 :(得分:2)
为什么with_items
?使用with_fileglob。
来自例子:
# copy each file over that matches the given pattern
- name: Copy each file over that matches the given pattern
copy:
src: "{{ item }}"
dest: "/etc/fooapp/"
owner: "root"
mode: 0600
with_fileglob:
- "/playbooks/files/fooapp/*"