diff --git a/.ansible-lint b/.ansible-lint new file mode 100644 index 0000000..b04781e --- /dev/null +++ b/.ansible-lint @@ -0,0 +1,5 @@ +--- +warn_list: + - role-name + - name[play] + - name[casing] diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..d204d7b --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,79 @@ +--- +name: CI +'on': + pull_request: + push: + branches: + - master + schedule: + - cron: '30 1 * * 3' + +jobs: + + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - name: Check out the codebase + uses: actions/checkout@v3 + + - name: Set up Python 3 + uses: actions/setup-python@v4 + with: + python-version: '3.x' + + - name: Install test dependencies + run: | + pip install ansible-lint + ansible-galaxy install -r requirements.yml + + - name: Lint code + run: | + yamllint . + ansible-lint + + molecule: + name: Molecule + runs-on: ubuntu-latest + defaults: + run: + working-directory: "${{ github.repository }}" + needs: + - lint + strategy: + fail-fast: false + matrix: + include: + - distro: debian10 + ansible-version: '>=9, <10' + - distro: debian11 + - distro: debian12 + - distro: ubuntu1804 + ansible-version: '>=9, <10' + - distro: ubuntu2004 + - distro: ubuntu2204 + - distro: ubuntu2404 + + steps: + - name: Check out the codebase + uses: actions/checkout@v3 + with: + path: "${{ github.repository }}" + + - name: Set up Python 3 + uses: actions/setup-python@v4 + with: + python-version: '3.x' + + - name: Install test dependencies + run: | + pip install 'ansible${{ matrix.ansible-version }}' molecule-plugins[docker] docker + - name: Run Molecule tests + run: | + molecule test + env: + ANSIBLE_FORCE_COLOR: '1' + ANSIBLE_VERBOSITY: '2' + MOLECULE_DEBUG: '1' + MOLECULE_DISTRO: "${{ matrix.distro }}" + PY_COLORS: '1' diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..5cc5164 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,20 @@ +--- +name: Release +'on': + push: + tags: + - '*' + +jobs: + + release: + name: Release + runs-on: ubuntu-latest + steps: + - name: Check out the codebase + uses: actions/checkout@v3 + + - name: Publish to Galaxy + uses: robertdebock/galaxy-action@1.2.0 + with: + galaxy_api_key: ${{ secrets.GALAXY_API_KEY }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f74c83a --- /dev/null +++ b/.gitignore @@ -0,0 +1,30 @@ +# OS generated files # +###################### +.DS_Store +.DS_Store? +._* +.Spotlight-V100 +.Trashes +Icon? +ehthumbs.db +Thumbs.db + +# IDE files # +################# +/.settings +/.buildpath +/.project +/nbproject +*.komodoproject +*.kpf +/.idea + +# Vagrant files # +.virtualbox/ +.vagrant/ +vagrant_ansible_inventory_* +ansible.cfg + +# Other files # +############### +!empty diff --git a/.yamllint b/.yamllint new file mode 100644 index 0000000..894450c --- /dev/null +++ b/.yamllint @@ -0,0 +1,15 @@ +--- +extends: default + +rules: + braces: + max-spaces-inside: 1 + level: error + brackets: + max-spaces-inside: 1 + level: error + line-length: disable + truthy: disable + +ignore: | + .tox/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..6ebe0c4 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,23 @@ +FROM ubuntu:18.04 +MAINTAINER Mischa ter Smitten + +ENV LANG C.UTF-8 +ENV LC_ALL C.UTF-8 + +# python +RUN apt-get update && \ + DEBIAN_FRONTEND=noninteractive apt-get install -y python3-minimal python3-dev curl && \ + apt-get clean +RUN curl -sL https://bootstrap.pypa.io/pip/3.6/get-pip.py | python3 - +RUN rm -rf $HOME/.cache + +# ansible +RUN DEBIAN_FRONTEND=noninteractive apt-get install -y python3-apt && \ + apt-get clean +RUN pip3 install ansible==2.10.7 +RUN rm -rf $HOME/.cache + +# provision +COPY . /etc/ansible/roles/ansible-role +WORKDIR /etc/ansible/roles/ansible-role +RUN ansible-playbook -i tests/inventory tests/test.yml --connection=local diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..5708f35 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,19 @@ +Copyright (c) Oefenweb.nl + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..bc8c73d --- /dev/null +++ b/README.md @@ -0,0 +1,40 @@ +## spotify + +[![CI](https://github.com/Oefenweb/ansible-spotify/workflows/CI/badge.svg)](https://github.com/Oefenweb/ansible-spotify/actions?query=workflow%3ACI) +[![Ansible Galaxy](http://img.shields.io/badge/ansible--galaxy-spotify-blue.svg)](https://galaxy.ansible.com/Oefenweb/spotify/) + +Set up [Spotify](https://www.spotify.com) in Debian-like systems. + +#### Requirements + +* `software-properties-common` (will be installed) +* `dirmngr` (will be installed) + +#### Variables + +None + +## Dependencies + +None + +#### Example + +```yaml +--- +- hosts: all + roles: + - oefenweb.spotify +``` + +#### License + +MIT + +#### Author Information + +Mischa ter Smitten + +#### Feedback, bug-reports, requests, ... + +Are [welcome](https://github.com/Oefenweb/ansible-spotify/issues)! diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 0000000..e86d32d --- /dev/null +++ b/Vagrantfile @@ -0,0 +1,77 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby ts=2 sw=2 tw=0 et : + +role = File.basename(File.expand_path(File.dirname(__FILE__))) + +boxes = [ + { + :name => "ubuntu-1804", + :box => "bento/ubuntu-18.04", + :ip => '10.0.0.13', + :cpu => "50", + :ram => "384" + }, + { + :name => "ubuntu-2004", + :box => "bento/ubuntu-20.04", + :ip => '10.0.0.14', + :cpu => "50", + :ram => "512" + }, + { + :name => "ubuntu-2204", + :box => "bento/ubuntu-22.04", + :ip => '10.0.0.15', + :cpu => "50", + :ram => "512" + }, + { + :name => "ubuntu-2404", + :box => "bento/ubuntu-24.04", + :ip => '10.0.0.16', + :cpu => "50", + :ram => "512" + }, + { + :name => "debian-10", + :box => "bento/debian-10", + :ip => '10.0.0.18', + :cpu => "50", + :ram => "256" + }, + { + :name => "debian-11", + :box => "bento/debian-11", + :ip => '10.0.0.19', + :cpu => "50", + :ram => "256" + }, + { + :name => "debian-12", + :box => "bento/debian-12", + :ip => '10.0.0.20', + :cpu => "50", + :ram => "384" + }, +] + +Vagrant.configure("2") do |config| + boxes.each do |box| + config.vm.define box[:name] do |vms| + vms.vm.box = box[:box] + vms.vm.hostname = "ansible-#{role}-#{box[:name]}" + + vms.vm.provider "virtualbox" do |v| + v.customize ["modifyvm", :id, "--cpuexecutioncap", box[:cpu]] + v.customize ["modifyvm", :id, "--memory", box[:ram]] + end + + vms.vm.network :private_network, ip: box[:ip] + + vms.vm.provision :ansible do |ansible| + ansible.playbook = "tests/vagrant.yml" + ansible.verbose = "vv" + end + end + end +end diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..d3c5414 --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,2 @@ +# defaults file +--- diff --git a/files/empty b/files/empty new file mode 100644 index 0000000..e69de29 diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..43d6a9a --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,2 @@ +# handlers file +--- diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..8a3d94b --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,27 @@ +# meta file +--- +galaxy_info: + author: oefenweb + role_name: spotify + company: Oefenweb.nl B.V. + description: Set up Insync in Debian-like systems + license: MIT + min_ansible_version: 2.10.0 + platforms: + - name: Ubuntu + versions: + - bionic + - focal + - jammy + - noble + - name: Debian + versions: + - buster + - bullseye + - bookworm + galaxy_tags: + - development + - system + - networking + - sync +dependencies: [] diff --git a/molecule/default/collections.yml b/molecule/default/collections.yml new file mode 100644 index 0000000..1062b36 --- /dev/null +++ b/molecule/default/collections.yml @@ -0,0 +1,2 @@ +--- +collections: [] diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml new file mode 100644 index 0000000..be762b2 --- /dev/null +++ b/molecule/default/converge.yml @@ -0,0 +1,6 @@ +--- +- name: Converge + hosts: all + become: true + roles: + - ../../../ diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml new file mode 100644 index 0000000..908aaf6 --- /dev/null +++ b/molecule/default/molecule.yml @@ -0,0 +1,21 @@ +--- +dependency: + name: galaxy +driver: + name: docker +platforms: + - name: instance + image: "geerlingguy/docker-${MOLECULE_DISTRO:-ubuntu2004}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + - /var/lib/containerd + cgroupns_mode: host + privileged: true + pre_build_image: true +provisioner: + name: ansible + playbooks: + prepare: prepare.yml + converge: converge.yml + verify: verify.yml diff --git a/molecule/default/prepare.yml b/molecule/default/prepare.yml new file mode 100644 index 0000000..9a6673d --- /dev/null +++ b/molecule/default/prepare.yml @@ -0,0 +1,5 @@ +--- +- name: Prepare + hosts: all + become: true + tasks: [] diff --git a/molecule/default/verify.yml b/molecule/default/verify.yml new file mode 100644 index 0000000..44debad --- /dev/null +++ b/molecule/default/verify.yml @@ -0,0 +1,5 @@ +--- +- name: Verify + hosts: all + become: true + tasks: [] diff --git a/requirements.yml b/requirements.yml new file mode 100644 index 0000000..3d5f1cd --- /dev/null +++ b/requirements.yml @@ -0,0 +1,3 @@ +# requirements file +--- +collections: [] diff --git a/tasks/install.yml b/tasks/install.yml new file mode 100644 index 0000000..220b250 --- /dev/null +++ b/tasks/install.yml @@ -0,0 +1,19 @@ +# tasks file +--- +- name: ensure update-notifier directory + ansible.builtin.file: + path: /var/lib/update-notifier/user.d + state: directory + recurse: true + when: + - ansible_distribution == 'Ubuntu' + - ansible_distribution_major_version is version('20', '>=') + tags: + - spotify-install-dependencies + +- name: install | dependencies + ansible.builtin.apt: + name: "{{ spotify_dependencies }}" + state: "{{ apt_install_state | default('latest') }}" + tags: + - spotify-install-dependencies diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..c7a435f --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,15 @@ +# tasks file +--- +- name: repository + ansible.builtin.import_tasks: repository.yml + tags: + - configuration + - spotify + - spotify-repository + +- name: install + ansible.builtin.import_tasks: install.yml + tags: + - configuration + - spotify + - spotify-install diff --git a/tasks/repository.yml b/tasks/repository.yml new file mode 100644 index 0000000..d15d482 --- /dev/null +++ b/tasks/repository.yml @@ -0,0 +1,39 @@ +# tasks file +--- +- name: repository | install dependencies (pre) + ansible.builtin.apt: + name: "{{ spotify_dependencies_pre }}" + state: "{{ apt_install_state | default('latest') }}" + update_cache: true + cache_valid_time: "{{ apt_update_cache_valid_time | default(3600) }}" + tags: + - spotify-repository-install-dependencies + +- name: repository | (keyrings) directory | create + ansible.builtin.file: + path: "{{ spotify_keyring_dst | dirname }}" + state: directory + owner: root + group: root + mode: '0755' + tags: + - spotify-repository-keyrings-directory-create + +- name: repository | (keyring) file | download + ansible.builtin.apt_key: + id: "{{ spotify_keyring_id }}" + keyserver: "{{ apt_key_keyserver | default('keyserver.ubuntu.com') }}" + keyring: "{{ spotify_keyring_dst }}" + state: present + tags: + - spotify-repository-keyring-file-download + +- name: repository | add + ansible.builtin.apt_repository: + repo: "{{ item.type }} {{ item.url }} {{ item.component }}" + state: "{{ item.state | default('present') }}" + update_cache: true + mode: '0644' + with_items: "{{ spotify_repositories }}" + tags: + - spotify-repository-add diff --git a/templates/empty b/templates/empty new file mode 100644 index 0000000..e69de29 diff --git a/tests/inventory b/tests/inventory new file mode 100644 index 0000000..2fbb50c --- /dev/null +++ b/tests/inventory @@ -0,0 +1 @@ +localhost diff --git a/tests/test.yml b/tests/test.yml new file mode 100644 index 0000000..6ca55c7 --- /dev/null +++ b/tests/test.yml @@ -0,0 +1,8 @@ +# test file +--- +- name: converge + hosts: localhost + connection: local + become: true + roles: + - ../../ diff --git a/tests/vagrant.yml b/tests/vagrant.yml new file mode 100644 index 0000000..c51aabf --- /dev/null +++ b/tests/vagrant.yml @@ -0,0 +1,8 @@ +# test file +--- +- name: converge + hosts: all + remote_user: vagrant + become: true + roles: + - ../../ diff --git a/vars/main.yml b/vars/main.yml new file mode 100644 index 0000000..358bad3 --- /dev/null +++ b/vars/main.yml @@ -0,0 +1,15 @@ +# vars file +--- +spotify_keyring_id: 6224F9941A8AA6D1 +spotify_keyring_dst: /usr/share/keyrings/spotify.gpg +spotify_repositories: + - type: "deb [signed-by={{ spotify_keyring_dst }}]" + url: http://repository.spotify.com stable' + component: 'non-free' + +spotify_dependencies_pre: + - software-properties-common + - dirmngr + +spotify_dependencies: + - spotify