๐Ÿ“— Ansible playbooks and roles for building an idempotent, interconnected and scalable infrastructure
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ansible-playbooks/roles/rclone/tasks/main.yml

121 lines
2.5 KiB

2 years ago
- name: install rclone and dependencies
include_tasks: tasks/install_packages.yml
vars:
package:
- fuse
- rclone
- name: create user and group
include_tasks: tasks/create_user.yml
vars:
user:
name: "{{ rclone_user }}"
group: "{{ rclone_group }}"
- name: create config directory
file:
path: "{{ rclone_conf_dir }}"
state: directory
owner: "{{ rclone_user }}"
group: "{{ rclone_group }}"
- name: create root mount directory
file:
path: "{{ rclone_mount_dir }}"
state: directory
mode: 0755
owner: "{{ rclone_user }}"
group: "{{ rclone_group }}"
- name: create other mount directories
file:
path: "{{ rclone_mount_dir ~ '/' ~ item }}"
state: directory
mode: 0755
owner: "{{ rclone_user }}"
group: "{{ rclone_group }}"
loop: "{{ rclone_remotes | map(attribute='name') | list }}"
- name: template config file for each remote
template:
src: config.j2
dest: "{{ rclone_conf_dir }}/{{ remote.name }}.conf"
force: no
mode: 0600
owner: "{{ rclone_user }}"
group: "{{ rclone_group }}"
lstrip_blocks: yes
notify: restart all rclone daemons
loop: "{{ rclone_remotes }}"
loop_control:
loop_var: remote
- name: template init script for each remote
template:
src: init.j2
dest: "/etc/init.d/rclone-{{ remote.name }}"
force: yes
mode: "+x"
notify: restart all rclone daemons
loop: "{{ rclone_remotes }}"
loop_control:
loop_var: remote
- name: edit fuse config
lineinfile:
path: /etc/fuse.conf
line: user_allow_other
notify: restart all rclone daemons
- name: flush handlers
meta: flush_handlers
- name: add directories to backup plan
include_role:
name: backup
vars:
function: add
backup_items:
- "{{ rclone_conf_dir }}"
- name: enable and start rclone daemons
service:
name: "rclone-{{ item }}"
enabled: yes
state: started
loop: "{{ rclone_remotes | map(attribute='name') | list }}"
- set_fact:
rclone_mount_dir_: "{{ rclone_mount_dir }}"
- name: setup backups
include_role:
name: backup
vars:
function: setup
backup_cfg:
repo: "{{ remote.name }}"
password: "{{ lookup('vars', 'backup_password') }}"
repo_password: "{{ remote.backup_password }}"
tags: automated
max_size: "1G"
dirs:
- "{{ rclone_mount_dir_ ~ '/' ~ remote.name }}"
fs_snapshot: no
when: (backup_password is defined) and (remote.backup_password is defined)
loop: "{{ rclone_remotes }}"
loop_control:
loop_var: remote