diff --git a/Makefile b/Makefile deleted file mode 100644 index 197e8f4..0000000 --- a/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -all: ipfs ipfs-cluster -ipfs: - ansible-playbook -i inventory.yml ipfs.yml -ipfs-cluster: - ansible-playbook -i inventory.yml ipfs-cluster.yml -.PHONY = all ipfs ipfs-cluster diff --git a/README.md b/README.md index 4c92038..c4691b0 100644 --- a/README.md +++ b/README.md @@ -1,35 +1,108 @@ -# Ansible roles for `go-ipfs` and `ipfs-cluster` +# Ansible role for `kubo` and `ipfs-cluster` -This repository contains Ansible roles to install and run -[`go-ipfs`](https://github.com/ipfs/go-ipfs) and +This repository contains an Ansible role to install and run +[`kubo`](ihttps://github.com/ipfs/kubo) and [`IPFS Cluster`](https://github.com/ipfs/ipfs-cluster). They include a Systemd service file both. +## Requirements + +- Ansible. you can install it by running `pip install ansible` +- [optional] Working moledule setup with docker for running the tests + +## Installation + +### Git +Use `git clone` or `git submodule add` to clone the ansible-ipfs-cluster role (`https://github.com/hsanjuan/ansible-ipfs-cluster.git`) into the `roles` folder of your playbook to pull the latest edge commit of the role from GitHub. + ## Usage If you are familiar with Ansible, you can just re-use the modules in the way that fits you best. Otherwise follow these steps: -0. Make sure you have ansible installed: `pip install ansible`. -1. Fill in `inventory.yml` and place the hostnames of your nodes under the `[ipfs]` group. -2. Edit the `group_vars/ipfs.yml` and `group_vars/ipfs_cluster.yml` file - setting the right configuration values, including generating an - [IPFS Cluster secret](https://cluster.ipfs.io/documentation/guides/security/#the-cluster-secret) - with `od -vN 32 -An -tx1 /dev/urandom | tr -d ' \n' ; echo` -3. Add a file for each hostname (filename is the hostname), to the `host_vars` - folder as outlined in [`host_vars/README.md`](host_vars/README.md), - containing the necessary host-specific variables (example in the - `host_vars` README). -4. Run `make`. - -`make` will run ansible for the `ipfs` and the `ipfs-cluster` roles, which -apply to the `[ipfs]` and `[ipfs_cluster]` inventory group. Upon successful, -both `go-ipfs` and `ipfs-cluster` should be running in the nodes (they are -installed under `/usr/local/bin` and run by a created `ipfs` system user). - -You can use `systemctl status ipfs` and `systemctl status ipfs-cluster` to -check the status of the new services. - -Note that `ipfs` configuration has been generated using `profile=server`, thus -will not automatically scan the local network. +- Fill in `inventory.yml` and place the hostnames of your nodes under the `[ipfs]` and `[ipfs-cluster]` groups. +- Create `group_vars/ipfs.yml` and `group_vars/ipfs_cluster.yml` files setting the right configuration values including generating an [IPFS Cluster secret](https://cluster.ipfs.io/documentation/guides/security/#the-cluster-secret) with `od -vN 32 -An -tx1 /dev/urandom | tr -d ' \n' ; echo`. More details in the [Group Vars](#group-vars) section. +- Add a file for each hostname (filename is the hostname), to the `host_vars` folder as outlined in [Host Vars](#host-vars), containing the necessary host-specific variables (example in the `molecule/default/molecule.yml` file). + +Upon successful execution, both `kubo` and `ipfs-cluster` should be running in the nodes (they are installed under `/usr/local/bin` and run by a created `ipfs` system user). + +You can use `systemctl status ipfs` and `systemctl status ipfs-cluster` to check the status of the new services. + +Note that `ipfs` configuration has been generated using `profile=server`, thus will not automatically scan the local network. + +### Host Vars + +Add one file for each ipfs-cluster host. The filename should match a domain name from your inventory, i.e. `example.org`. + +Each file should contain the following variables, updated for your cluster: + +```yaml +ipfs_peer_id: "" +ipfs_private_key: "" + +ipfs_cluster_id: "" +ipfs_cluster_private_key: "" + +ipfs_cluster_peer_addr: "/dns4//tcp/9096/ipfs/" +``` + +To generate the `ipfs_peer_id`/`ipfs_private_key` and `ipfs_cluster_id`/`ipfs_cluster_private_key` key-pairs, use [`ipfs-key`]. Theymust be all different (no ID or Key can be shared between daemons). + +To install [`ipfs-key`], with Go installed, run: + +```console +$ go get github.com/whyrusleeping/ipfs-key +``` + +then generate a key-pair: + +```console +$ ipfs-key | base64 -w 0 + +# or on macos +$ ipfs-key | base64 + +Generating a 2048 bit RSA key... +Success! +ID for generated key: Qmat3Bk4SixhZdU5j5pf2uXcpUuTSxKHQu7whbWrdFwn5g +CAASqAkwggSkAgEAAoIBAQCUzxjdml2fORveg9PN98qqiENexLzoaSeNc6N7K8iVzneCU1aDZpM... +``` + +Where: + +- the value of `ID for generated key: ` is your `ipfs_peer_id` or `ipfs_cluster_id` +- the subsequent line is your `ipfs_private_key` or `ipfs_cluster_private_key`, encoded as base64 + +Copy those values into your host config file. + +For `ipfs_cluster_peer_addr` you need to specify a valid [multiaddr] by taking the example below + +``` +"/dns4//tcp/9096/ipfs/" +``` +and replacing: + +`hostname`: with the host from your invetory that this file is for, e.g `example.org` `ipfs_cluster_peer_id`: with the peer id for this cluster node, that you just created. + + +You can also define `ipfs_cluster_peername` to name your cluster peer for conviniency. Otherwise, the hostname will be used. + +[`ipfs-key`]: https://github.com/whyrusleeping/ipfs-key +[multiaddr]: https://multiformats.io/multiaddr/ + +### Group Vars + +The `group_vars` file can be used to set variables to control the common configuration for of all ipfs and ipfs-cluster peers. + +Create `ipfs.yml` and `ipfs-cluster.yml` files in this folder and set the appropiate values for the variables. + +Note the cluster `service.json` template can be fully customized by defining the appropiate variables, and otherwise they will take sensisble defaults. + +## Running the tests + +Assumes you have a working molecule setup with docker, running `molecule test` should spin up a docker container and execute the test playbook declared in `molecule/default/converge.yml` as well as the verifications in `molecule/default/verify.yml` + +```console +python 3 -m molecule test +``` diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..db69ba4 --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,31 @@ +# IPFS + +# override to disable kubo setup +ipfs_enable: true + +ipfs_version: v0.9.0 +ipfs_arch: amd64 +ipfs_home: /home/ipfs +ipfs_storage_max: 10G +ipfs_bloom_filter_size: 1048576 # 1MB +ipfs_api_listen: /ip4/127.0.0.1/tcp/5001 +ipfs_fd_max: 4092 +ipfs_use_badger: false +ipfs_discovery: false +ipfs_disk_sync: true +ipfs_routing: dht +ipfs_disable_bandthwidth_metrics: false +ipfs_reprovider_strategy: all + +# If you find IPFS uses too much RAM, you can +# limit the max amount in the systemd service +# file by setting this to something suitable: +# ipfs_memory_max: "1.5G" + +# IPFS Cluster + +# override to disable ipfs cluster setup +ipfs_cluster_enable: true +ipfs_cluster_arch: amd64 +ipfs_cluster_version: v0.13.3 +ipfs_cluster_fd_max: 10000 diff --git a/group_vars/README.md b/group_vars/README.md deleted file mode 100644 index a834161..0000000 --- a/group_vars/README.md +++ /dev/null @@ -1,10 +0,0 @@ -# Group vars - -The `group_vars` file can be used to set variables to control the -common configuration for of all ipfs and ipfs-cluster peers. - -Edit the `ipfs.yml` file in this folder and set the appropiate values for the -variables. - -Note the cluster `service.json` template can be fully customized by defining -the appropiate variables, and otherwise they will take sensisble defaults. diff --git a/group_vars/ipfs.yml b/group_vars/ipfs.yml deleted file mode 100644 index 2f04eac..0000000 --- a/group_vars/ipfs.yml +++ /dev/null @@ -1,14 +0,0 @@ -dist_url: https://dist.ipfs.io -ipfs_version: v0.4.19 -ipfs_arch: amd64 -ipfs_home: /home/ipfs -ipfs_storage_max: 10G -ipfs_bloom_filter_size: 1048576 # 1MB -ipfs_api_listen: /ip4/127.0.0.1/tcp/5001 -ipfs_fd_max: 4092 -ipfs_use_badger: false -ipfs_discovery: false -ipfs_disk_sync: true -ipfs_routing: dht -ipfs_disable_bandthwidth_metrics: false -ipfs_reprovider_strategy: all \ No newline at end of file diff --git a/group_vars/ipfs_cluster.yml b/group_vars/ipfs_cluster.yml deleted file mode 100644 index fbb19e4..0000000 --- a/group_vars/ipfs_cluster.yml +++ /dev/null @@ -1,5 +0,0 @@ -dist_url: https://dist.ipfs.io -ipfs_cluster_secret: "use `od -vN 32 -An -tx1 /dev/urandom | tr -d ' \n' ; echo` to generate this" -ipfs_cluster_arch: amd64 -ipfs_cluster_version: v0.10.0 -ipfs_cluster_fd_max: 10000 diff --git a/roles/ipfs/handlers/main.yml b/handlers/main.yml similarity index 80% rename from roles/ipfs/handlers/main.yml rename to handlers/main.yml index 186859f..0c353fd 100644 --- a/roles/ipfs/handlers/main.yml +++ b/handlers/main.yml @@ -3,7 +3,6 @@ systemd: daemon_reload: yes name: ipfs - notify: restart IPFS when: - not (ansible_distribution == "Amazon" and ansible_distribution_major_version == "NA") - not (ansible_distribution == "Ubuntu" and ansible_distribution_version is version('15.04', '<')) @@ -15,3 +14,10 @@ name: ipfs enabled: yes state: restarted + +- name: restart IPFS Cluster + become: yes + service: + name: ipfs-cluster + enabled: yes + state: restarted diff --git a/host_vars/README.md b/host_vars/README.md deleted file mode 100644 index 115890f..0000000 --- a/host_vars/README.md +++ /dev/null @@ -1,65 +0,0 @@ -# Setting up `host_vars` for each IPFS Cluster node - -Add one file for each ipfs-cluster host. The filename should match a domain -name from your inventory, i.e. `example.org`. - -Each file should contain the following variables, updated for your cluster: - -```yaml -ipfs_peer_id: "" -ipfs_private_key: "" - -ipfs_cluster_id: "" -ipfs_cluster_private_key: "" - -ipfs_cluster_peer_addr: "/dns4//tcp/9096/ipfs/" -``` - -To generate the `ipfs_peer_id`/`ipfs_private_key` and -`ipfs_cluster_id`/`ipfs_cluster_private_key` key-pairs, use [`ipfs-key`]. They -must be all different (no ID or Key can be shared between daemons). - -To install [`ipfs-key`], with Go installed, run: - -```console -$ go get github.com/whyrusleeping/ipfs-key -``` - -then generate a key-pair: - -```console -$ ipfs-key | base64 -w 0 - -# or on macos -$ ipfs-key | base64 - -Generating a 2048 bit RSA key... -Success! -ID for generated key: Qmat3Bk4SixhZdU5j5pf2uXcpUuTSxKHQu7whbWrdFwn5g -CAASqAkwggSkAgEAAoIBAQCUzxjdml2fORveg9PN98qqiENexLzoaSeNc6N7K8iVzneCU1aDZpM... -``` - -Where: - -- the value of `ID for generated key: ` is your `ipfs_peer_id` or `ipfs_cluster_id` -- the subsequent line is your `ipfs_private_key` or `ipfs_cluster_private_key`, encoded as base64 - -Copy those values into your host config file. - -For `ipfs_cluster_peer_addr` you need to specify a valid [multiaddr] by taking the example below - -``` -"/dns4//tcp/9096/ipfs/" -``` -and replacing: - -`hostname`: with the host from your invetory that this file is for, e.g -`example.org` `ipfs_cluster_peer_id`: with the peer id for this cluster node, -that you just created. - - -You can also define `ipfs_cluster_peername` to name your cluster peer for -conviniency. Otherwise, the hostname will be used. - -[`ipfs-key`]: https://github.com/whyrusleeping/ipfs-key -[multiaddr]: https://multiformats.io/multiaddr/ diff --git a/inventory.yml b/inventory.yml deleted file mode 100644 index d19a4a6..0000000 --- a/inventory.yml +++ /dev/null @@ -1,5 +0,0 @@ -[ipfs] -# Write here your ipfs nodes - -[ipfs_cluster:children] -ipfs \ No newline at end of file diff --git a/ipfs-cluster.yml b/ipfs-cluster.yml deleted file mode 100644 index 057df2c..0000000 --- a/ipfs-cluster.yml +++ /dev/null @@ -1,3 +0,0 @@ -- hosts: ipfs - roles: - - ipfs-cluster diff --git a/ipfs.yml b/ipfs.yml deleted file mode 100644 index 7108d2f..0000000 --- a/ipfs.yml +++ /dev/null @@ -1,6 +0,0 @@ -- hosts: ipfs - roles: - - ipfs -- hosts: ipfs_cluster - roles: - - ipfs-cluster diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..5c877ad --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,51 @@ +galaxy_info: + author: Hector Sanjuan + description: Ansible role to install and run kubo and IPFS Cluster + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Choose a valid license ID from https://spdx.org - some suggested licenses: + # - BSD-3-Clause (default) + # - MIT + # - GPL-2.0-or-later + # - GPL-3.0-only + # - Apache-2.0 + # - CC-BY-4.0 + license: MIT + + min_ansible_version: 2.1 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + # + # Provide a list of supported platforms, and for each platform a list of versions. + # If you don't wish to enumerate all versions for a particular platform, use 'all'. + # To view available platforms and versions (or releases), visit: + # https://galaxy.ansible.com/api/v1/platforms/ + # + # platforms: + # - name: Fedora + # versions: + # - all + # - 25 + # - name: SomePlatform + # versions: + # - all + # - 1.0 + # - 7 + # - 99.99 + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml new file mode 100644 index 0000000..076172b --- /dev/null +++ b/molecule/default/converge.yml @@ -0,0 +1,10 @@ +--- +- name: Converge + hosts: all + tasks: + - name: "Include ansible-ipfs-cluster" + vars: + ipfs_enable: true + ipfs_cluster_enable: true + include_role: + name: "ansible-ipfs-cluster" diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml new file mode 100644 index 0000000..efb6424 --- /dev/null +++ b/molecule/default/molecule.yml @@ -0,0 +1,29 @@ +--- +dependency: + name: galaxy +driver: + name: docker +platforms: + - name: instance-1 + image: centos:8 + command: "/usr/sbin/init" + volumes: + - "/sys/fs/cgroup:/sys/fs/cgroup:rw" + privileged: True + groups: + - ipfs_cluster +provisioner: + name: ansible + inventory: + group_vars: + ipfs_cluster: + ipfs_cluster_secret: "81643eba8fedcc4aa31fef6459e8b852a97c3cf3d0489158cb85166e8255e912" + host_vars: + instance-1: + ipfs_peer_id: "12D3KooWH31GCY8gjo8n2ucpcqoXzWPWe1jXzLZYKxyBM8WpcVLU" + ipfs_private_key: "CAESQJ0rgc303IwfPtdz6VfR8sHEG13FOrFH3qE8a1jCiz3zaz64d7f/r14AUMxdGtDpan4mlRxpG1XIim8oRydnFKE=" + ipfs_cluster_id: "12D3KooWJg9EybwXzoHV182Zdn7ibftJxZtqS66Boim8fd6ccCw4" + ipfs_cluster_private_key: "CAESQCnWLxgdpNdMwCHOker/ozlR3alTULffh3PIvZECcQCYg53rUlp1Gst4JUNXkPzQrCYH7xNpsrJZKFG7JtzjiJM=" + ipfs_cluster_peer_addr: "/dns4/node01/tcp/9096/ipfs/QmUdZCogpVVrPMxdPHhtT2KuUuxNVi1uLb7UC4HwHBqejb" +verifier: + name: ansible diff --git a/molecule/default/verify.yml b/molecule/default/verify.yml new file mode 100644 index 0000000..d38ff8f --- /dev/null +++ b/molecule/default/verify.yml @@ -0,0 +1,25 @@ +--- +# Validates if ipfs and ipfs-cluster are installed and running + +- name: Verify + hosts: instance-1 + gather_facts: false + tasks: + + - name: Check if IPFS service is running + service: + name: ipfs + state: started + enabled: true + check_mode: true + register: service_ipfs + failed_when: (service_ipfs is changed) or (service_ipfs is failed) + + - name: Check if IPFS Cluster service is running + service: + name: ipfs-cluster + state: started + enabled: true + check_mode: true + register: service_ipfs_cluster + failed_when: (service_ipfs_cluster is changed) or (service_ipfs_cluster is failed) \ No newline at end of file diff --git a/roles/ipfs-cluster/handlers/main.yaml b/roles/ipfs-cluster/handlers/main.yaml deleted file mode 100644 index 8381b32..0000000 --- a/roles/ipfs-cluster/handlers/main.yaml +++ /dev/null @@ -1,16 +0,0 @@ -- name: reload systemd - become: yes - systemd: daemon_reload=yes - notify: restart IPFS Cluster - when: - - not (ansible_distribution == "Amazon" and ansible_distribution_major_version == "NA") - - not (ansible_distribution == "Ubuntu" and ansible_distribution_version is version('15.04', '<')) - - not (ansible_distribution == "Debian" and ansible_distribution_version is version('8', '<')) - - -- name: restart IPFS Cluster - become: yes - service: - name: ipfs-cluster - enabled: yes - state: restarted diff --git a/roles/ipfs-cluster/tasks/main.yml b/tasks/ipfs-cluster/main.yml similarity index 95% rename from roles/ipfs-cluster/tasks/main.yml rename to tasks/ipfs-cluster/main.yml index 012a5cf..96f4af0 100644 --- a/roles/ipfs-cluster/tasks/main.yml +++ b/tasks/ipfs-cluster/main.yml @@ -45,7 +45,7 @@ - name: install ipfs-cluster init service become: yes template: - src: etc/systemd/system/ipfs-cluster.service + src: ipfs-cluster/etc/systemd/system/ipfs-cluster.service dest: /etc/systemd/system/ipfs-cluster.service owner: root group: root @@ -61,7 +61,7 @@ - name: install ipfs-custer init service become: yes template: - src: etc/init.d/ipfs-cluster + src: ipfs-cluster/etc/init.d/ipfs-cluster dest: /etc/init.d/ipfs-cluster owner: root group: root @@ -85,7 +85,7 @@ - name: copy configuration become: yes template: - src: "{{ item }}" + src: "ipfs-cluster/{{ item }}" dest: "{{ ipfs_home }}/.ipfs-cluster/{{ item }}" mode: 0600 owner: ipfs @@ -110,7 +110,7 @@ - name: copy peerstore become: yes template: - src: peerstore + src: ipfs-cluster/peerstore dest: "{{ ipfs_home }}/.ipfs-cluster/peerstore" mode: 0600 owner: ipfs diff --git a/roles/ipfs/tasks/main.yml b/tasks/ipfs/main.yml similarity index 58% rename from roles/ipfs/tasks/main.yml rename to tasks/ipfs/main.yml index 9f6077c..8bdf949 100644 --- a/roles/ipfs/tasks/main.yml +++ b/tasks/ipfs/main.yml @@ -1,10 +1,10 @@ -- name: create download folder for go-ipfs +- name: create download folder for kubo become: yes file: state: directory owner: root group: root - dest: /opt/go-ipfs/{{ipfs_version}} + dest: /opt/kubo/{{ipfs_version}} - name: download and unpack IPFS when: not ansible_check_mode @@ -12,32 +12,32 @@ - name: download IPFS become: yes get_url: - url: "{{ dist_url }}/go-ipfs/{{ipfs_version}}/go-ipfs_{{ipfs_version}}_linux-{{ipfs_arch}}.tar.gz" - dest: /opt/go-ipfs/{{ipfs_version}}/go-ipfs.tar.gz + url: "{{ dist_url }}/kubo/{{ipfs_version}}/kubo_{{ipfs_version}}_linux-{{ipfs_arch}}.tar.gz" + dest: /opt/kubo/{{ipfs_version}}/kubo.tar.gz timeout: 30 - - name: unpack go-ipfs + - name: unpack kubo become: yes unarchive: remote_src: yes - src: /opt/go-ipfs/{{ipfs_version}}/go-ipfs.tar.gz - dest: /opt/go-ipfs/{{ipfs_version}} - creates: /opt/go-ipfs/{{ipfs_version}}/go-ipfs + src: /opt/kubo/{{ipfs_version}}/kubo.tar.gz + dest: /opt/kubo/{{ipfs_version}} + creates: /opt/kubo/{{ipfs_version}}/kubo notify: restart IPFS - - name: link go-ipfs executable + - name: link kubo executable become: yes file: state: link owner: root group: root dest: /usr/local/bin/ipfs - src: /opt/go-ipfs/{{ipfs_version}}/go-ipfs/ipfs + src: /opt/kubo/{{ipfs_version}}/kubo/ipfs - name: install ipfs systemd init service become: yes template: - src: etc/systemd/system/ipfs.service + src: ipfs/etc/systemd/system/ipfs.service dest: /etc/systemd/system/ipfs.service owner: root group: root @@ -55,7 +55,7 @@ - name: install ipfs init service become: yes template: - src: etc/init.d/ipfs + src: ipfs/etc/init.d/ipfs dest: /etc/init.d/ipfs owner: root group: root @@ -69,28 +69,10 @@ tags: - init - -- name: make ipfs group - become: yes - group: - state: present - name: ipfs - -- name: make ipfs user - become: yes - user: - state: present - name: ipfs - group: ipfs - shell: /bin/bash - home: "{{ ipfs_home }}" - comment: IPFS user - system: yes - - name: copy default config become: yes template: - src: home/ipfs/ipfs_default_config + src: ipfs/home/ipfs/ipfs_default_config dest: "{{ ipfs_home }}/ipfs_default_config" owner: ipfs group: ipfs @@ -101,39 +83,11 @@ - name: init IPFS become: yes become_user: ipfs - command: ipfs init --empty-repo -- {{ ipfs_home }}/ipfs_default_config + command: /usr/local/bin/ipfs init --empty-repo -- {{ ipfs_home }}/ipfs_default_config args: creates: "{{ ipfs_home }}/.ipfs/config" notify: restart IPFS -- name: download and unpack NOpfs - when: not ansible_check_mode - block: - - name: create plugins folder - become: yes - file: - state: directory - owner: ipfs - group: ipfs - dest: "{{ ipfs_home }}/.ipfs/plugins" - - - name: download and unpack nopfs - when: not ansible_check_mode - become: yes - unarchive: - remote_src: yes - src: "https://github.com/ipfs-shipyard/nopfs/releases/download/nopfs-kubo-plugin/{{nopfs_version}}/nopfs-kubo-plugin_{{nopfs_version}}_linux_{{ipfs_arch}}.tar.gz" - dest: "{{ ipfs_home }}/.ipfs/plugins/" - include: - - nopfs-kubo-plugin/nopfs-kubo-plugin - extra_opts: - - "--strip-components=1" - owner: ipfs - group: ipfs - notify: restart IPFS - tags: - - nopfs - - name: set version file (to notify restart on upgrades) become: yes copy: @@ -143,7 +97,7 @@ owner: ipfs group: ipfs notify: restart IPFS - + - name: reload systemd become: yes systemd: diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..edddcd9 --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,26 @@ +- name: make ipfs group + become: yes + group: + state: present + name: ipfs + +- name: make ipfs user + become: yes + user: + state: present + name: ipfs + group: ipfs + shell: /bin/bash + home: "{{ ipfs_home }}" + comment: IPFS user + system: yes + +- name: Set up ipfs + include_tasks: "{{ role_path }}/tasks/ipfs/main.yml" + tags: ipfs + when: ipfs_enable | bool + +- name: Set up ipfs-cluster + include_tasks: "{{ role_path }}/tasks/ipfs-cluster/main.yml" + tags: ipfs-cluster + when: ipfs_cluster_enable | bool \ No newline at end of file diff --git a/roles/ipfs-cluster/templates/etc/init.d/ipfs-cluster b/templates/ipfs-cluster/etc/init.d/ipfs-cluster similarity index 100% rename from roles/ipfs-cluster/templates/etc/init.d/ipfs-cluster rename to templates/ipfs-cluster/etc/init.d/ipfs-cluster diff --git a/roles/ipfs-cluster/templates/etc/systemd/system/ipfs-cluster.service b/templates/ipfs-cluster/etc/systemd/system/ipfs-cluster.service similarity index 100% rename from roles/ipfs-cluster/templates/etc/systemd/system/ipfs-cluster.service rename to templates/ipfs-cluster/etc/systemd/system/ipfs-cluster.service diff --git a/roles/ipfs-cluster/templates/identity.json b/templates/ipfs-cluster/identity.json similarity index 100% rename from roles/ipfs-cluster/templates/identity.json rename to templates/ipfs-cluster/identity.json diff --git a/roles/ipfs-cluster/templates/peerstore b/templates/ipfs-cluster/peerstore similarity index 100% rename from roles/ipfs-cluster/templates/peerstore rename to templates/ipfs-cluster/peerstore diff --git a/roles/ipfs-cluster/templates/service.json b/templates/ipfs-cluster/service.json similarity index 100% rename from roles/ipfs-cluster/templates/service.json rename to templates/ipfs-cluster/service.json diff --git a/roles/ipfs/templates/etc/init.d/ipfs b/templates/ipfs/etc/init.d/ipfs similarity index 100% rename from roles/ipfs/templates/etc/init.d/ipfs rename to templates/ipfs/etc/init.d/ipfs diff --git a/roles/ipfs/templates/etc/systemd/system/ipfs.service b/templates/ipfs/etc/systemd/system/ipfs.service similarity index 63% rename from roles/ipfs/templates/etc/systemd/system/ipfs.service rename to templates/ipfs/etc/systemd/system/ipfs.service index 1e69814..18c0326 100644 --- a/roles/ipfs/templates/etc/systemd/system/ipfs.service +++ b/templates/ipfs/etc/systemd/system/ipfs.service @@ -9,9 +9,12 @@ Group=ipfs StateDirectory=ipfs TimeoutStartSec=10800 LimitNOFILE={{ ipfs_fd_max }} +{% if ipfs_memory_max is defined %} +MemoryMax={{ ipfs_memory_max }} +{% endif %} MemorySwapMax=0 Environment="IPFS_FD_MAX={{ ipfs_fd_max}}" -ExecStart=/usr/local/bin/ipfs daemon --migrate {%- if ipfs_enable_gc | default(False) %} --enable-gc{% endif %} +ExecStart=/usr/local/bin/ipfs daemon --migrate {%- if ipfs_enable_gc | default(False) %} --enable-gc{% endif %} {%- if ipfs_routing | default(False) %} --routing={{ ipfs_routing }}{% endif %} Restart=on-failure KillSignal=SIGINT diff --git a/roles/ipfs/templates/home/ipfs/ipfs_default_config b/templates/ipfs/home/ipfs/ipfs_default_config similarity index 95% rename from roles/ipfs/templates/home/ipfs/ipfs_default_config rename to templates/ipfs/home/ipfs/ipfs_default_config index 1904570..8af5185 100644 --- a/roles/ipfs/templates/home/ipfs/ipfs_default_config +++ b/templates/ipfs/home/ipfs/ipfs_default_config @@ -201,7 +201,18 @@ "Router": "" }, "Peering": { + {% if ipfs_peering_nodes is defined and ipfs_peering_nodes|length %} + "Peers":[ + {% for node in ipfs_peering_nodes %} + { + "ID": {{ node.id }}, + "Addrs": {{ node.addrs | to_json }} + }{% if not loop.last %},{% endif %} + {% endfor %} + ] + {% else %} "Peers": null + {% endif %} }, "DNS": { "Resolvers": {} diff --git a/vars/main.yml b/vars/main.yml new file mode 100644 index 0000000..3d6e1dc --- /dev/null +++ b/vars/main.yml @@ -0,0 +1 @@ +dist_url: https://dist.ipfs.tech