Created
April 2, 2016 10:23
-
-
Save arbabnazar/29f9186ac31dc8e029b0aaf9ae29b603 to your computer and use it in GitHub Desktop.
This playbook is used to perform bulk files rename on remote hosts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- hosts: all | |
gather_facts: no | |
become: yes | |
tasks: | |
- shell: ls /files/* | |
register: files_to_rename | |
- copy: | |
src: "{{ item.1 }}" | |
dest: "/files/file-{{ item.0 + 1 }}" | |
remote_src: yes | |
with_indexed_items: "{{ files_to_rename.stdout_lines }}" | |
- file: | |
path: "{{ item }}" | |
state: absent | |
with_items: "{{ files_to_rename.stdout_lines }}" | |
# Reference: | |
# If you just want the filenames without fullpath | |
# (cd /remote; find . -maxdepth 1 -type f) | cut -d'/' -f2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment