Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support installation by non-root users #162

Merged
merged 10 commits into from
Aug 4, 2024
2 changes: 1 addition & 1 deletion .cz.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ commitizen:
- ''
- - disabled
- fg:#858585 italic
version: 0.1.3
version: 0.2.0
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
## Unreleased

## 0.2.0 [2024-08-04]

- installation for non-root users
- improvements in the molecule setup: arch-linux as separate platform, everything in default scenario

## 0.1.3 - 0.1.9 TODO

## 0.1.2 (2023-03-09)

Expand Down
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,37 @@ Available variables are listed below, along with default values (see `defaults/m

This can be used to toggle the installation of manpages.

### `rclone_manpages_location: "{{ default_rclone_manpages_location }}"`

The location to install `rclone` manpages. The default is an OS specific location, but you can override it anywhere.

### `rclone_manpages_owner:`

These variables allow for setting the ownership of manpages for `rclone`. They are mostly needed if configuring `rclone` to run as an other user than root (maybe a specific backup user or so).

rclone_manpages_owner:
OWNER: rclone
GROUP: rclone

### `rclone_binary_location: "/usr/local/bin/"`

The location to install the `rclone` binary.

### `rclone_binary_owner:`

These variables allow for setting the ownership of the `rclone` binary. They are mostly needed if configuring `rclone` to install for non-root user.

rclone_binary_location: "/home/rclone/.local/bin/"
rclone_binary_owner:
OWNER: rclone
GROUP: rclone

### rclone_fact_path: "/etc/ansible/facts.d/rclone.fact"

The location to ansible local facts for `rclone`. They are mostly needed if you run this role by non-root user.

rclone_fact_path: "/home/rclone/.config/ansible/facts.d/rclone.fact"

### `rclone_arch: "amd64"`

This variable chooses the target architecture (for example 'amd64').
Expand Down Expand Up @@ -177,6 +208,8 @@ Note: This example assumes you have created the `rclone.service` systemd unit yo

This variable allows for the configuration of rclone mounts within your infrastructure. `rclone_mounts` should be a YAML list of objects, each including keys for `name`, `remote_name`, `remote_path`, `local_path`, `auto_mount`, and `extra_args`. This setup enables precise control over multiple mount points, their remote sources, and whether they should be automatically mounted.

If you use this variable, you must run this role as root using `become: true`.

#### Detailed example for `rclone_mounts`

To define mounts, you'll specify each mount's details in the playbook, allowing Ansible to handle the mounting process as per your configuration. This method is advantageous for managing mounts across multiple systems or ensuring persistent mounts across reboots when combined with the `auto_mount` option.
Expand Down
17 changes: 14 additions & 3 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,29 @@ rclone_release: stable

rclone_version: '{{ ansible_local.rclone.version | d("0.0.0") }}'

rclone_fact_path: "/etc/ansible/facts.d/rclone.fact"

install_manpages: true

# Defaults in case no variables for OS are chosen
rclone_setup_tmp_dir: "/tmp/rclone_setup"

# The location to install manpages
rclone_manpages_location: "{{ default_rclone_manpages_location }}"

# The location to install the binary file
rclone_binary_location: "/usr/local/bin/"

# The location to install the config file if configured
rclone_config_location: "/root/.config/rclone/rclone.conf"

rclone_packages:
- unzip
rclone_packages: "{{ default_rclone_packages }}"

rclone_manpages_owner:
OWNER: root
GROUP: root

rclone_man_pages:
rclone_binary_owner:
OWNER: root
GROUP: root

Expand Down
2 changes: 1 addition & 1 deletion galaxy.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
name: ansible_rclone
namespace: stefangweichinger
version: 0.1.7
version: 0.2.0
authors:
- stefangweichinger
readme: ./README.md
Expand Down
1 change: 1 addition & 0 deletions tasks/beta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
mode: 0744
list_files: true
creates: "{{ rclone_setup_tmp_dir }}/rclone-v{{ rclone_version }}-linux-{{ rclone_arch }}"
changed_when: False
32 changes: 16 additions & 16 deletions tasks/install-bin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
- name: Update repositories cache on Ubuntu
ansible.builtin.apt:
update_cache: true
become: true
when: ansible_facts.distribution == 'Ubuntu'
when: >-
rclone_packages | length > 0
and ansible_facts.distribution == 'Ubuntu'

- name: Install required packages
ansible.builtin.package:
name: '{{ item }}'
state: present
become: true
with_items: '{{ rclone_packages }}'
when: rclone_packages | length > 0

- name: Remove temporary working directory
ansible.builtin.file:
Expand All @@ -26,6 +27,7 @@
path: "{{ rclone_setup_tmp_dir }}"
state: directory
mode: '0775'
changed_when: False

- name: Do beta install
ansible.builtin.include_tasks: beta.yml
Expand All @@ -45,38 +47,36 @@
- name: Copy rclone binary
ansible.builtin.copy:
src: "{{ rclone_setup_tmp_dir }}/rclone-v{{ rclone_version }}-linux-{{ rclone_arch }}/rclone"
dest: "/usr/local/bin/rclone"
dest: '{{ rclone_binary_location }}'
mode: '0755'
owner: root
group: root
owner: '{{ rclone_binary_owner.OWNER }}'
group: '{{ rclone_binary_owner.GROUP }}'
force: true
remote_src: true
become: true

- name: Make dir for local manpages
ansible.builtin.file:
path: '{{ rclone_man_pages.PATH }}'
path: '{{ rclone_manpages_location }}'
state: directory
mode: '0775'
owner: '{{ rclone_man_pages.OWNER }}'
group: '{{ rclone_man_pages.GROUP }}'
become: true
owner: '{{ rclone_manpages_owner.OWNER }}'
group: '{{ rclone_manpages_owner.GROUP }}'
when: install_manpages

- name: Copy rclone manpage
ansible.builtin.copy:
src: "{{ rclone_setup_tmp_dir }}/rclone-v{{ rclone_version }}-linux-{{ rclone_arch }}/rclone.1"
dest: "{{ rclone_man_pages.PATH }}/rclone.1"
dest: "{{ rclone_manpages_location }}/rclone.1"
mode: '0644'
owner: root
group: root
owner: '{{ rclone_manpages_owner.OWNER }}'
group: '{{ rclone_manpages_owner.GROUP }}'
force: true
remote_src: true
become: true
when: install_manpages

- name: Update mandb
ansible.builtin.command: mandb
become: true
environment:
MANPATH: "{{ rclone_manpages_location | dirname }}"
changed_when: false
when: install_manpages
9 changes: 3 additions & 6 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,21 @@
- vars

- name: Create directory for ansible custom facts
become: true
ansible.builtin.file:
state: directory
recurse: true
path: /etc/ansible/facts.d
path: "{{ rclone_fact_path | dirname }}"

- name: Create facts file from template
become: true
ansible.builtin.template:
src: 'etc/ansible/facts.d/rclone.fact.j2'
dest: /etc/ansible/facts.d/rclone.fact
dest: '{{ rclone_fact_path }}'
mode: '0755'
notify: Update facts

- name: Re-read facts after adding custom fact
become: true
ansible.builtin.setup:
fact_path: "{{ rclone_fact_path }}"
filter: ansible_local

- name: Handle stable version number
Expand Down Expand Up @@ -68,7 +66,6 @@

- name: Install configs
when: rclone_configs is defined
become: true
block:
- name: Create config directory
ansible.builtin.file:
Expand Down
1 change: 1 addition & 0 deletions tasks/stable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
remote_src: true
mode: 0744
creates: "{{ rclone_setup_tmp_dir }}/rclone-v{{ rclone_version }}-linux-{{ rclone_arch }}"
changed_when: False
7 changes: 2 additions & 5 deletions vars/Archlinux.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
---

rclone_packages:
default_rclone_packages:
- unzip
- man
- file

rclone_man_pages:
OWNER: root
GROUP: root
PATH: '/usr/local/share/man/man1'
default_rclone_manpages_location: '/usr/local/share/man/man1'
7 changes: 2 additions & 5 deletions vars/CentOS-6.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
---

rclone_packages:
default_rclone_packages:
- unzip
- man

rclone_man_pages:
OWNER: root
GROUP: root
PATH: '/usr/local/share/man/man1'
default_rclone_manpages_location: '/usr/local/share/man/man1'
7 changes: 2 additions & 5 deletions vars/CentOS-7.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
---

rclone_packages:
default_rclone_packages:
- unzip
- man-db

rclone_man_pages:
OWNER: root
GROUP: root
PATH: '/usr/local/share/man/man1'
default_rclone_manpages_location: '/usr/local/share/man/man1'
7 changes: 2 additions & 5 deletions vars/Debian.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
---

rclone_packages:
default_rclone_packages:
- unzip
- man-db

rclone_man_pages:
OWNER: root
GROUP: root
PATH: '/usr/share/man/man1'
default_rclone_manpages_location: '/usr/share/man/man1'
7 changes: 2 additions & 5 deletions vars/Fedora.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
---

rclone_packages:
default_rclone_packages:
- unzip
- man
- file

rclone_man_pages:
OWNER: root
GROUP: root
PATH: '/usr/local/share/man/man1'
default_rclone_manpages_location: '/usr/local/share/man/man1'
7 changes: 2 additions & 5 deletions vars/Linuxmint.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
---

rclone_packages:
default_rclone_packages:
- unzip
- man-db

rclone_man_pages:
OWNER: root
GROUP: root
PATH: '/usr/local/share/man/man1'
default_rclone_manpages_location: '/usr/local/share/man/man1'
7 changes: 2 additions & 5 deletions vars/Pop!_OS.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
---

rclone_packages:
default_rclone_packages:
- unzip
- man-db

rclone_man_pages:
OWNER: root
GROUP: root
PATH: '/usr/local/share/man/man1'
default_rclone_manpages_location: '/usr/local/share/man/man1'
7 changes: 2 additions & 5 deletions vars/RedHat.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
---

rclone_packages:
default_rclone_packages:
- unzip
- man
- file

rclone_man_pages:
OWNER: root
GROUP: root
PATH: '/usr/local/share/man/man1'
default_rclone_manpages_location: '/usr/local/share/man/man1'
7 changes: 2 additions & 5 deletions vars/SLES.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
---

rclone_packages: # noqa var-naming
default_rclone_packages:
- unzip
- man-pages

rclone_man_pages: # noqa var-naming
OWNER: root
GROUP: root
PATH: '/usr/local/share/man/man1'
default_rclone_manpages_location: '/usr/local/share/man/man1'
7 changes: 2 additions & 5 deletions vars/Ubuntu.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
---

rclone_packages: # noqa var-naming
default_rclone_packages:
- unzip
- man-db

rclone_man_pages: # noqa var-naming
OWNER: root
GROUP: root
PATH: '/usr/local/share/man/man1'
default_rclone_manpages_location: '/usr/local/share/man/man1'
7 changes: 2 additions & 5 deletions vars/default.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
---

rclone_packages: [] # noqa var-naming
default_rclone_packages: []

rclone_man_pages: # noqa var-naming
OWNER: root
GROUP: root
PATH: '/usr/local/share/man/man1'
default_rclone_manpages_location: '/usr/local/share/man/man1'
7 changes: 2 additions & 5 deletions vars/openSUSE Leap.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
---

rclone_packages: # noqa var-naming
default_rclone_packages:
- unzip
- man-pages

rclone_man_pages: # noqa var-naming
OWNER: root
GROUP: root
PATH: '/usr/local/share/man/man1'
default_rclone_manpages_location: '/usr/local/share/man/man1'