Shasha99
Shasha99

Reputation: 1916

Move files from all directories to parent directory using ansible

I have the following file structure:

- Parent
  - folder1
     - file1
  - folder2
     - file2
  - folder3
     - file3

And i want the file1, file2, file3 to be moved to parent directory. The problem is to find out all directories inside the parent directory.I am trying to implement something like this:

- name: Moving file.
  command: mv /parent/{{item}}/* /parent
  with_items: "folders in parent"

Any approach will be fine for me. I don't have any clue.

Upvotes: 0

Views: 1686

Answers (1)

udondan
udondan

Reputation: 60029

You can use with_fileglob.

- name: Moving file.
  command: mv {{ item }} /parent/
  with_fileglob:
    - /parent/*/*

Upvotes: 1

Related Questions