Skip to content

Convert into ansible role (#9) #10

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

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions Makefile

This file was deleted.

123 changes: 98 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -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_daemon_peer_id>"
ipfs_private_key: "<ipfs_daemon_private_key>"

ipfs_cluster_id: "<cluster_peer_id>"
ipfs_cluster_private_key: "<cluster_peer_private_key>"

ipfs_cluster_peer_addr: "/dns4/<hostname>/tcp/9096/ipfs/<ipfs_cluster_peer_id>"
```

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: <PeerId>` 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/<hostname>/tcp/9096/ipfs/<ipfs_cluster_peer_id>"
```
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
```
31 changes: 31 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -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
10 changes: 0 additions & 10 deletions group_vars/README.md

This file was deleted.

14 changes: 0 additions & 14 deletions group_vars/ipfs.yml

This file was deleted.

5 changes: 0 additions & 5 deletions group_vars/ipfs_cluster.yml

This file was deleted.

8 changes: 7 additions & 1 deletion roles/ipfs/handlers/main.yml → handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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', '<'))
Expand All @@ -15,3 +14,10 @@
name: ipfs
enabled: yes
state: restarted

- name: restart IPFS Cluster
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no reason to restart cluster just because IPFS role has run, is there?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

didn't get this one. the handler is called only if there are tasks with notify: restart IPFS Cluster am I missing something ?

become: yes
service:
name: ipfs-cluster
enabled: yes
state: restarted
65 changes: 0 additions & 65 deletions host_vars/README.md

This file was deleted.

5 changes: 0 additions & 5 deletions inventory.yml

This file was deleted.

3 changes: 0 additions & 3 deletions ipfs-cluster.yml

This file was deleted.

6 changes: 0 additions & 6 deletions ipfs.yml

This file was deleted.

51 changes: 51 additions & 0 deletions meta/main.yml
Original file line number Diff line number Diff line change
@@ -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.
10 changes: 10 additions & 0 deletions molecule/default/converge.yml
Original file line number Diff line number Diff line change
@@ -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"
Loading