diff --git a/.gitea/workflows/test.yml b/.gitea/workflows/test.yml new file mode 100644 index 0000000..fd684f6 --- /dev/null +++ b/.gitea/workflows/test.yml @@ -0,0 +1,52 @@ +--- +name: test +on: [push] + +jobs: + lint: + name: Linting + runs-on: ubuntu-latest + container: + image: git.ednz.fr/container-factory/ansible-runner:act-latest + credentials: + username: ${{ secrets.ACTIONS_USER }} + password: ${{ secrets.ACTIONS_TOKEN }} + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: "Ansible lint" + run: ansible-lint --force-color + working-directory: ${{ gitea.workspace }} + + - name: "YAML lint" + run: yamllint . -f colored -c .yamllint + working-directory: ${{ gitea.workspace }} + + molecule-test: + name: Molecule tests + runs-on: ubuntu-latest + needs: lint + container: + image: git.ednz.fr/container-factory/ansible-runner:act-latest + credentials: + username: ${{ secrets.ACTIONS_USER }} + password: ${{ secrets.ACTIONS_TOKEN }} + strategy: + matrix: + test_os: [debian11, debian12, ubuntu2004, ubuntu2204] + scenario: [default, with_custom_packages] + env: + ANSIBLE_HOST_KEY_CHECKING: 'false' + ANSIBLE_FORCE_COLOR: 'true' + ANSIBLE_PYTHON_INTERPRETER: /usr/bin/python3 + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: "Molecule test" + run: molecule test -s ${{ matrix.scenario }} + shell: bash + working-directory: ${{ gitea.workspace }} + env: + MOLECULE_TEST_OS: ${{ matrix.test_os }} diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index dd61f31..0000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -1,82 +0,0 @@ ---- -stages: - - verify - - test-default - - test-with-custom-packages - -image: - name: registry.ednz.fr/forge/ansible-runner - -variables: - ANSIBLE_HOST_KEY_CHECKING: 'false' - ANSIBLE_FORCE_COLOR: 'true' - ANSIBLE_PYTHON_INTERPRETER: /usr/bin/python3 - DOCKER_AUTH_CONFIG: $CI_DOCKER_AUTH_CONFIG - -.stage-test-default: - stage: test-default - -.stage-test-with-custom-packages: - stage: test-with-custom-packages - -.variables-ubuntu-2004: - variables: - MOLECULE_TEST_OS: "ubuntu2004" - -.variables-ubuntu-2204: - variables: - MOLECULE_TEST_OS: "ubuntu2204" - -.variables-debian-11: - variables: - MOLECULE_TEST_OS: "debian11" - -.script-molecule-test-default: - script: - - molecule test - -.script-molecule-test-with-custom-packages: - script: - - molecule test -s with_custom_packages - -ansible-verify: - stage: verify - script: - - yamllint . -c .yamllint - - ansible-lint - -ansible-test-ubuntu-2004-default: - extends: - - .stage-test-default - - .variables-ubuntu-2004 - - .script-molecule-test-default - -ansible-test-ubuntu-2204-default: - extends: - - .stage-test-default - - .variables-ubuntu-2204 - - .script-molecule-test-default - -ansible-test-debian-11-default: - extends: - - .stage-test-default - - .variables-debian-11 - - .script-molecule-test-default - -ansible-test-ubuntu-2004-with-custom-packages: - extends: - - .stage-test-with-custom-packages - - .variables-ubuntu-2004 - - .script-molecule-test-with-custom-packages - -ansible-test-ubuntu-2204-with-custom-packages: - extends: - - .stage-test-with-custom-packages - - .variables-ubuntu-2204 - - .script-molecule-test-with-custom-packages - -ansible-test-debian-11-with-custom-packages: - extends: - - .stage-test-with-custom-packages - - .variables-debian-11 - - .script-molecule-test-with-custom-packages diff --git a/LICENSE b/LICENSE index 9ef042d..c9a37e5 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2017 Jeff Geerling +Copyright (c) 2017 Bertrand Lanson 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 diff --git a/README.md b/README.md index e65303a..c4caf05 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -Manage pip packages +manage_pip_packages ========= > This repository is only a mirror. Development and testing is done on a private gitlab server. @@ -63,4 +63,4 @@ MIT / BSD Author Information ------------------ -This role was created by Bertrand Lanson in 2023. \ No newline at end of file +This role was created by Bertrand Lanson in 2023. diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml index 7a62eb2..49efc7f 100644 --- a/molecule/default/molecule.yml +++ b/molecule/default/molecule.yml @@ -20,7 +20,7 @@ provisioner: defaults: remote_tmp: /tmp/.ansible verifier: - name: testinfra + name: ansible scenario: name: default test_sequence: diff --git a/molecule/default/verify.yml b/molecule/default/verify.yml new file mode 100644 index 0000000..20a4467 --- /dev/null +++ b/molecule/default/verify.yml @@ -0,0 +1,46 @@ +--- +- name: Verify + hosts: all + gather_facts: false + tasks: + - name: "Test: file /etc/hosts" + block: + - name: "Stat file /etc/hosts" + ansible.builtin.stat: + path: "/etc/hosts" + register: stat_etc_hosts + + - name: "Verify file /etc/hosts" + ansible.builtin.assert: + that: + - stat_etc_hosts.stat.exists + - stat_etc_hosts.stat.isreg + - stat_etc_hosts.stat.pw_name == 'root' + - stat_etc_hosts.stat.gr_name == 'root' + + - name: "Test: packages pip, vault-cli, yamllint, docker" + block: + - name: "Get pip3 up-to-date packages" + ansible.builtin.command: "pip3 list -u --format=json" + changed_when: false + register: pip_updated_packages + + - name: "Get pip3 out-of-date packages" + ansible.builtin.command: "pip3 list -o --format=json" + changed_when: false + register: pip_outdated_packages + + - name: "Verify packages pip, vault-cli, yamllint, docker" + vars: + pip_up_to_date_list: "{{ pip_updated_packages.stdout | from_json | json_query('[].name') }}" + pip_out_of_date_list: "{{ pip_outdated_packages.stdout | from_json | json_query('[].name') }}" + ansible.builtin.assert: + that: + - "'pip' in pip_up_to_date_list" + - "'pip' not in pip_out_of_date_list" + - "'vault-cli' not in pip_up_to_date_list" + - "'vault-cli' not in pip_out_of_date_list" + - "'yamllint' not in pip_up_to_date_list" + - "'yamllint' not in pip_out_of_date_list" + - "'docker' not in pip_up_to_date_list" + - "'docker' not in pip_out_of_date_list" diff --git a/molecule/with_custom_packages/molecule.yml b/molecule/with_custom_packages/molecule.yml index c641fc1..30f7b0f 100644 --- a/molecule/with_custom_packages/molecule.yml +++ b/molecule/with_custom_packages/molecule.yml @@ -20,7 +20,7 @@ provisioner: defaults: remote_tmp: /tmp/.ansible verifier: - name: testinfra + name: ansible scenario: name: with_custom_packages test_sequence: diff --git a/molecule/with_custom_packages/verify.yml b/molecule/with_custom_packages/verify.yml new file mode 100644 index 0000000..d0c1d64 --- /dev/null +++ b/molecule/with_custom_packages/verify.yml @@ -0,0 +1,46 @@ +--- +- name: Verify + hosts: all + gather_facts: false + tasks: + - name: "Test: file /etc/hosts" + block: + - name: "Stat file /etc/hosts" + ansible.builtin.stat: + path: "/etc/hosts" + register: stat_etc_hosts + + - name: "Verify file /etc/hosts" + ansible.builtin.assert: + that: + - stat_etc_hosts.stat.exists + - stat_etc_hosts.stat.isreg + - stat_etc_hosts.stat.pw_name == 'root' + - stat_etc_hosts.stat.gr_name == 'root' + + - name: "Test: packages pip, vault-cli, yamllint, docker" + block: + - name: "Get pip3 up-to-date packages" + ansible.builtin.command: "pip3 list -u --format=json" + changed_when: false + register: pip_updated_packages + + - name: "Get pip3 out-of-date packages" + ansible.builtin.command: "pip3 list -o --format=json" + changed_when: false + register: pip_outdated_packages + + - name: "Verify packages pip, vault-cli, yamllint, docker" + vars: + pip_up_to_date_list: "{{ pip_updated_packages.stdout | from_json | json_query('[].name') }}" + pip_out_of_date_list: "{{ pip_outdated_packages.stdout | from_json | json_query('[].name') }}" + ansible.builtin.assert: + that: + - "'pip' in pip_up_to_date_list" + - "'pip' not in pip_out_of_date_list" + - "'vault-cli' not in pip_up_to_date_list" + - "'vault-cli' in pip_out_of_date_list" + - "'yamllint' not in pip_up_to_date_list" + - "'yamllint' in pip_out_of_date_list" + - "'docker' in pip_up_to_date_list" + - "'docker' not in pip_out_of_date_list"