Skip to content

Instantly share code, notes, and snippets.

@arbabnazar
Created April 2, 2016 10:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save arbabnazar/29f9186ac31dc8e029b0aaf9ae29b603 to your computer and use it in GitHub Desktop.
Save arbabnazar/29f9186ac31dc8e029b0aaf9ae29b603 to your computer and use it in GitHub Desktop.
This playbook is used to perform bulk files rename on remote hosts
- 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