diff --git a/.travis.yml b/.travis.yml index b0ada53..619d74f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,9 +12,9 @@ services: env: matrix: - - ANSIBLE=2.3 - ANSIBLE=2.4 - ANSIBLE=2.5 + - ANSIBLE=2.6 # Install tox install: diff --git a/.yamllint b/.yamllint index 06fd860..739c7c1 100644 --- a/.yamllint +++ b/.yamllint @@ -1,14 +1,21 @@ extends: default + ignore: | .travis/ .travis.yml meta/ rules: + + # Disable line-length and truthy values reporting + line-length: disable + truthy: disable + + # Max 1 space to separate the elements in brakets braces: max-spaces-inside: 1 - level: error + + # Max 1 space in empty brackets brackets: - max-spaces-inside: 1 - level: error - line-length: disable + min-spaces-inside-empty: 0 + max-spaces-inside-empty: 1 diff --git a/molecule/alternative/molecule.yml b/molecule/alternative/molecule.yml index 41bef2b..efc3e2b 100644 --- a/molecule/alternative/molecule.yml +++ b/molecule/alternative/molecule.yml @@ -1,8 +1,13 @@ --- + +scenario: + name: alternative + driver: name: docker -lint: - name: yamllint + +dependency: + name: galaxy platforms: - name: minio-centos-7 @@ -35,16 +40,22 @@ provisioner: name: ansible lint: name: ansible-lint + options: + diff: True + v: True playbooks: - create: ../default/create.yml - prepare: ../default/prepare.yml - converge: playbook.yml - destroy: ../default/destroy.yml + create: ../resources/create.yml + prepare: ../resources/prepare.yml + destroy: ../resources/destroy.yml + +lint: + name: yamllint -scenario: - name: alternative verifier: name: testinfra + options: + vvv: True + additional_files_or_dirs: + - ../resources/tests/ lint: name: flake8 - enabled: true diff --git a/molecule/alternative/tests/test_minio.py b/molecule/alternative/tests/test_minio.py deleted file mode 100644 index 142a110..0000000 --- a/molecule/alternative/tests/test_minio.py +++ /dev/null @@ -1,49 +0,0 @@ -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' - - -@pytest.mark.parametrize('minio_bin_var', [ - 'minio_server_bin', - 'minio_client_bin', -]) -def test_minio_installed(File, AnsibleDefaults, minio_bin_var): - - f = File(AnsibleDefaults[minio_bin_var]) - assert f.exists - assert f.user == AnsibleDefaults['minio_user'] - assert f.group == AnsibleDefaults['minio_group'] - assert oct(f.mode) == '0755' - - -def test_minio_service(Service): - - s = Service('minio') - assert s.is_running - assert s.is_enabled - - -def test_capabilities(host): - service_file = host.file("/etc/systemd/system/minio.service") - assert service_file.contains("AmbientCapabilities=CAP_NET_BIND_SERVICE") diff --git a/molecule/alternative/tests/test_minio_alternative.py b/molecule/alternative/tests/test_minio_alternative.py new file mode 100644 index 0000000..a809115 --- /dev/null +++ b/molecule/alternative/tests/test_minio_alternative.py @@ -0,0 +1,45 @@ +import os +import yaml +import pytest +import testinfra.utils.ansible_runner + + +testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( + os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') + + +@pytest.fixture() +def AnsibleDefaults(Ansible): + with open("../../defaults/main.yml", 'r') as stream: + return yaml.load(stream) + + +def test_minio_server_env_file(host, AnsibleDefaults): + + f = host.file('/opt/minio') + assert f.is_file + assert f.exists + assert f.user == 'root' + assert f.group == AnsibleDefaults['minio_group'] + assert oct(f.mode) == '0640' + + +@pytest.mark.parametrize('minio_datadir', [ + '/srv/data1', + '/srv/data2', + '/srv/data3', + '/srv/data4' +]) +def test_minio_server_data_directories(host, AnsibleDefaults, minio_datadir): + + d = host.file(minio_datadir) + 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_minio_server_webserver(host): + + host.socket("tcp://127.0.0.1:80").is_listening diff --git a/molecule/cluster/molecule.yml b/molecule/cluster/molecule.yml index e1ff900..5041513 100644 --- a/molecule/cluster/molecule.yml +++ b/molecule/cluster/molecule.yml @@ -1,8 +1,13 @@ --- + +scenario: + name: cluster + driver: name: docker -lint: - name: yamllint + +dependency: + name: galaxy platforms: - name: minio-centos-7 @@ -31,21 +36,26 @@ platforms: volumes: - /sys/fs/cgroup:/sys/fs/cgroup:ro - provisioner: name: ansible lint: name: ansible-lint + options: + diff: True + v: True playbooks: - create: ../default/create.yml - prepare: ../default/prepare.yml - converge: playbook.yml - destroy: ../default/destroy.yml + create: ../resources/create.yml + prepare: ../resources/prepare.yml + destroy: ../resources/destroy.yml + +lint: + name: yamllint -scenario: - name: cluster verifier: name: testinfra + options: + vvv: True + additional_files_or_dirs: + - ../resources/tests/ lint: name: flake8 - enabled: true diff --git a/molecule/cluster/tests/test_minio_cluster.py b/molecule/cluster/tests/test_minio_cluster.py index 1f125d0..11841a1 100644 --- a/molecule/cluster/tests/test_minio_cluster.py +++ b/molecule/cluster/tests/test_minio_cluster.py @@ -1,38 +1,30 @@ +import os import yaml import pytest import testinfra.utils.ansible_runner + testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - '.molecule/ansible_inventory').get_hosts('all') + os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') @pytest.fixture() def AnsibleDefaults(Ansible): - with open("./defaults/main.yml", 'r') as stream: + with open("../../defaults/main.yml", 'r') as stream: return yaml.load(stream) -@pytest.mark.parametrize("dirs", [ - "/minio-test" +@pytest.mark.parametrize('minio_datadir', [ + '/test1', + '/test2', + '/test3', + '/test4' ]) -def test_directories(host, dirs): - d = host.file(dirs) +def test_directories(host, AnsibleDefaults, minio_datadir): + + d = host.file(minio_datadir) 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") - 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): - s = Service('minio') - assert s.is_running - assert s.is_enabled diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml index dc4a929..817f6bb 100644 --- a/molecule/default/molecule.yml +++ b/molecule/default/molecule.yml @@ -1,8 +1,13 @@ --- + +scenario: + name: default + driver: name: docker -lint: - name: yamllint + +dependency: + name: galaxy platforms: - name: minio-centos-7 @@ -31,21 +36,26 @@ platforms: volumes: - /sys/fs/cgroup:/sys/fs/cgroup:ro - provisioner: name: ansible lint: name: ansible-lint + options: + diff: True + v: True playbooks: - create: create.yml - prepare: prepare.yml - converge: playbook.yml - destroy: destroy.yml + create: ../resources/create.yml + destroy: ../resources/destroy.yml + prepare: ../resources/prepare.yml + +lint: + name: yamllint -scenario: - name: default verifier: name: testinfra + options: + vvv: True + additional_files_or_dirs: + - ../resources/tests/ lint: name: flake8 - enabled: true diff --git a/molecule/default/playbook.yml b/molecule/default/playbook.yml index dc269bd..6451545 100644 --- a/molecule/default/playbook.yml +++ b/molecule/default/playbook.yml @@ -4,5 +4,3 @@ any_errors_fatal: true roles: - ansible-minio - vars: - minio_server_datadirs: [ "/minio-test" ] diff --git a/molecule/default/prepare.yml b/molecule/default/prepare.yml deleted file mode 100644 index 5358b3b..0000000 --- a/molecule/default/prepare.yml +++ /dev/null @@ -1,5 +0,0 @@ ---- -- name: Prepare - hosts: all - gather_facts: false - tasks: [] diff --git a/molecule/default/tests/test_minio.py b/molecule/default/tests/test_minio.py deleted file mode 100644 index d09f8d8..0000000 --- a/molecule/default/tests/test_minio.py +++ /dev/null @@ -1,44 +0,0 @@ -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' - - -@pytest.mark.parametrize('minio_bin_var', [ - 'minio_server_bin', - 'minio_client_bin', -]) -def test_minio_installed(File, AnsibleDefaults, minio_bin_var): - - f = File(AnsibleDefaults[minio_bin_var]) - assert f.exists - assert f.user == AnsibleDefaults['minio_user'] - assert f.group == AnsibleDefaults['minio_group'] - assert oct(f.mode) == '0755' - - -def test_minio_service(Service): - - s = Service('minio') - assert s.is_running - assert s.is_enabled diff --git a/molecule/default/tests/test_minio_default.py b/molecule/default/tests/test_minio_default.py new file mode 100644 index 0000000..397a96e --- /dev/null +++ b/molecule/default/tests/test_minio_default.py @@ -0,0 +1,43 @@ +import os +import yaml +import pytest +import testinfra.utils.ansible_runner + + +testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( + os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') + + +@pytest.fixture() +def AnsibleDefaults(Ansible): + with open("../../defaults/main.yml", 'r') as stream: + return yaml.load(stream) + + +@pytest.mark.parametrize('minio_bin_var', [ + 'minio_server_bin', + 'minio_client_bin', +]) +def test_minio_installed(host, AnsibleDefaults, minio_bin_var): + + f = host.file(AnsibleDefaults[minio_bin_var]) + assert f.exists + assert f.user == 'root' + assert f.group == 'root' + assert oct(f.mode) == '0755' + + +def test_minio_server_data_directories(host, AnsibleDefaults): + + for datadir in AnsibleDefaults['minio_server_datadirs']: + d = host.file(datadir) + 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_minio_server_webserver(host): + + host.socket("tcp://127.0.0.1:9091").is_listening diff --git a/molecule/default/create.yml b/molecule/resources/create.yml similarity index 100% rename from molecule/default/create.yml rename to molecule/resources/create.yml diff --git a/molecule/default/destroy.yml b/molecule/resources/destroy.yml similarity index 100% rename from molecule/default/destroy.yml rename to molecule/resources/destroy.yml diff --git a/molecule/resources/prepare.yml b/molecule/resources/prepare.yml new file mode 100644 index 0000000..f16ae76 --- /dev/null +++ b/molecule/resources/prepare.yml @@ -0,0 +1,12 @@ +--- +- name: Prepare + hosts: all + gather_facts: true + tasks: + - name: Install ansible support packages + package: + name: "{{ item }}" + state: present + with_items: + - ca-certificates + when: ansible_os_family == 'Debian' diff --git a/molecule/resources/tests/test_minio_common.py b/molecule/resources/tests/test_minio_common.py new file mode 100644 index 0000000..9524e02 --- /dev/null +++ b/molecule/resources/tests/test_minio_common.py @@ -0,0 +1,13 @@ +import os +import testinfra.utils.ansible_runner + + +testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( + os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') + + +def test_minio_service(host): + + s = host.service('minio') + assert s.is_running + assert s.is_enabled diff --git a/tasks/client.yml b/tasks/client.yml deleted file mode 100644 index 2ad9365..0000000 --- a/tasks/client.yml +++ /dev/null @@ -1,13 +0,0 @@ ---- -- name: download minio client - get_url: - url: "{{ minio_client_download_url }}" - dest: "{{ minio_client_bin }}" - owner: "root" - group: "root" - mode: 0755 - checksum: "sha256:{{ minio_client_checksum }}" - register: _download_client - until: _download_client is succeeded - retries: 5 - delay: 2 diff --git a/tasks/install-client.yml b/tasks/install-client.yml new file mode 100644 index 0000000..77fe977 --- /dev/null +++ b/tasks/install-client.yml @@ -0,0 +1,22 @@ +--- + +- name: Compose the Minio client download url + set_fact: + _minio_client_download_url: "https://dl.minio.io/client/mc/release/linux-{{ go_arch_map[ansible_architecture] | default(ansible_architecture) }}/mc" + +- name: "Get the Minio client checksum for {{ go_arch_map[ansible_architecture] | default(ansible_architecture) }} architecture" + set_fact: + _minio_client_checksum: "{{ lookup('url', _minio_client_download_url + '.sha256sum').split(' ')[0] }}" + +- name: Download the Minio client + get_url: + url: "{{ _minio_client_download_url }}" + dest: "{{ minio_client_bin }}" + owner: "root" + group: "root" + mode: 0755 + checksum: "sha256:{{ _minio_client_checksum }}" + register: _download_client + until: _download_client is succeeded + retries: 5 + delay: 2 diff --git a/tasks/install-server.yml b/tasks/install-server.yml new file mode 100644 index 0000000..2191240 --- /dev/null +++ b/tasks/install-server.yml @@ -0,0 +1,75 @@ +--- + +- name: Compose the Minio server download url + set_fact: + _minio_server_download_url: "https://dl.minio.io/server/minio/release/linux-{{ go_arch_map[ansible_architecture] | default(ansible_architecture) }}/minio" + +- name: "Get the Minio server checksum for {{ go_arch_map[ansible_architecture] | default(ansible_architecture) }} architecture" + set_fact: + _minio_server_checksum: "{{ lookup('url', _minio_server_download_url + '.sha256sum').split(' ')[0] }}" + +- name: Create Minio group + group: + name: "{{ minio_group }}" + state: present + +- name: Create Minio user + user: + name: "{{ minio_user }}" + group: "{{ minio_group }}" + shell: /bin/bash + +- name: Create the Minio data storage directories + file: + path: "{{ item }}" + state: directory + owner: "{{ minio_user }}" + group: "{{ minio_group }}" + mode: 0750 + when: minio_server_make_datadirs + with_items: "{{ minio_server_datadirs }}" + +- name: Download the Minio server + get_url: + url: "{{ _minio_server_download_url }}" + dest: "{{ minio_server_bin }}" + owner: "root" + group: "root" + mode: 0755 + checksum: "sha256:{{ _minio_server_checksum }}" + register: _download_server + until: _download_server is succeeded + retries: 5 + delay: 2 + +- name: Generate the Minio server envfile + template: + src: minio.env.j2 + dest: "{{ minio_server_envfile }}" + owner: "root" + group: "{{ minio_group }}" + mode: 0640 + notify: restart minio + +- name: Create the Minio server systemd config + template: + src: minio.service.j2 + dest: "/etc/systemd/system/minio.service" + owner: "root" + group: "root" + when: ansible_service_mgr == "systemd" + +- name: Create the Minio server init.d config + template: + src: minio.init.j2 + dest: "/etc/init.d/minio" + owner: "root" + group: "root" + mode: 0750 + when: ansible_service_mgr != "systemd" + +- name: Enable and start the Minio service + service: + name: minio + state: started + enabled: true diff --git a/tasks/main.yml b/tasks/main.yml index b338379..4abb3ca 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,38 +1,14 @@ --- -- include: preflight.yml -- name: add the python sni support to legacy python installations +- name: Add sni support to legacy python installations include: python_sni.yml when: - ansible_os_family == 'Debian' - ansible_python_version is version_compare('2.6.0', '>=') - ansible_python_version is version_compare('2.7.9', '<') -- name: install ansible support packages - package: - name: "{{ item }}" - state: present - with_items: - - ca-certificates - register: _install_packages - until: _install_packages is succeeded - retries: 5 - delay: 2 - when: ansible_os_family == 'Debian' - -- name: create minio group - group: - name: "{{ minio_group }}" - state: present - -- name: create minio user - user: - name: "{{ minio_user }}" - group: "{{ minio_group }}" - shell: /bin/bash - -- include: server.yml +- include: install-server.yml when: minio_install_server -- include: client.yml +- include: install-client.yml when: minio_install_client diff --git a/tasks/preflight.yml b/tasks/preflight.yml deleted file mode 100644 index 7fc2153..0000000 --- a/tasks/preflight.yml +++ /dev/null @@ -1,22 +0,0 @@ ---- -- block: - - name: Compose Minio download url - set_fact: - minio_server_download_url: "https://dl.minio.io/server/minio/release/linux-{{ go_arch_map[ansible_architecture] | default(ansible_architecture) }}/minio" - - - name: "Minio server checksum for {{ go_arch_map[ansible_architecture] | default(ansible_architecture) }} architecture" - set_fact: - minio_server_checksum: "{{ lookup('url', minio_server_download_url + '.sha256sum').split(' ')[0] }}" - when: - - minio_install_server - -- block: - - name: Compose MC download url - set_fact: - minio_client_download_url: "https://dl.minio.io/client/mc/release/linux-{{ go_arch_map[ansible_architecture] | default(ansible_architecture) }}/mc" - - - name: "Minio client checksum for {{ go_arch_map[ansible_architecture] | default(ansible_architecture) }} architecture" - set_fact: - minio_client_checksum: "{{ lookup('url', minio_client_download_url + '.sha256sum').split(' ')[0] }}" - when: - - minio_install_client diff --git a/tasks/python_sni.yml b/tasks/python_sni.yml index 9d5e1ba..21e462e 100644 --- a/tasks/python_sni.yml +++ b/tasks/python_sni.yml @@ -1,4 +1,5 @@ --- + - name: install python-pip and SNI support packages package: name: "{{ item }}" diff --git a/tasks/server.yml b/tasks/server.yml deleted file mode 100644 index 9a795bb..0000000 --- a/tasks/server.yml +++ /dev/null @@ -1,59 +0,0 @@ ---- -- name: create minio group - group: - name: "{{ minio_group }}" - state: present - -- name: create minio user - user: - name: "{{ minio_user }}" - group: "{{ minio_group }}" - shell: /bin/bash - -- name: create data storage directories - file: - path: "{{ item }}" - state: directory - owner: "{{ minio_user }}" - group: "{{ minio_group }}" - mode: 0750 - when: minio_server_make_datadirs - with_items: "{{ minio_server_datadirs }}" - -- name: download minio server - get_url: - url: "{{ minio_server_download_url }}" - dest: "{{ minio_server_bin }}" - owner: "root" - group: "root" - mode: 0755 - checksum: "sha256:{{ minio_server_checksum }}" - register: _download_server - until: _download_server is succeeded - retries: 5 - delay: 2 - -- name: generate the minio server envfile - template: - src: minio.env.j2 - dest: "{{ minio_server_envfile }}" - notify: restart minio - -- name: create the minio server systemd config - template: - src: minio.service.j2 - dest: "/etc/systemd/system/minio.service" - when: ansible_service_mgr == "systemd" - -- name: create the minio server init.d config - template: - src: minio.init.j2 - dest: "/etc/init.d/minio" - mode: 0750 - when: ansible_service_mgr != "systemd" - -- name: enable and start the minio service - service: - name: minio - state: started - enabled: true diff --git a/tox.ini b/tox.ini index d32a1ca..56fd2aa 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,6 @@ [tox] minversion = 1.8 -envlist = py{27}-ansible{23,24,25} +envlist = py{27}-ansible{23,24,25,26} skipsdist = true [travis:env] @@ -8,6 +8,7 @@ ANSIBLE= 2.3: ansible23 2.4: ansible24 2.5: ansible25 + 2.6: ansible26 [testenv] passenv = * @@ -16,5 +17,6 @@ deps = ansible23: ansible<2.4 ansible24: ansible<2.5 ansible25: ansible<2.6 + ansible26: ansible<2.7 commands = {posargs:molecule test --all --destroy always}