Select Page

If you have Ubuntu only environment you can easily download all crontabs for all users from machines you need using this playbook. Just create folder “crontabs” in directory where you will run playbook or modify path in synchronize.dest (Made 2016/03 for ansible 2.0).

---

- name: find crontabs
hosts: cloud
become: yes
become_method: sudo

tasks:
- name: find all
command: bash -c "sudo ls -1 /var/spool/cron/crontabs/* 2>/dev/null"
register: crontab_files

- name: download files
synchronize:
src: "{{ item }}"
dest: "crontabs/{{ ansible_hostname }}/"
mode: pull
recursive: yes
with_items: "{{ crontab_files.stdout_lines }}"