From 29986647b1710ed1c7ad16bdc859e6e0eb19fd9a Mon Sep 17 00:00:00 2001 From: John Freeman Date: Tue, 10 Apr 2018 18:37:27 +0100 Subject: [PATCH] Added support for openSUSE 42.3 (#112) Using `zypper` package manager. --- .travis.yml | 6 ++++ README.md | 8 +++++ molecule/opensuse/Dockerfile.j2 | 9 ++++++ molecule/opensuse/INSTALL.rst | 16 ++++++++++ molecule/opensuse/molecule.yml | 31 +++++++++++++++++++ molecule/opensuse/tests/test_install.py | 10 ++++++ .../opensuse/tests/test_install_extensions.py | 17 ++++++++++ molecule/opensuse/tests/test_settings.py | 17 ++++++++++ tasks/install-zypper.yml | 21 +++++++++++++ tasks/install.yml | 5 ++- templates/vscode.repo.j2 | 8 +++++ 11 files changed, 147 insertions(+), 1 deletion(-) create mode 100644 molecule/opensuse/Dockerfile.j2 create mode 100644 molecule/opensuse/INSTALL.rst create mode 100644 molecule/opensuse/molecule.yml create mode 100644 molecule/opensuse/tests/test_install.py create mode 100644 molecule/opensuse/tests/test_install_extensions.py create mode 100644 molecule/opensuse/tests/test_settings.py create mode 100644 tasks/install-zypper.yml create mode 100644 templates/vscode.repo.j2 diff --git a/.travis.yml b/.travis.yml index 63e1642..3ead75c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,6 +15,9 @@ matrix: - env: - ANSIBLE_VERSION=2.3.3 - MOLECULE_SCENARIO=fedora + - env: + - ANSIBLE_VERSION=2.3.3 + - MOLECULE_SCENARIO=opensuse - env: - ANSIBLE_VERSION=2.4.4 - MOLECULE_SCENARIO=centos-7 @@ -24,6 +27,9 @@ matrix: - env: - ANSIBLE_VERSION=2.4.4 - MOLECULE_SCENARIO=fedora + - env: + - ANSIBLE_VERSION=2.4.4 + - MOLECULE_SCENARIO=opensuse # Require the standard build environment sudo: required diff --git a/README.md b/README.md index d289fd1..0cbe102 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,14 @@ Requirements * 27 + * SUSE + + * Leap + + * 42.3 + + * Note: other versions are likely to work but have not been tested. + Role Variables -------------- diff --git a/molecule/opensuse/Dockerfile.j2 b/molecule/opensuse/Dockerfile.j2 new file mode 100644 index 0000000..f8b4e75 --- /dev/null +++ b/molecule/opensuse/Dockerfile.j2 @@ -0,0 +1,9 @@ +# Molecule managed + +FROM {{ item.image }} + +RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get upgrade -y && 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 python2-dnf bash && dnf clean all; \ + elif [ $(command -v yum) ]; then yum makecache fast && yum update -y && 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 update -y && 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; fi diff --git a/molecule/opensuse/INSTALL.rst b/molecule/opensuse/INSTALL.rst new file mode 100644 index 0000000..e26493b --- /dev/null +++ b/molecule/opensuse/INSTALL.rst @@ -0,0 +1,16 @@ +******* +Install +******* + +Requirements +============ + +* Docker Engine +* docker-py + +Install +======= + +.. code-block:: bash + + $ sudo pip install docker-py diff --git a/molecule/opensuse/molecule.yml b/molecule/opensuse/molecule.yml new file mode 100644 index 0000000..34788be --- /dev/null +++ b/molecule/opensuse/molecule.yml @@ -0,0 +1,31 @@ +--- +dependency: + name: galaxy + +driver: + name: docker + +lint: + name: yamllint + +platforms: + - name: ansible-role-visual-studio-code-opensuse + image: opensuse:42.3 + +provisioner: + name: ansible + playbooks: + create: ../default/create.yml + destroy: ../default/destroy.yml + prepare: ../default/prepare.yml + converge: ../default/playbook.yml + lint: + name: ansible-lint + +scenario: + name: opensuse + +verifier: + name: testinfra + lint: + name: flake8 diff --git a/molecule/opensuse/tests/test_install.py b/molecule/opensuse/tests/test_install.py new file mode 100644 index 0000000..1c64c2b --- /dev/null +++ b/molecule/opensuse/tests/test_install.py @@ -0,0 +1,10 @@ +import os + +import testinfra.utils.ansible_runner + +testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( + os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') + + +def test_visual_studio_code(Command): + assert Command('which code').rc == 0 diff --git a/molecule/opensuse/tests/test_install_extensions.py b/molecule/opensuse/tests/test_install_extensions.py new file mode 100644 index 0000000..b32a0b0 --- /dev/null +++ b/molecule/opensuse/tests/test_install_extensions.py @@ -0,0 +1,17 @@ +import os +import pytest + +import testinfra.utils.ansible_runner + +testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( + os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') + + +@pytest.mark.parametrize('extension', [ + 'ms-python.python', + 'wholroyd.jinja' +]) +def test_visual_studio_code(Command, extension): + output = Command.check_output('sudo --user test_usr -H code %s %s', + '--install-extension', extension) + assert 'already installed' in output diff --git a/molecule/opensuse/tests/test_settings.py b/molecule/opensuse/tests/test_settings.py new file mode 100644 index 0000000..54a0511 --- /dev/null +++ b/molecule/opensuse/tests/test_settings.py @@ -0,0 +1,17 @@ +import os + +import testinfra.utils.ansible_runner + +testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( + os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') + + +def test_settings(File): + settings_file = File('/home/test_usr/.config/Code/User/settings.json') + + assert settings_file.exists + assert settings_file.is_file + assert settings_file.user == 'test_usr' + assert settings_file.group == 'users' + assert oct(settings_file.mode) == '0600' + assert settings_file.contains('"Vagrantfile": "ruby"') diff --git a/tasks/install-zypper.yml b/tasks/install-zypper.yml new file mode 100644 index 0000000..78ce523 --- /dev/null +++ b/tasks/install-zypper.yml @@ -0,0 +1,21 @@ +--- +- name: install key (zypper) + become: yes + rpm_key: + state: present + key: https://packages.microsoft.com/keys/microsoft.asc + +- name: write repo configuration (zypper) + become: yes + template: + src: vscode.repo.j2 + dest: '/etc/zypp/repos.d/vscode.repo' + mode: 'u=rw,go=' + owner: root + group: root + +- name: install VS Code (zypper) + become: yes + zypper: + name: "code{{ (visual_studio_code_version != '') | ternary('=' + visual_studio_code_version, '') }}" + state: present diff --git a/tasks/install.yml b/tasks/install.yml index 03524f4..ecc2cbe 100644 --- a/tasks/install.yml +++ b/tasks/install.yml @@ -2,7 +2,7 @@ - name: assert supported distribution assert: that: - - "ansible_pkg_mgr in ('apt', 'yum', 'dnf')" + - "ansible_pkg_mgr in ('apt', 'yum', 'dnf', 'zypper')" - include: install-apt.yml when: ansible_pkg_mgr == 'apt' @@ -12,3 +12,6 @@ - include: install-dnf.yml when: ansible_pkg_mgr == 'dnf' + +- include: install-zypper.yml + when: ansible_pkg_mgr == 'zypper' diff --git a/templates/vscode.repo.j2 b/templates/vscode.repo.j2 new file mode 100644 index 0000000..c70da0a --- /dev/null +++ b/templates/vscode.repo.j2 @@ -0,0 +1,8 @@ +{{ ansible_managed | comment }} +[code] +name=Visual Studio Code +baseurl=https://packages.microsoft.com/yumrepos/vscode +enabled=1 +type=rpm-md +gpgcheck=1 +gpgkey=https://packages.microsoft.com/keys/microsoft.asc