How to create folder with name as timestamp using Ansible

Ansible shell module can be used to create folder with name as current timestamp.

Let's see one sample snippet.

- name: Collect current  timestamp
  shell: date +%d%b%y_%H-%M-%S
  register: timestamp
- name: Create folder
  shell: mkdir {{ timestamp.stdout }}

Here in the first part we are collecting the current timestamp and saving it to Ansible register. Then creating the folder with name as the collected timestamp in the second step. We can choose different timestamp formats according to the requirements. This method is verify useful in the case of creating folder backups.

That's all...

Leave a Reply