add rclone_yandex role
This commit is contained in:
58
roles/rclone_yandex/tasks/configure.yaml
Normal file
58
roles/rclone_yandex/tasks/configure.yaml
Normal file
@@ -0,0 +1,58 @@
|
||||
---
|
||||
- name: "Configure | create a group - '{{ rclone_group }}'"
|
||||
ansible.builtin.group:
|
||||
name: "{{ rclone_group }}"
|
||||
state: present
|
||||
|
||||
- name: "Configure | get GID for '{{ rclone_group }}'"
|
||||
register: rclone_group_gid
|
||||
changed_when: false
|
||||
failed_when: not rclone_group_gid.stdout
|
||||
ansible.builtin.shell:
|
||||
cmd: 'set -o pipefail && getent group "{{ rclone_group }}" | cut -d: -f3'
|
||||
executable: /bin/bash
|
||||
|
||||
- name: "Configure | display rclone mount ownership group"
|
||||
ansible.builtin.debug:
|
||||
msg: "'{{ rclone_group }}' ({{ rclone_group_gid.stdout }})"
|
||||
|
||||
- name: "Configure | set up directories"
|
||||
loop:
|
||||
- {path: "/tmp/rclone", group: "root"}
|
||||
- {path: "/mnt/yandex-disk", group: "{{ rclone_group }}"}
|
||||
ansible.builtin.file:
|
||||
state: directory
|
||||
path: "{{ item.path }}"
|
||||
owner: root
|
||||
group: "{{ item.group }}"
|
||||
mode: "0770"
|
||||
|
||||
- name: "Configure | create the [yandex] section"
|
||||
ansible.builtin.lineinfile:
|
||||
create: true
|
||||
path: "{{ rclone_config_path }}"
|
||||
line: "[yandex]"
|
||||
mode: "0660"
|
||||
|
||||
- name: "Configure | read in the YAMLified Yandex share credentials"
|
||||
ansible.builtin.include_vars:
|
||||
file: "{{ rclone_secrets }}"
|
||||
|
||||
- name: "Configure | insert/update the section for the [yandex] share"
|
||||
ansible.builtin.blockinfile:
|
||||
path: "{{ rclone_config_path }}"
|
||||
insertafter: "^[yandex]"
|
||||
block: |
|
||||
type = yandex
|
||||
token = {{ rclone | to_json }}
|
||||
|
||||
- name: "Configure | template a systemd service file"
|
||||
ansible.builtin.template:
|
||||
src: templates/rclone-yandex.service.j2
|
||||
dest: /lib/systemd/system/rclone-yandex.service
|
||||
mode: "0660"
|
||||
|
||||
# validate attribute doesn't seem to work here, unfortunately, so command to the rescue
|
||||
- name: "Configure | validate the service file"
|
||||
ansible.builtin.command: systemd-analyze verify rclone-yandex.service
|
||||
changed_when: false
|
||||
39
roles/rclone_yandex/tasks/install.yaml
Normal file
39
roles/rclone_yandex/tasks/install.yaml
Normal file
@@ -0,0 +1,39 @@
|
||||
---
|
||||
- name: "Install | unzip (RHEL)"
|
||||
ansible.builtin.dnf:
|
||||
name: [ unzip ]
|
||||
state: installed
|
||||
when: ansible_os_family == 'RHEL'
|
||||
|
||||
- name: "Install | unzip (Debian)"
|
||||
ansible.builtin.apt:
|
||||
update_cache: true
|
||||
name: [ unzip ]
|
||||
state: present
|
||||
when: ansible_os_family == 'Debian'
|
||||
|
||||
- name: "Install | rclone_yandex"
|
||||
block:
|
||||
- name: "Install | check if rclone binary is available in PATH"
|
||||
changed_when: false
|
||||
ansible.builtin.command:
|
||||
cmd: "rclone --version"
|
||||
rescue:
|
||||
- name: "Install | fetch and install the rclone binary" # noqa: no-changed-when
|
||||
register: result
|
||||
failed_when: result.rc != 0
|
||||
ansible.builtin.shell:
|
||||
cmd: "set -o pipefail && curl https://rclone.org/install.sh | sudo bash"
|
||||
executable: /bin/bash
|
||||
|
||||
- name: "Install | fuse (RHEL)"
|
||||
ansible.builtin.dnf:
|
||||
name: [ fuse ]
|
||||
state: installed
|
||||
when: ansible_os_family == 'RHEL'
|
||||
|
||||
- name: "Install | fuse (Debian)"
|
||||
ansible.builtin.apt:
|
||||
name: [ fuse3 ]
|
||||
state: present
|
||||
when: ansible_os_family == 'Debian'
|
||||
11
roles/rclone_yandex/tasks/main.yml
Normal file
11
roles/rclone_yandex/tasks/main.yml
Normal file
@@ -0,0 +1,11 @@
|
||||
# tasks file
|
||||
---
|
||||
|
||||
- name: "Include installation tasks"
|
||||
ansible.builtin.include_tasks: "install.yaml"
|
||||
|
||||
- name: "Include configuration tasks"
|
||||
ansible.builtin.include_tasks: "configure.yaml"
|
||||
|
||||
- name: "Include run tasks"
|
||||
ansible.builtin.include_tasks: "run.yaml"
|
||||
6
roles/rclone_yandex/tasks/run.yaml
Normal file
6
roles/rclone_yandex/tasks/run.yaml
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
- name: "Run | start the 'rclone-yandex' service"
|
||||
ansible.builtin.systemd:
|
||||
name: rclone-yandex
|
||||
state: started
|
||||
daemon_reload: true
|
||||
Reference in New Issue
Block a user