rsync/ansible/playbook_rsync.yml

61 lines
1.6 KiB
YAML
Raw Permalink Normal View History

2024-02-27 18:52:12 +08:00
- name: Deploy rsync_backup script
hosts: all
become: yes
vars:
script_url: "https://code.3err0.ru/3err0/rsync/raw/branch/main/rsync_backup.sh"
script_path: "/usr/local/bin/rsync_backup"
exclude_url: "https://code.3err0.ru/3err0/rsync/raw/branch/main/etc/rsyncd.exclude"
backup_user: "backup"
dest_ip: "ip"
files_source: "'/opt'"
tasks:
- name: Download script
ansible.builtin.get_url:
url: "{{ script_url }}"
dest: "{{ script_path }}"
mode: '0755'
2024-02-28 13:58:12 +08:00
- name: Create rsyncd.pwd file
2024-02-27 18:52:12 +08:00
ansible.builtin.copy:
2024-02-28 13:58:12 +08:00
dest: /etc/rsyncd.pwd
2024-02-27 18:52:12 +08:00
content: password
mode: '0600'
- name: Create rsyncd.exclude file
ansible.builtin.get_url:
url: "{{ exclude_url }}"
dest: /etc/rsyncd.exclude
mode: '0644'
- name: Update user in script
ansible.builtin.lineinfile:
path: "{{ script_path }}"
regexp: "^user='[^']*'"
line: "user='{{ backup_user }}'"
state: present
- name: Update ip in script
ansible.builtin.lineinfile:
path: "{{ script_path }}"
regexp: "^ip='[^']*'"
line: "ip='{{ dest_ip }}'"
state: present
- name: Update source in script
ansible.builtin.lineinfile:
path: "{{ script_path }}"
regexp: "^source='[^']*'"
line: "source={{ files_source }}"
state: present
- name: Schedule script in cron for daily execution at 1 AM
ansible.builtin.cron:
name: "Backup with rsync"
job: "{{ script_path }}"
minute: "0"
hour: "1"
day: "*"
month: "*"
weekday: "*"