diff --git a/.github/workflows/galaxy.yml b/.github/workflows/galaxy.yml new file mode 100644 index 0000000..6ccf841 --- /dev/null +++ b/.github/workflows/galaxy.yml @@ -0,0 +1,17 @@ +--- + +name: Deploy on Ansible Galaxy + +'on': + - push + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v2 + - name: galaxy + uses: robertdebock/galaxy-action@1.2.0 + with: + galaxy_api_key: ${{ secrets.galaxy_api_key }} diff --git a/.github/workflows/molecule.yml b/.github/workflows/molecule.yml new file mode 100644 index 0000000..eaff792 --- /dev/null +++ b/.github/workflows/molecule.yml @@ -0,0 +1,35 @@ +--- +name: Molecule + +'on': + pull_request: + push: + branches: + - master + +jobs: + build: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + scenario: + - debian-10 + - debian-11 + - debian-12 + - ubuntu-18.04 + - ubuntu-20.04 + - ubuntu-22.04 + + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + path: "${{ github.repository }}" + + - name: Molecule + uses: gofrolist/molecule-action@v2.3.19 + with: + molecule_options: --base-config molecule/_shared/base.yml + molecule_args: --scenario-name ${{ matrix.scenario }} + molecule_working_dir: "HanXHX/ansible-debian-bootstrap" diff --git a/.gitignore b/.gitignore index 4646d22..515943d 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ *.swp *.retry /ubuntu*.log +/.idea diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index dc808ac..0000000 --- a/.travis.yml +++ /dev/null @@ -1,60 +0,0 @@ ---- - -env: - global: - - VAGRANT_VERSION='2.2.18' - jobs: - - PLATFORM='docker-debian-stretch' ANSIBLE_VERSION='>=2.11,<2.12' - - PLATFORM='docker-debian-bullseye' ANSIBLE_VERSION='>=2.11,<2.12' - - PLATFORM='docker-debian-buster' ANSIBLE_VERSION='>=2.11,<2.12' - - PLATFORM='docker-ubuntu-bionic' ANSIBLE_VERSION='>=2.11,<2.12' - - PLATFORM='docker-ubuntu-focal' ANSIBLE_VERSION='>=2.11,<2.12' - - PLATFORM='docker-ubuntu-jammy' ANSIBLE_VERSION='>=2.11,<2.12' - -jobs: - allow_failures: - - env: PLATFORM='docker-ubuntu-bionic' ANSIBLE_VERSION='>=2.11,<2.12' - - env: PLATFORM='docker-ubuntu-focal' ANSIBLE_VERSION='>=2.11,<2.12' - - env: PLATFORM='docker-ubuntu-jammy' ANSIBLE_VERSION='>=2.11,<2.12' - -os: - - linux -dist: focal - -language: python -python: - - 3.8 - -services: - - docker - -before_install: - - sudo apt-get -q update - - sudo apt-get install -y yamllint - - sudo wget -nv https://releases.hashicorp.com/vagrant/${VAGRANT_VERSION}/vagrant_${VAGRANT_VERSION}_x86_64.deb - - sudo dpkg -i vagrant_${VAGRANT_VERSION}_x86_64.deb - -install: - - sudo pip install "ansible-core$ANSIBLE_VERSION" - - sudo pip install ansible-lint - - ansible-galaxy collection install ansible.posix community.general - -script: - - VAGRANT_DEFAULT_PROVIDER=docker vagrant up $PLATFORM - - > - VAGRANT_DEFAULT_PROVIDER=docker vagrant provision $PLATFORM - | grep -q 'changed=0.*failed=0' - && (echo 'Idempotence test: pass' && exit 0) - || (echo 'Idempotence test: fail' && exit 1) - - VAGRANT_DEFAULT_PROVIDER=docker vagrant status - - > - yamllint . - && (echo 'YAML lint test: pass' && exit 0) - || (echo 'YAML lint test: fail' && exit 1) - - > - ansible-lint -v tests/test.yml - && (echo 'Ansible lint test: pass' && exit 0) - || (echo 'Ansible lint test: fail' && exit 1) - -notifications: - webhooks: https://galaxy.ansible.com/api/v1/notifications/ diff --git a/README.md b/README.md index 989ef10..6bd3b5e 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ Ansible Debian/Devuan/Ubuntu/Raspbian bootstrap ==================================================== -[![Ansible Galaxy](http://img.shields.io/badge/ansible--galaxy-HanXHX.debian_bootstrap-blue.svg)](https://galaxy.ansible.com/HanXHX/debian_bootstrap) [![Build Status](https://app.travis-ci.com/HanXHX/ansible-debian-bootstrap.svg?branch=master)](https://app.travis-ci.com/HanXHX/ansible-debian-bootstrap) +[![Ansible Galaxy](http://img.shields.io/badge/ansible--galaxy-HanXHX.debian_bootstrap-blue.svg)](https://galaxy.ansible.com/HanXHX/debian_bootstrap) ![GitHub Workflow Status (with branch)](https://img.shields.io/github/actions/workflow/status/hanxhx/ansible-debian-bootstrap/molecule.yml?branch=master) This role bootstraps Debian/Devuan/Ubuntu/Raspbian hosts: @@ -152,6 +152,34 @@ Due to Docker limitations, theses features are disabled: - Setting hostname - Configure sysctl + +How to develop and test this role +--------------------------------- + +### Vagrant way + +Install vagrant + virtualbox or docker + +```commandline +vagrant up debian-bullseye # with virtualbox +vagrant up docker-debian-bullseye # with docker +``` + +### Molecule way + +Install: + +```commandline +pip install molecule molecule[docker] +``` + +Run: + +```commandline +molecule -vv -c molecule/_shared/base.yml converge -s ubuntu-22.04 +``` + + License ------- diff --git a/molecule/_shared/Dockerfile.j2 b/molecule/_shared/Dockerfile.j2 new file mode 100644 index 0000000..ca98098 --- /dev/null +++ b/molecule/_shared/Dockerfile.j2 @@ -0,0 +1,19 @@ +# Molecule managed + +{% if item.registry is defined %} +FROM {{ item.registry.url }}/{{ item.image }} +{% else %} +FROM {{ item.image }} +{% endif %} + +{% if item.env is defined %} +{% for var, value in item.env.items() %} +{% if value %} +ENV {{ var }} {{ value }} +{% endif %} +{% endfor %} +{% endif %} + +RUN apt-get update && \ + apt-get install -y python3 sudo bash ca-certificates iproute2 python-apt-common \ + && apt-get clean \ No newline at end of file diff --git a/molecule/_shared/base.yml b/molecule/_shared/base.yml new file mode 100644 index 0000000..b466ed4 --- /dev/null +++ b/molecule/_shared/base.yml @@ -0,0 +1,37 @@ +--- + +scenario: + test_sequence: + - dependency + - syntax + - create + - prepare + - converge + - idempotence + - verify + - destroy +dependency: + name: galaxy + options: + requirements-file: ../../requirements.yml +driver: + name: docker +role_name_check: 1 +provisioner: + name: ansible + config_options: + defaults: + deprecation_warnings: false + callback_whitelist: timer,profile_tasks + fact_caching: jsonfile + fact_caching_connection: ./cache + forks: 100 + connection: + pipelining: true + playbooks: + converge: ../_shared/converge.yml + +# TODO: Add this back in when we have a testinfra verifier +# verifier: +# name: testinfra +# directory: ../_shared/tests diff --git a/molecule/_shared/converge.yml b/molecule/_shared/converge.yml new file mode 100644 index 0000000..84f20fa --- /dev/null +++ b/molecule/_shared/converge.yml @@ -0,0 +1,12 @@ +--- + +- name: Converge + hosts: all + gather_facts: true + tasks: + - name: Include role + ansible.builtin.include_role: + name: "hanxhx.debian_bootstrap" + vars: + # Force SysVinit, since systemd won't work in a Docker container + ansible_service_mgr: "sysvinit" diff --git a/molecule/debian-10/molecule.yml b/molecule/debian-10/molecule.yml new file mode 100644 index 0000000..0308383 --- /dev/null +++ b/molecule/debian-10/molecule.yml @@ -0,0 +1,13 @@ +--- + +platforms: + - name: debian-10 + image: dokken/debian-10 + command: /lib/systemd/systemd + dockerfile: ../_shared/Dockerfile.j2 + capabilities: + - SYS_ADMIN + cgroupns_mode: host + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + privileged: true diff --git a/molecule/debian-11/molecule.yml b/molecule/debian-11/molecule.yml new file mode 100644 index 0000000..a9d5a5f --- /dev/null +++ b/molecule/debian-11/molecule.yml @@ -0,0 +1,13 @@ +--- + +platforms: + - name: debian-11 + image: dokken/debian-11 + command: /lib/systemd/systemd + dockerfile: ../_shared/Dockerfile.j2 + capabilities: + - SYS_ADMIN + cgroupns_mode: host + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + privileged: true diff --git a/molecule/debian-12/molecule.yml b/molecule/debian-12/molecule.yml new file mode 100644 index 0000000..6d4e51f --- /dev/null +++ b/molecule/debian-12/molecule.yml @@ -0,0 +1,13 @@ +--- + +platforms: + - name: debian-12 + image: dokken/debian-12 + command: /lib/systemd/systemd + dockerfile: ../_shared/Dockerfile.j2 + capabilities: + - SYS_ADMIN + cgroupns_mode: host + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + privileged: true diff --git a/molecule/default/.gitkeep b/molecule/default/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/molecule/ubuntu-18.04/molecule.yml b/molecule/ubuntu-18.04/molecule.yml new file mode 100644 index 0000000..7a55da6 --- /dev/null +++ b/molecule/ubuntu-18.04/molecule.yml @@ -0,0 +1,13 @@ +--- + +platforms: + - name: ubuntu-18.04 + image: dokken/ubuntu-18.04 + command: /lib/systemd/systemd + dockerfile: ../_shared/Dockerfile.j2 + capabilities: + - SYS_ADMIN + cgroupns_mode: host + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + privileged: true diff --git a/molecule/ubuntu-20.04/molecule.yml b/molecule/ubuntu-20.04/molecule.yml new file mode 100644 index 0000000..d889c6a --- /dev/null +++ b/molecule/ubuntu-20.04/molecule.yml @@ -0,0 +1,13 @@ +--- + +platforms: + - name: ubuntu-20.04 + image: dokken/ubuntu-20.04 + command: /lib/systemd/systemd + dockerfile: ../_shared/Dockerfile.j2 + capabilities: + - SYS_ADMIN + cgroupns_mode: host + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + privileged: true diff --git a/molecule/ubuntu-22.04/molecule.yml b/molecule/ubuntu-22.04/molecule.yml new file mode 100644 index 0000000..d820e55 --- /dev/null +++ b/molecule/ubuntu-22.04/molecule.yml @@ -0,0 +1,13 @@ +--- + +platforms: + - name: ubuntu-22.04 + image: dokken/ubuntu-22.04 + command: /lib/systemd/systemd + dockerfile: ../_shared/Dockerfile.j2 + capabilities: + - SYS_ADMIN + cgroupns_mode: host + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + privileged: true diff --git a/requirements.yml b/requirements.yml index f212a67..9c08140 100644 --- a/requirements.yml +++ b/requirements.yml @@ -2,3 +2,4 @@ collections: - community.general + - ansible.posix