4

I'm using the following task in my Ansible script to copy all files from a local data folder to the server:

- name: copy basic files to folder
  copy:
    src: "{{ item }}"
    dest: ~/data/
    mode: 755
    owner: "www-data"
    group: "www-data"
  with_fileglob:
    - ../files/data/*

This works fine, except for that it skips hidden files (such as .htaccess).

Does anybody know how I can make with_fileglob also include hidden files?

kramer65
  • 50,427
  • 120
  • 308
  • 488

2 Answers2

13

Ok, found the answer myself. I found that with_fileglob simply calls the python glob.glob() function. So after some fideling around I found just had to add a fileglob with .* to it:

- name: copy basic files to folder
  copy:
    src: "{{ item }}"
    dest: ~/data/
    mode: 755
    owner: "www-data"
    group: "www-data"
  with_fileglob:
    - ../files/data/*
    - ../files/data/.*
kramer65
  • 50,427
  • 120
  • 308
  • 488
9

Ansible uses Python's glob.

If the directory contains files starting with . they won’t be matched by default.

>>> import glob
>>> glob.glob('*.gif')
['card.gif']
>>> glob.glob('.c*')
['.card.gif']

Add .* explicitly to the list of patterns.

Community
  • 1
  • 1
techraf
  • 64,883
  • 27
  • 193
  • 198