diff --git a/.ansible-lint b/.ansible-lint new file mode 100644 index 0000000..43cae14 --- /dev/null +++ b/.ansible-lint @@ -0,0 +1,9 @@ +--- +profile: production +strict: true + +# Enable checking of loop variable prefixes in roles +loop_var_prefix: "^(__|{role}_)" + +exclude_paths: + - .github/ diff --git a/.github/workflows/kics.yml b/.github/workflows/kics.yml new file mode 100644 index 0000000..4135c16 --- /dev/null +++ b/.github/workflows/kics.yml @@ -0,0 +1,22 @@ +--- +name: kics + +on: + pull_request: + branches: ["master"] + +jobs: + kics: + runs-on: ubuntu-latest + timeout-minutes: 5 + + steps: + - uses: actions/checkout@v5 + name: Check out source code + + - name: run a KICS scan + uses: checkmarx/kics-github-action@e01759d524f8abd5bd650d3d5bd4b96d46ebbc1d + with: + path: . + token: ${{ secrets.GITHUB_TOKEN }} + output_path: myResults/ diff --git a/.github/workflows/linters.yml b/.github/workflows/linters.yml new file mode 100644 index 0000000..03c44ab --- /dev/null +++ b/.github/workflows/linters.yml @@ -0,0 +1,46 @@ +--- +name: linters + +on: + pull_request: + branches: [ "master" ] + push: + branches: [ "master" ] + +jobs: + + ansible-lint: + runs-on: ubuntu-latest + timeout-minutes: 5 + + steps: + - uses: actions/checkout@v5 + + + - uses: mamba-org/setup-micromamba@7f29b8b80078b1b601dfa018b0f7425c587c63bb + with: + micromamba-version: '2.4.0-0' + environment-file: ci/conda.yml + init-shell: bash + post-cleanup: 'all' + cache-environment: true + + # - name: "Install role dependencies" + # run: ansible-galaxy install -r requirements.yml + # shell: micromamba-shell {0} + + - name: Check workflow files themselves with ActionLint + run: actionlint + shell: micromamba-shell {0} + + - name: Check environment files with YAMLLint + run: yamllint ci/*.yml + shell: micromamba-shell {0} + + - name: "Install collection dependencies" + run: ansible-galaxy install -r requirements.yml + shell: micromamba-shell {0} + + - name: Run ansible-lint + run: ansible-lint -c .ansible-lint + shell: micromamba-shell {0} diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..6361e43 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,3 @@ +# Changelog + +All notable changes to this project will be documented in this file. diff --git a/README.md b/README.md index 52eca89..dc6784a 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ # Ansible Collection - genlab.common +[![linters](https://github.com/corvus-migratorius/genlab.common/actions/workflows/linters.yml/badge.svg)](https://github.com/corvus-migratorius/genlab.common/actions/workflows/linters.yml) +[![kics](https://github.com/corvus-migratorius/genlab.common/actions/workflows/kics.yml/badge.svg)](https://github.com/corvus-migratorius/genlab.common/actions/workflows/kics.yml) + ## Roles - [mount_device](roles/mount_device/README.md) diff --git a/ci/conda.yml b/ci/conda.yml new file mode 100644 index 0000000..68df58c --- /dev/null +++ b/ci/conda.yml @@ -0,0 +1,11 @@ +--- +name: genlab.common +channels: + - conda-forge +dependencies: + - python~=3.13.10 + - pip==25.3 + - actionlint + - pip: + - -r requirements.txt + - -r requirements.ci.txt diff --git a/ci/requirements.ci.txt b/ci/requirements.ci.txt new file mode 100644 index 0000000..f99c76a --- /dev/null +++ b/ci/requirements.ci.txt @@ -0,0 +1,6 @@ +ansible-lint +molecule==24.12.0 +molecule-plugins[docker] +docker~=7.1.0 +requests==2.31.0 # pinned to the latest version not breaking Docker SDK +yamllint diff --git a/ci/requirements.txt b/ci/requirements.txt new file mode 100644 index 0000000..456b2b7 --- /dev/null +++ b/ci/requirements.txt @@ -0,0 +1 @@ +ansible-core==2.18.11 diff --git a/galaxy.yml b/galaxy.yml index 9e284de..66c7b7e 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -9,6 +9,8 @@ description: >- The genlab.common collection includes roles for performing deploying and configuring common infrastructural components license_file: LICENSE tags: + - linux + - infrastructure - genlab repository: https://github.com/corvus-migratorius/genlab.common issues: https://github.com/corvus-migratorius/genlab.common/issues diff --git a/renovate.json b/renovate.json new file mode 100644 index 0000000..5db72dd --- /dev/null +++ b/renovate.json @@ -0,0 +1,6 @@ +{ + "$schema": "https://docs.renovatebot.com/renovate-schema.json", + "extends": [ + "config:recommended" + ] +} diff --git a/requirements.yml b/requirements.yml new file mode 100644 index 0000000..a0cd255 --- /dev/null +++ b/requirements.yml @@ -0,0 +1,3 @@ +--- +collections: + - name: ansible.posix diff --git a/roles/mount_device/meta/main.yml b/roles/mount_device/meta/main.yml index 5b34d77..b6eded3 100644 --- a/roles/mount_device/meta/main.yml +++ b/roles/mount_device/meta/main.yml @@ -10,7 +10,7 @@ galaxy_info: platforms: - name: "Ubuntu" - versions: [ "focal", "jammy", "noble" ] + versions: ["jammy", "noble"] galaxy_tags: [] diff --git a/roles/mount_device/molecule/default/converge.yml b/roles/mount_device/molecule/default/converge.yml index af31c05..abb2a3b 100644 --- a/roles/mount_device/molecule/default/converge.yml +++ b/roles/mount_device/molecule/default/converge.yml @@ -5,19 +5,19 @@ pre_tasks: - name: "Check if the disk file already exists" + register: mount_device_disk_file ansible.builtin.stat: path: /tmp/test_file - register: disk_file - name: "Create a file to act as a disk if it doesn't exist" - when: not disk_file.stat.exists + when: not mount_device_disk_file.stat.exists changed_when: false ansible.builtin.shell: | dd if=/dev/zero of=/tmp/test_file bs=1000000 count=100 mkfs.ext3 /tmp/test_file roles: - - role: genlab.mount_device + - role: genlab.common.mount_device devices: - what: "/tmp/test_file" where: "/test_mount" diff --git a/roles/mount_device/molecule/default/verify.yml b/roles/mount_device/molecule/default/verify.yml index 3538604..ea6fda8 100644 --- a/roles/mount_device/molecule/default/verify.yml +++ b/roles/mount_device/molecule/default/verify.yml @@ -7,12 +7,12 @@ tasks: - name: "Check mountpoint" # noqa: command-instead-of-module changed_when: false - register: mounts + register: mount_device_mounts ansible.builtin.command: cmd: mount -l - name: "Ensure test_file is mounted on test_mount" ansible.builtin.assert: - that: "'/tmp/test_file on /test_mount type ext3' in mounts.stdout" + that: "'/tmp/test_file on /test_mount type ext3' in mount_device_mounts.stdout" success_msg: "/test_mount is a mounted" fail_msg: "/test_mount is not on the list of mounts"