diff --git a/.gitignore b/.gitignore index c9d1596..c7d5766 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ *~ *.bak *.retry +__pycache__ +*.pyc diff --git a/roles/product_base/.yamllint b/roles/product_base/.yamllint new file mode 100644 index 0000000..ad0be76 --- /dev/null +++ b/roles/product_base/.yamllint @@ -0,0 +1,11 @@ +extends: default + +rules: + braces: + max-spaces-inside: 1 + level: error + brackets: + max-spaces-inside: 1 + level: error + line-length: disable + truthy: disable diff --git a/roles/product_base/molecule/default/Dockerfile.j2 b/roles/product_base/molecule/default/Dockerfile.j2 new file mode 100644 index 0000000..e6aa95d --- /dev/null +++ b/roles/product_base/molecule/default/Dockerfile.j2 @@ -0,0 +1,14 @@ +# Molecule managed + +{% if item.registry is defined %} +FROM {{ item.registry.url }}/{{ item.image }} +{% else %} +FROM {{ item.image }} +{% endif %} + +RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y python sudo bash ca-certificates && apt-get clean; \ + elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python sudo python-devel python*-dnf bash && dnf clean all; \ + elif [ $(command -v yum) ]; then yum makecache fast && yum install -y python sudo yum-plugin-ovl bash && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \ + elif [ $(command -v zypper) ]; then zypper refresh && zypper install -y python sudo bash python-xml && zypper clean -a; \ + elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates; \ + elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python sudo bash ca-certificates && xbps-remove -O; fi diff --git a/roles/product_base/molecule/default/molecule.yml b/roles/product_base/molecule/default/molecule.yml new file mode 100644 index 0000000..65faca2 --- /dev/null +++ b/roles/product_base/molecule/default/molecule.yml @@ -0,0 +1,18 @@ +--- +dependency: + name: galaxy +driver: + name: docker +lint: + name: yamllint +platforms: + - name: instance + image: centos:7 +provisioner: + name: ansible + lint: + name: ansible-lint +verifier: + name: testinfra + lint: + name: flake8 diff --git a/roles/product_base/molecule/default/playbook.yml b/roles/product_base/molecule/default/playbook.yml new file mode 100644 index 0000000..82e95cf --- /dev/null +++ b/roles/product_base/molecule/default/playbook.yml @@ -0,0 +1,9 @@ +--- +- name: Converge + hosts: all + vars: + atl_product_user: "testuser" + atl_product_home: "/opt/atlassian/product" + atl_temp_dir: "/opt/atlassian/temp" + roles: + - role: product_base diff --git a/roles/product_base/molecule/default/tests/test_default.py b/roles/product_base/molecule/default/tests/test_default.py new file mode 100644 index 0000000..f7ecb48 --- /dev/null +++ b/roles/product_base/molecule/default/tests/test_default.py @@ -0,0 +1,23 @@ +import os +import pytest + +import testinfra.utils.ansible_runner + +testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( + os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') + + +def test_user_created(host): + user = host.user('testuser') + assert user.exists + + +@pytest.mark.parametrize('target', [ + '/opt/atlassian/product', + '/opt/atlassian/temp' +]) +def test_dirs_created(host, target): + d = host.file(target) + assert d.exists + assert d.is_directory + assert d.user == 'testuser' diff --git a/roles/product_base/tasks/main.yml b/roles/product_base/tasks/main.yml index 4758609..2447210 100644 --- a/roles/product_base/tasks/main.yml +++ b/roles/product_base/tasks/main.yml @@ -2,5 +2,15 @@ - name: Create product user user: - name: "{{ product_user }}" + name: "{{ atl_product_user }}" comment: "Product runtime user" + +- name: Create installation directories + file: + path: "{{ item }}" + state: directory + mode: 0750 + owner: "{{ atl_product_user }}" + with_items: + - "{{ atl_product_home }}" + - "{{ atl_temp_dir }}"