Ansible - 迭代路径中的项目的问题

问题描述 投票:0回答:1

我对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"}

有谁知道我为什么不能这样做?

loops path ansible
1个回答
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/*"
© www.soinside.com 2019 - 2024. All rights reserved.