From c6e5bb58a6ce35c847b1ee70d807767938a02bb1 Mon Sep 17 00:00:00 2001 From: Konradas Bunikis Date: Sun, 9 Jun 2024 21:01:26 +0300 Subject: [PATCH] feat: Add seaweedfs role (#15) --- roles/seaweedfs/README.md | 27 +++++++ roles/seaweedfs/defaults/main.yml | 27 +++++++ roles/seaweedfs/handlers/main.yml | 9 +++ roles/seaweedfs/meta/main.yml | 19 +++++ roles/seaweedfs/molecule/default/converge.yml | 7 ++ roles/seaweedfs/molecule/default/molecule.yml | 19 +++++ roles/seaweedfs/tasks/main.yml | 74 +++++++++++++++++++ roles/seaweedfs/templates/s3.conf.j2 | 1 + .../seaweedfs/templates/seaweedfs.service.j2 | 12 +++ 9 files changed, 195 insertions(+) create mode 100644 roles/seaweedfs/README.md create mode 100644 roles/seaweedfs/defaults/main.yml create mode 100644 roles/seaweedfs/handlers/main.yml create mode 100644 roles/seaweedfs/meta/main.yml create mode 100644 roles/seaweedfs/molecule/default/converge.yml create mode 100644 roles/seaweedfs/molecule/default/molecule.yml create mode 100644 roles/seaweedfs/tasks/main.yml create mode 100644 roles/seaweedfs/templates/s3.conf.j2 create mode 100644 roles/seaweedfs/templates/seaweedfs.service.j2 diff --git a/roles/seaweedfs/README.md b/roles/seaweedfs/README.md new file mode 100644 index 0000000..bf046db --- /dev/null +++ b/roles/seaweedfs/README.md @@ -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) diff --git a/roles/seaweedfs/defaults/main.yml b/roles/seaweedfs/defaults/main.yml new file mode 100644 index 0000000..bc6410e --- /dev/null +++ b/roles/seaweedfs/defaults/main.yml @@ -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 diff --git a/roles/seaweedfs/handlers/main.yml b/roles/seaweedfs/handlers/main.yml new file mode 100644 index 0000000..432ebed --- /dev/null +++ b/roles/seaweedfs/handlers/main.yml @@ -0,0 +1,9 @@ +--- +- name: Reload systemd + ansible.builtin.systemd: + daemon_reload: true + +- name: Restart seaweedfs + ansible.builtin.systemd: + name: seaweedfs + state: restarted diff --git a/roles/seaweedfs/meta/main.yml b/roles/seaweedfs/meta/main.yml new file mode 100644 index 0000000..8461853 --- /dev/null +++ b/roles/seaweedfs/meta/main.yml @@ -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 diff --git a/roles/seaweedfs/molecule/default/converge.yml b/roles/seaweedfs/molecule/default/converge.yml new file mode 100644 index 0000000..2c36c81 --- /dev/null +++ b/roles/seaweedfs/molecule/default/converge.yml @@ -0,0 +1,7 @@ +--- +- name: Converge + hosts: + - all + + roles: + - seaweedfs diff --git a/roles/seaweedfs/molecule/default/molecule.yml b/roles/seaweedfs/molecule/default/molecule.yml new file mode 100644 index 0000000..3dc76ce --- /dev/null +++ b/roles/seaweedfs/molecule/default/molecule.yml @@ -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} diff --git a/roles/seaweedfs/tasks/main.yml b/roles/seaweedfs/tasks/main.yml new file mode 100644 index 0000000..49c0ea7 --- /dev/null +++ b/roles/seaweedfs/tasks/main.yml @@ -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 }}" diff --git a/roles/seaweedfs/templates/s3.conf.j2 b/roles/seaweedfs/templates/s3.conf.j2 new file mode 100644 index 0000000..7823358 --- /dev/null +++ b/roles/seaweedfs/templates/s3.conf.j2 @@ -0,0 +1 @@ +{{ seaweedfs_s3_config | default({}) | to_nice_json }} diff --git a/roles/seaweedfs/templates/seaweedfs.service.j2 b/roles/seaweedfs/templates/seaweedfs.service.j2 new file mode 100644 index 0000000..b50d42d --- /dev/null +++ b/roles/seaweedfs/templates/seaweedfs.service.j2 @@ -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