jitter
jitter

Reputation: 51

Ansible - Issue with iterating through items in path

I'm quite new to Ansible and I can't seem to be able to iterate through the items in a path using "with_items".

Below is the sample code which is meant to go through some files in a path and apply the configuration to a Juniper router.

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

The error I'm getting is this:

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

Does anyone have any idea why I'm unable to do so?

Upvotes: 0

Views: 560

Answers (1)

Konstantin Suvorov
Konstantin Suvorov

Reputation: 68329

Why with_items? Use with_fileglob.

From examples:

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

Upvotes: 2

Related Questions