Skip to content

Commit

Permalink
feat: Add seaweedfs role (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
konradasb authored Jun 9, 2024
1 parent dd6053d commit c6e5bb5
Show file tree
Hide file tree
Showing 9 changed files with 195 additions and 0 deletions.
27 changes: 27 additions & 0 deletions roles/seaweedfs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# seaweedfs

Ansible role to install and configure [SeaweedFS](https://github.com/seaweedfs/seaweedfs).

## Requirements

None.

## Dependencies

None.

## Role Variables

Refer to [defaults/main.yml](defaults/main.yml) for a list of variables along with documentation.

## Example Playbook

```yaml
- hosts: all
roles:
- role: hostinger.common.seaweedfs
```
## License
See [LICENSE](../../LICENSE)
27 changes: 27 additions & 0 deletions roles/seaweedfs/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
seaweedfs_version: 3.67
seaweedfs_url: https://github.com/seaweedfs/seaweedfs/releases/download/{{ seaweedfs_version }}/{{ seaweedfs_os }}_{{ seaweedfs_arch }}.tar.gz
seaweedfs_arch: amd64
seaweedfs_os: linux
seaweedfs_install_dir: /opt/seaweedfs/{{ seaweedfs_version }}
seaweedfs_owner: root
seaweedfs_group: root
seaweedfs_config_dir: /etc/seaweedfs
seaweedfs_service_state: started
seaweedfs_command: server
seaweedfs_args:
- -ip=127.0.0.1
- -volume.max=0
- -volume.fileSizeLimitMB=2048
seaweedfs_s3_config: {}
# identities:
# - name: default
# credentials:
# - accessKey: "example"
# secretKey: "example"
# actions:
# - Admin
# - Read
# - List
# - Tagging
# - Write
9 changes: 9 additions & 0 deletions roles/seaweedfs/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
- name: Reload systemd
ansible.builtin.systemd:
daemon_reload: true

- name: Restart seaweedfs
ansible.builtin.systemd:
name: seaweedfs
state: restarted
19 changes: 19 additions & 0 deletions roles/seaweedfs/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
galaxy_info:
role_name: seaweedfs
author: hostinger
description: Ansible role to install and configure SeaweedFS
license: license (MIT)
min_ansible_version: "2.10"
platforms:
- name: Fedora
versions:
- all
- name: Debian
versions:
- all
- name: Ubuntu
versions:
- all
galaxy_tags:
- seaweedfs
7 changes: 7 additions & 0 deletions roles/seaweedfs/molecule/default/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
- name: Converge
hosts:
- all

roles:
- seaweedfs
19 changes: 19 additions & 0 deletions roles/seaweedfs/molecule/default/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
dependency:
name: galaxy
driver:
name: docker
platforms:
- name: default
image: geerlingguy/docker-${MOLECULE_DISTRO:-ubuntu2204}-ansible:latest
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
command: ${MOLECULE_DOCKER_COMMAND:-""}
cgroupns_mode: host
pre_build_image: true
privileged: true
platform: amd64
provisioner:
name: ansible
playbooks:
converge: ${MOLECULE_PLAYBOOK:-converge.yml}
74 changes: 74 additions & 0 deletions roles/seaweedfs/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
---
- name: Fail when unsupported architecture
ansible.builtin.fail:
msg: "Unsupported architecture"
when:
- seaweedfs_arch not in ['amd64', 'arm64']

- name: Create directories
ansible.builtin.file:
path: "{{ item }}"
state: directory
owner: "{{ seaweedfs_owner }}"
group: "{{ seaweedfs_group }}"
mode: 0755
with_items:
- "{{ seaweedfs_install_dir }}"
- "{{ seaweedfs_config_dir }}"

- name: Download tarball
ansible.builtin.get_url:
url: "{{ seaweedfs_url }}"
dest: "{{ seaweedfs_install_dir }}/seaweedfs.tar.gz"
mode: 0644
owner: "{{ seaweedfs_owner }}"
group: "{{ seaweedfs_group }}"
timeout: 30

- name: Unarchive tarball
ansible.builtin.unarchive:
src: "{{ seaweedfs_install_dir }}/seaweedfs.tar.gz"
dest: "{{ seaweedfs_install_dir }}"
mode: 0755
creates: "{{ seaweedfs_install_dir }}/weed"
owner: "{{ seaweedfs_owner }}"
group: "{{ seaweedfs_group }}"
remote_src: true

- name: Create symlink to binaries
ansible.builtin.file:
src: "{{ seaweedfs_install_dir }}/{{ item }}"
dest: /usr/bin/{{ item }}
state: link
force: true
owner: "{{ seaweedfs_owner }}"
group: "{{ seaweedfs_group }}"
mode: 0755
with_items:
- weed

- name: Template service file
ansible.builtin.template:
src: seaweedfs.service.j2
dest: /etc/systemd/system/seaweedfs.service
mode: 0644
owner: root
group: root
notify:
- Restart seaweedfs

- name: Template S3 config file
ansible.builtin.template:
src: s3.conf.j2
dest: "{{ seaweedfs_config_dir }}/s3.conf"
mode: 0644
owner: "{{ seaweedfs_owner }}"
group: "{{ seaweedfs_group }}"
notify:
- Restart seaweedfs

- name: Enable and start service
ansible.builtin.service:
name: seaweedfs
enabled: true
state: "{{ seaweedfs_service_state }}"
1 change: 1 addition & 0 deletions roles/seaweedfs/templates/s3.conf.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{ seaweedfs_s3_config | default({}) | to_nice_json }}
12 changes: 12 additions & 0 deletions roles/seaweedfs/templates/seaweedfs.service.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[Unit]
Description=SeaweedFS
Documentation=https://github.com/seaweedfs/seaweedfs
After=network.target

[Service]
User={{ seaweedfs_owner }}
ExecStart=/usr/bin/weed {{ seaweedfs_command }} {% for arg in seaweedfs_args %}{{ arg }} {% endfor +%}
Restart=on-failure

[Install]
WantedBy=multi-user.target

0 comments on commit c6e5bb5

Please sign in to comment.