Question

So I have an Ansible playbook and I'm trying to call a command for each item in a list, but also run that command over a fileglob. There is a "with_nested" in Ansible, and it can take variable names, but if I add a "with_fileglob," it just inserts "with_fileglob" as the filename instead of actually doing a glob.

  vars:
    repo_versions:
      - version: trusty
        distribution: Ubuntu
      - version: wheezy
        distribution: Debian

  ...

  - command: reprepro -b /var/www/html includedeb {{ item[0].version }} {{ item[1] }}
    with_nested:
      - repo_versions
      with_fileglob: /home/repoman/debs/*.deb
    when: debs_available.stat.exists == True

I've tried a couple of different combinations and I can't seem to get it to process the command in a double for loop (for each .version, for each .deb file)

Was it helpful?

Solution

This should be what you are trying to accomplish.

I used the shell module to register the output of the fileglob, and then the stdout_lines property of the registerd variable in the loop. I have converted the task from my test to your actual commands and paths, so you might need to double check:

  vars:
    repo_versions:
      - version: trusty
        distribution: Ubuntu
      - version: wheezy
        distribution: Debian

  tasks:
    - shell: ls -1 /home/repoman/debs/*.deb
      register: repo_list

    - command: reprepro -b /var/www/html includedeb {{ item[0].version }} {{ item[1] }}
      with_nested:
        - repo_versions
        - repo_list.stdout_lines
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top