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 b/LICENSE.txt similarity index 86% rename from LICENSE rename to LICENSE.txt index 291cca2..5708f35 100644 --- a/LICENSE +++ b/LICENSE.txt @@ -1,13 +1,11 @@ -MIT License - -Copyright (c) 2025 Oefenweb.nl +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: +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. @@ -17,5 +15,5 @@ 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. +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 index 0603fa8..ce5671e 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,47 @@ -# ansible-msodbcsql -Ansible role to set up msodbcsql in Debian-like systems +## msodbcsql + +[![CI](https://github.com/Oefenweb/ansible-msodbcsql/workflows/CI/badge.svg)](https://github.com/Oefenweb/ansible-msodbcsql/actions?query=workflow%3ACI) +[![Ansible Galaxy](http://img.shields.io/badge/ansible--galaxy-msodbcsql-blue.svg)](https://galaxy.ansible.com/Oefenweb/msodbcsql) + +Set up [Microsoft ODBC](https://learn.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server) in Debian-like systems. + +#### Requirements + +* `software-properties-common` (will be installed) +* `dirmngr` (will be installed) +* `apt-transport-https` (will be installed) +* `wget` (will be installed) + +#### Variables + +* `msodbcsql_version`: [default: `18`]: Version to install (e.g. `17`) +* `msodbcsql_install`: [default: `[]`]: Additional packages to install (e.g. `mssql-tools`) + +## Dependencies + +None + +## Recommended + +None + +#### Example + +```yaml +--- +- hosts: all + roles: + - oefenweb.msodbcsql +``` + +#### License + +MIT + +#### Author Information + +Mischa ter Smitten + +#### Feedback, bug-reports, requests, ... + +Are [welcome](https://github.com/Oefenweb/ansible-msodbcsql/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 100755 index 0000000..b462d3f --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,4 @@ +# defaults file +--- +msodbcsql_version: 18 +msodbcsql_install: [] 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..a05c6bd --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,29 @@ +# meta file +--- +galaxy_info: + author: oefenweb + role_name: msodbcsql + company: Oefenweb.nl B.V. + description: Set up Microsoft ODBC 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 + - database + - sql + - r + - cran +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..481725e --- /dev/null +++ b/tasks/install.yml @@ -0,0 +1,23 @@ +# tasks file +--- +- name: install | configure debconf + ansible.builtin.debconf: + name: "{{ item.name }}" + question: "{{ item.question }}" + value: "{{ item.value }}" + vtype: "{{ item.vtype }}" + with_items: "{{ msodbcsql_debconf_selections }}" + +- name: install | dependencies + ansible.builtin.apt: + name: "{{ msodbcsql_dependencies }}" + state: "{{ apt_install_state | default('latest') }}" + tags: + - msodbcsql-install-dependencies + +- name: install | additional + ansible.builtin.apt: + name: "{{ msodbcsql_install }}" + state: "{{ apt_install_state | default('latest') }}" + tags: + - msodbcsql-install-additional diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..9bebb07 --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,32 @@ +# tasks file +--- +- name: include variables + ansible.builtin.include_vars: "{{ item }}" + with_first_found: + - "_{{ ansible_distribution_release }}.yml" + - "_{{ ansible_distribution | lower }}.yml" + - _default.yml + tags: + - configuration + - msodbcsql + +- name: version support + ansible.builtin.import_tasks: version-support.yml + tags: + - configuration + - msodbcsql + - msodbcsql-version-support + +- name: repository + ansible.builtin.import_tasks: repository.yml + tags: + - configuration + - msodbcsql + - msodbcsql-repository + +- name: install + ansible.builtin.import_tasks: install.yml + tags: + - configuration + - msodbcsql + - msodbcsql-install diff --git a/tasks/repository.yml b/tasks/repository.yml new file mode 100644 index 0000000..c496ff8 --- /dev/null +++ b/tasks/repository.yml @@ -0,0 +1,38 @@ +# tasks file +--- +- name: repository | install dependencies (pre) + ansible.builtin.apt: + name: "{{ msodbcsql_dependencies_pre }}" + state: "{{ apt_install_state | default('latest') }}" + update_cache: true + cache_valid_time: "{{ apt_update_cache_valid_time | default(3600) }}" + tags: + - msodbcsql-repository-install-dependencies + +- name: repository | (keyrings) directory | create + ansible.builtin.file: + path: "{{ msodbcsql_keyring_dst | dirname }}" + state: directory + owner: root + group: root + mode: '0755' + tags: + - msodbcsql-repository-keyrings-directory-create + +- name: repository | (keyring) file | download # noqa command-instead-of-module risky-shell-pipe + ansible.builtin.shell: > + wget -O- {{ msodbcsql_keyring_src }} | gpg --dearmor --yes --output {{ msodbcsql_keyring_dst }} + args: + creates: "{{ msodbcsql_keyring_dst }}" + tags: + - msodbcsql-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: "{{ msodbcsql_repositories }}" + tags: + - msodbcsql-repository-add diff --git a/tasks/version-support.yml b/tasks/version-support.yml new file mode 100644 index 0000000..7ae8a17 --- /dev/null +++ b/tasks/version-support.yml @@ -0,0 +1,8 @@ +# tasks file +--- +- name: version support | check + ansible.builtin.fail: + msg: "Microsoft ODBC version {{ msodbcsql_version }} is not supported" + when: msodbcsql_version | string not in msodbcsql_versions_supported + tags: + - msodbcsql-version-support-check 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/_default.yml b/vars/_default.yml new file mode 100644 index 0000000..7a5d904 --- /dev/null +++ b/vars/_default.yml @@ -0,0 +1,6 @@ +# vars file +--- +msodbcsql_repositories: + - type: "deb [arch=amd64 signed-by={{ msodbcsql_keyring_dst }}]" + url: "https://packages.microsoft.com/{{ ansible_distribution | lower }}/{{ ansible_distribution_major_version }}/prod {{ ansible_distribution_release }}" + component: main diff --git a/vars/_ubuntu.yml b/vars/_ubuntu.yml new file mode 100644 index 0000000..dc0534f --- /dev/null +++ b/vars/_ubuntu.yml @@ -0,0 +1,6 @@ +# vars file +--- +msodbcsql_repositories: + - type: "deb [arch=amd64 signed-by={{ msodbcsql_keyring_dst }}]" + url: "https://packages.microsoft.com/{{ ansible_distribution | lower }}/{{ ansible_distribution_version }}/prod {{ ansible_distribution_release }}" + component: main diff --git a/vars/main.yml b/vars/main.yml new file mode 100644 index 0000000..a50b0c8 --- /dev/null +++ b/vars/main.yml @@ -0,0 +1,23 @@ +# vars file +--- +msodbcsql_versions_supported: + - '17' + - '18' + +msodbcsql_keyring_src: https://packages.microsoft.com/keys/microsoft.asc +msodbcsql_keyring_dst: /usr/share/keyrings/microsoft-prod.gpg + +msodbcsql_dependencies_pre: + - software-properties-common + - dirmngr + - apt-transport-https + - wget + +msodbcsql_debconf_selections: + - name: "msodbcsql{{ msodbcsql_version }}" + question: msodbcsql/ACCEPT_EULA + value: true + vtype: boolean + +msodbcsql_dependencies: + - "msodbcsql{{ msodbcsql_version }}"