Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Loops Ansible-在路径中迭代项的问题_Loops_Path_Ansible - Fatal编程技术网

Loops Ansible-在路径中迭代项的问题

Loops Ansible-在路径中迭代项的问题,loops,path,ansible,Loops,Path,Ansible,我是Ansible的新手,似乎无法使用“with_items”遍历路径中的项 下面是示例代码,用于遍历路径中的一些文件,并将配置应用于JUniter路由器 --- - name: Get Juniper Device Facts hosts: "junos_devices" gather_facts: false connection: local tasks: - name: Update prefix-lists junos_config: src:

我是Ansible的新手,似乎无法使用“with_items”遍历路径中的项

下面是示例代码,用于遍历路径中的一些文件,并将配置应用于JUniter路由器

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

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

为什么
带有项目?使用

例如:

# 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/*"

为什么
带有项目
?使用

例如:

# 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/*"

Hi Konstantin,使用with_fileglob而不是with_items工作,谢谢你的帮助。实际上它不工作,因为Ansible没有像我预期的那样在迭代文件中应用配置。Hi Konstantin,使用with_fileglob而不是with_items工作,谢谢你的帮助。实际上它不工作,因为Ansible没有像我预期的那样在迭代文件中应用配置。