diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index afcc9bd24d6fc83a89526c3da483160d05121620..a2be19e928bc8513b416391d4ed348462cc85740 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -17,143 +17,143 @@ stages: - lint-tests - molecule -# ### -# ### SYNTAX-CHECK -# ### -# syntax-test: -# stage: syntax-check -# image: python:3.10.15-bullseye -# before_script: -# - apt-get update && apt-get install -y python3-pip && apt-get clean && rm -rf /var/lib/apt/lists/* -# - pip3 install -r ci-cd/requirements.txt -# script: -# - echo "Running ansible-playbook --syntax-check tests at the role-> 'test'" -# - ansible-playbook --syntax-check -i $INVENTORIES_PATH $PLAYBOOK_PATH_FOR_ROLE_TEST -# allow_failure: false +### +### SYNTAX-CHECK +### +syntax-test: + stage: syntax-check + image: python:3.10.15-bullseye + before_script: + - apt-get update && apt-get install -y python3-pip && apt-get clean && rm -rf /var/lib/apt/lists/* + - pip3 install -r ci-cd/requirements.txt + script: + - echo "Running ansible-playbook --syntax-check tests at the role-> 'test'" + - ansible-playbook --syntax-check -i $INVENTORIES_PATH $PLAYBOOK_PATH_FOR_ROLE_TEST + allow_failure: false -# syntax-dependencies: -# stage: syntax-check -# image: python:3.10.15-bullseye -# before_script: -# - apt-get update && apt-get install -y python3-pip && apt-get clean && rm -rf /var/lib/apt/lists/* -# - pip3 install -r ci-cd/requirements.txt -# script: -# - echo "Running ansible-playbook --syntax-check tests at the role-> 'dependencies'" -# - ansible-playbook --syntax-check -i $INVENTORIES_PATH $PLAYBOOK_PATH_FOR_ROLE_DEPENDENCIES -# allow_failure: false +syntax-dependencies: + stage: syntax-check + image: python:3.10.15-bullseye + before_script: + - apt-get update && apt-get install -y python3-pip && apt-get clean && rm -rf /var/lib/apt/lists/* + - pip3 install -r ci-cd/requirements.txt + script: + - echo "Running ansible-playbook --syntax-check tests at the role-> 'dependencies'" + - ansible-playbook --syntax-check -i $INVENTORIES_PATH $PLAYBOOK_PATH_FOR_ROLE_DEPENDENCIES + allow_failure: false -# syntax-clone-repositories: -# stage: syntax-check -# image: python:3.10.15-bullseye -# before_script: -# - apt-get update && apt-get install -y python3-pip && apt-get clean && rm -rf /var/lib/apt/lists/* -# - pip3 install -r ci-cd/requirements.txt -# script: -# - echo "Running ansible-playbook --syntax-check tests at the role-> 'clone_repositories'" -# - ansible-playbook --syntax-check -i $INVENTORIES_PATH $PLAYBOOK_PATH_FOR_ROLE_CLONE_REPOSITORIES -# allow_failure: false +syntax-clone-repositories: + stage: syntax-check + image: python:3.10.15-bullseye + before_script: + - apt-get update && apt-get install -y python3-pip && apt-get clean && rm -rf /var/lib/apt/lists/* + - pip3 install -r ci-cd/requirements.txt + script: + - echo "Running ansible-playbook --syntax-check tests at the role-> 'clone_repositories'" + - ansible-playbook --syntax-check -i $INVENTORIES_PATH $PLAYBOOK_PATH_FOR_ROLE_CLONE_REPOSITORIES + allow_failure: false -# syntax-docker-images: -# stage: syntax-check -# image: python:3.10.15-bullseye -# before_script: -# - apt-get update && apt-get install -y python3-pip && apt-get clean && rm -rf /var/lib/apt/lists/* -# - pip3 install -r ci-cd/requirements.txt -# script: -# - echo "Running ansible-playbook --syntax-check tests at the role-> 'docker_images'" -# - ansible-playbook --syntax-check -i $INVENTORIES_PATH $PLAYBOOK_PATH_FOR_ROLE_DOCKER_IMAGES -# allow_failure: false +syntax-docker-images: + stage: syntax-check + image: python:3.10.15-bullseye + before_script: + - apt-get update && apt-get install -y python3-pip && apt-get clean && rm -rf /var/lib/apt/lists/* + - pip3 install -r ci-cd/requirements.txt + script: + - echo "Running ansible-playbook --syntax-check tests at the role-> 'docker_images'" + - ansible-playbook --syntax-check -i $INVENTORIES_PATH $PLAYBOOK_PATH_FOR_ROLE_DOCKER_IMAGES + allow_failure: false -# syntax-docker-containers: -# stage: syntax-check -# image: python:3.10.15-bullseye -# before_script: -# - apt-get update && apt-get install -y python3-pip && apt-get clean && rm -rf /var/lib/apt/lists/* -# - pip3 install -r ci-cd/requirements.txt -# script: -# - echo "Running ansible-playbook --syntax-check tests at the role-> 'docker_containers'" -# - ansible-playbook --syntax-check -i $INVENTORIES_PATH $PLAYBOOK_PATH_FOR_ROLE_DOCKER_CONTAINERS -# allow_failure: false +syntax-docker-containers: + stage: syntax-check + image: python:3.10.15-bullseye + before_script: + - apt-get update && apt-get install -y python3-pip && apt-get clean && rm -rf /var/lib/apt/lists/* + - pip3 install -r ci-cd/requirements.txt + script: + - echo "Running ansible-playbook --syntax-check tests at the role-> 'docker_containers'" + - ansible-playbook --syntax-check -i $INVENTORIES_PATH $PLAYBOOK_PATH_FOR_ROLE_DOCKER_CONTAINERS + allow_failure: false -# ### -# ### LINT-TESTS -# ### -# lint-test: -# stage: lint-tests -# image: python:3.10.15-bullseye -# before_script: -# - apt-get update && apt-get install -y python3-pip && apt-get clean && rm -rf /var/lib/apt/lists/* -# - pip3 install -r ci-cd/requirements.txt -# script: -# - echo "Running ansible-lint tests at the role-> 'test'" -# - ansible-lint $PLAYBOOK_PATH_FOR_ROLE_TEST -# allow_failure: false +### +### LINT-TESTS +### +lint-test: + stage: lint-tests + image: python:3.10.15-bullseye + before_script: + - apt-get update && apt-get install -y python3-pip && apt-get clean && rm -rf /var/lib/apt/lists/* + - pip3 install -r ci-cd/requirements.txt + script: + - echo "Running ansible-lint tests at the role-> 'test'" + - ansible-lint $PLAYBOOK_PATH_FOR_ROLE_TEST + allow_failure: false -# lint-dependencies: -# stage: lint-tests -# image: python:3.10.15-bullseye -# before_script: -# - apt-get update && apt-get install -y python3-pip && apt-get clean && rm -rf /var/lib/apt/lists/* -# - pip3 install -r ci-cd/requirements.txt -# script: -# - echo "Running ansible-lint tests at the role-> 'dependencies'" -# - ansible-lint $PLAYBOOK_PATH_FOR_ROLE_DEPENDENCIES -# allow_failure: false +lint-dependencies: + stage: lint-tests + image: python:3.10.15-bullseye + before_script: + - apt-get update && apt-get install -y python3-pip && apt-get clean && rm -rf /var/lib/apt/lists/* + - pip3 install -r ci-cd/requirements.txt + script: + - echo "Running ansible-lint tests at the role-> 'dependencies'" + - ansible-lint $PLAYBOOK_PATH_FOR_ROLE_DEPENDENCIES + allow_failure: false -# lint-clone-repositories: -# stage: lint-tests -# image: python:3.10.15-bullseye -# before_script: -# - apt-get update && apt-get install -y python3-pip && apt-get clean && rm -rf /var/lib/apt/lists/* -# - pip3 install -r ci-cd/requirements.txt -# script: -# - echo "Running ansible-lint tests at the role-> 'clone_repositories'" -# - ansible-lint $PLAYBOOK_PATH_FOR_ROLE_CLONE_REPOSITORIES -# allow_failure: false +lint-clone-repositories: + stage: lint-tests + image: python:3.10.15-bullseye + before_script: + - apt-get update && apt-get install -y python3-pip && apt-get clean && rm -rf /var/lib/apt/lists/* + - pip3 install -r ci-cd/requirements.txt + script: + - echo "Running ansible-lint tests at the role-> 'clone_repositories'" + - ansible-lint $PLAYBOOK_PATH_FOR_ROLE_CLONE_REPOSITORIES + allow_failure: false -# lint-docker-images: -# stage: lint-tests -# image: python:3.10.15-bullseye -# before_script: -# - apt-get update && apt-get install -y python3-pip && apt-get clean && rm -rf /var/lib/apt/lists/* -# - pip3 install -r ci-cd/requirements.txt -# script: -# - echo "Running ansible-lint tests at the role-> 'docker_images'" -# - ansible-lint $PLAYBOOK_PATH_FOR_ROLE_DOCKER_IMAGES -# allow_failure: false +lint-docker-images: + stage: lint-tests + image: python:3.10.15-bullseye + before_script: + - apt-get update && apt-get install -y python3-pip && apt-get clean && rm -rf /var/lib/apt/lists/* + - pip3 install -r ci-cd/requirements.txt + script: + - echo "Running ansible-lint tests at the role-> 'docker_images'" + - ansible-lint $PLAYBOOK_PATH_FOR_ROLE_DOCKER_IMAGES + allow_failure: false -# lint-docker-containers: -# stage: lint-tests -# image: python:3.10.15-bullseye -# before_script: -# - apt-get update && apt-get install -y python3-pip && apt-get clean && rm -rf /var/lib/apt/lists/* -# - pip3 install -r ci-cd/requirements.txt -# script: -# - echo "Running ansible-lint tests at the role-> 'docker_containers'" -# - ansible-lint $PLAYBOOK_PATH_FOR_ROLE_DOCKER_CONTAINERS -# allow_failure: false +lint-docker-containers: + stage: lint-tests + image: python:3.10.15-bullseye + before_script: + - apt-get update && apt-get install -y python3-pip && apt-get clean && rm -rf /var/lib/apt/lists/* + - pip3 install -r ci-cd/requirements.txt + script: + - echo "Running ansible-lint tests at the role-> 'docker_containers'" + - ansible-lint $PLAYBOOK_PATH_FOR_ROLE_DOCKER_CONTAINERS + allow_failure: false ### ### molecule ### -molecule-test: - stage: molecule - # image: docker:latest - # image: docker:27.5.1-alpine3.21 - image: docker:27.5.1-dind - before_script: - - apk add --no-cache python3 py3-pip - - rm /usr/lib/python*/EXTERNALLY-MANAGED - - python3 -m ensurepip - - pip3 install ansible ansible-lint molecule molecule-docker - - pip3 install --user "molecule-plugins[docker]" - script: - - echo "Running ansible-lint tests at the role-> 'test'" - - docker ps -a - - cd roles/test - - molecule test - allow_failure: false +# molecule-test: +# stage: molecule +# # image: docker:latest +# # image: docker:27.5.1-alpine3.21 +# image: docker:27.5.1-dind +# before_script: +# - apk add --no-cache python3 py3-pip +# - rm /usr/lib/python*/EXTERNALLY-MANAGED +# - python3 -m ensurepip +# - pip3 install ansible ansible-lint molecule molecule-docker +# - pip3 install --user "molecule-plugins[docker]" +# script: +# - echo "Running ansible-lint tests at the role-> 'test'" +# - docker ps -a +# - cd roles/test +# - molecule test +# allow_failure: false # molecule-test: # stage: molecule diff --git a/roles/test/README.md b/roles/test/README.md index e443d1878e35c1bd9d149cd6070c3409841370ef..123e54580ff8dba8c32568eb02b387aa00211109 100644 --- a/roles/test/README.md +++ b/roles/test/README.md @@ -1,16 +1,19 @@ # test role - This is a ansible-role for testing your installed ansible. + ## Requirements To have ansible installed at your system. + ## Role Variables You should look around where the variables are setted. And figure it out from where the ouput comes + ## Dependencies This role have no dependency from any another role. + ## Example Playbook Here is an example for adding this role for your playbook for **restarting** the **c3infodesk-printer**. containers: @@ -27,10 +30,32 @@ And call the playbook as: ansible-playbook -i <INVENTORY> <PLAYBOOK_NAME>.yml ``` +## Tests +Here are the tests made at **CI-CD** for this role. + +The tests shuold be runned at the root directory from the repository. + +### Syntax +```bash +ansible-playbook --syntax-check -i invenvories/hosts ci-cd/01_test.yml +``` + +### Lint +```bash +ansible-lint ci-cd/01_test.yml +``` + +### molecule +```bash +cd roles/test +molecule test +``` + ## License MIT/BSD + ## Author Information  [https://chaos.social/@fejao](https://chaos.social/@fejao)