From 828bd25175805b5869c1b351e46e8fa470a930b6 Mon Sep 17 00:00:00 2001 From: Ben Kochie Date: Mon, 25 Jun 2018 19:19:34 +0200 Subject: [PATCH 1/3] Add option to create minio clusters Add a cluster list that overrides the datadirs list, this allows for local creation of data storage directories separate from a list of cluster members. --- README.md | 19 ++++++++ defaults/main.yml | 3 ++ molecule/cluster/molecule.yml | 51 ++++++++++++++++++++ molecule/cluster/playbook.yml | 11 +++++ molecule/cluster/tests/test_minio_cluster.py | 35 ++++++++++++++ templates/minio.env.j2 | 4 ++ 6 files changed, 123 insertions(+) create mode 100644 molecule/cluster/molecule.yml create mode 100644 molecule/cluster/playbook.yml create mode 100644 molecule/cluster/tests/test_minio_cluster.py diff --git a/README.md b/README.md index 0a38aee..f53ae56 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,25 @@ minio_server_make_datadirs: true Create directories from `minio_server_datadirs` +```yaml +minio_server_cluster_nodes: [ ] +``` + +Set a list of nodes to create a [distributed cluster](https://docs.minio.io/docs/distributed-minio-quickstart-guide). + +In this mode, ansible will create your server datadirs, but use this list for the server startup. + +Example: + +```yaml +minio_server_datadirs: + - '/minio-data' +minio_server_cluster_nodes: + - 'https://server1/minio-data' + - 'https://server2/minio-data' + - 'https://server3/minio-data' +``` + ```yaml minio_server_opts: "" ``` diff --git a/defaults/main.yml b/defaults/main.yml index 9dfda1a..99b92ce 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -18,6 +18,9 @@ minio_server_addr: ":9091" minio_server_datadirs: [ ] minio_server_make_datadirs: true +# Minio server cluster node list. +minio_server_cluster_nodes: [ ] + # Additional minio server CLI options minio_server_opts: "" diff --git a/molecule/cluster/molecule.yml b/molecule/cluster/molecule.yml new file mode 100644 index 0000000..e1ff900 --- /dev/null +++ b/molecule/cluster/molecule.yml @@ -0,0 +1,51 @@ +--- +driver: + name: docker +lint: + name: yamllint + +platforms: + - name: minio-centos-7 + image: paulfantom/centos-molecule:7 + privileged: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:ro + - name: minio-fedora-27 + image: paulfantom/fedora-molecule:27 + privileged: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:ro + - name: minio-debian-9 + image: paulfantom/debian-molecule:9 + privileged: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:ro + - name: minio-ubuntu-18.04 + image: paulfantom/ubuntu-molecule:18.04 + privileged: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:ro + - name: minio-ubuntu-16.04 + image: paulfantom/ubuntu-molecule:16.04 + privileged: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:ro + + +provisioner: + name: ansible + lint: + name: ansible-lint + playbooks: + create: ../default/create.yml + prepare: ../default/prepare.yml + converge: playbook.yml + destroy: ../default/destroy.yml + +scenario: + name: cluster +verifier: + name: testinfra + lint: + name: flake8 + enabled: true diff --git a/molecule/cluster/playbook.yml b/molecule/cluster/playbook.yml new file mode 100644 index 0000000..62127ac --- /dev/null +++ b/molecule/cluster/playbook.yml @@ -0,0 +1,11 @@ +--- + +- hosts: all + any_errors_fatal: true + roles: + - ansible-minio + vars: + minio_server_datadirs: + - "/test" + minio_server_cluster_nodes: + - "https://172.17.0.2:9091/test" diff --git a/molecule/cluster/tests/test_minio_cluster.py b/molecule/cluster/tests/test_minio_cluster.py new file mode 100644 index 0000000..4a31134 --- /dev/null +++ b/molecule/cluster/tests/test_minio_cluster.py @@ -0,0 +1,35 @@ +import yaml +import pytest +import testinfra.utils.ansible_runner + +testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( + '.molecule/ansible_inventory').get_hosts('all') + + +@pytest.fixture() +def AnsibleDefaults(Ansible): + with open("./defaults/main.yml", 'r') as stream: + return yaml.load(stream) + + +@pytest.mark.parametrize("dirs", [ + "/minio-test" +]) +def test_directories(host, dirs): + d = host.file(dirs) + assert d.is_directory + assert d.exists + assert d.user == AnsibleDefaults['minio_user'] + assert d.group == AnsibleDefaults['minio_group'] + assert oct(d.mode) == '0750' + + +def test_env_file(host): + env_file = host.file("/etc/default/minio") + assert env_file.contains('MINIO_VOLUMES="https://172.17.0.2:9091/test"') + + +def test_minio_service(Service): + s = Service('minio') + assert s.is_running + assert s.is_enabled diff --git a/templates/minio.env.j2 b/templates/minio.env.j2 index 4ad10be..c121f91 100644 --- a/templates/minio.env.j2 +++ b/templates/minio.env.j2 @@ -1,7 +1,11 @@ # {{ ansible_managed }} # Minio local/remote volumes. +{% if minio_server_cluster_nodes | length > 0 %} +MINIO_VOLUMES="{{ minio_server_cluster_nodes | join(' ') }}" +{% else %} MINIO_VOLUMES="{{ minio_server_datadirs | join(' ') }}" +{% endif %} # Minio cli options. MINIO_OPTS="--address {{ minio_server_addr }} {{ minio_server_opts }}" From 6924d8eba4db4cbbed0d7f26679ad04a66b0a8c2 Mon Sep 17 00:00:00 2001 From: Ben Kochie Date: Mon, 25 Jun 2018 20:19:30 +0200 Subject: [PATCH 2/3] Fix tests. --- molecule/cluster/playbook.yml | 10 ++++++++-- molecule/cluster/tests/test_minio_cluster.py | 5 ++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/molecule/cluster/playbook.yml b/molecule/cluster/playbook.yml index 62127ac..b5b3c4e 100644 --- a/molecule/cluster/playbook.yml +++ b/molecule/cluster/playbook.yml @@ -6,6 +6,12 @@ - ansible-minio vars: minio_server_datadirs: - - "/test" + - "/test1" + - "/test2" + - "/test3" + - "/test4" minio_server_cluster_nodes: - - "https://172.17.0.2:9091/test" + - "http://{{ ansible_hostname }}:9091/test1" + - "http://{{ ansible_hostname }}:9091/test2" + - "http://{{ ansible_hostname }}:9091/test3" + - "http://{{ ansible_hostname }}:9091/test4" diff --git a/molecule/cluster/tests/test_minio_cluster.py b/molecule/cluster/tests/test_minio_cluster.py index 4a31134..1f125d0 100644 --- a/molecule/cluster/tests/test_minio_cluster.py +++ b/molecule/cluster/tests/test_minio_cluster.py @@ -26,7 +26,10 @@ def test_directories(host, dirs): def test_env_file(host): env_file = host.file("/etc/default/minio") - assert env_file.contains('MINIO_VOLUMES="https://172.17.0.2:9091/test"') + a = host.ansible.get_variables() + host = a['ansible_hostname'] + volume_string = "MINIO_VOLUMES=\"http://%s:9091/test1 " % (host) + assert env_file.contains(volume_string) def test_minio_service(Service): From 756bc21e6b21c285586ebd6936200efeca6c4bb9 Mon Sep 17 00:00:00 2001 From: Ben Kochie Date: Mon, 25 Jun 2018 22:58:09 +0200 Subject: [PATCH 3/3] Add additional cluster storage notes. --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f53ae56..1130c77 100644 --- a/README.md +++ b/README.md @@ -64,17 +64,19 @@ minio_server_cluster_nodes: [ ] Set a list of nodes to create a [distributed cluster](https://docs.minio.io/docs/distributed-minio-quickstart-guide). -In this mode, ansible will create your server datadirs, but use this list for the server startup. +In this mode, ansible will create your server datadirs, but use this list for the server startup. Note you will need a number of disks to satisfy Minio's distributed storage requirements. Example: ```yaml minio_server_datadirs: - '/minio-data' + - ... minio_server_cluster_nodes: - 'https://server1/minio-data' - 'https://server2/minio-data' - 'https://server3/minio-data' + - ... ``` ```yaml