Skip to content
Snippets Groups Projects
Commit ead0f3b5 authored by fejao's avatar fejao
Browse files

Merge branch 'Setting_submodule_role_test' into 'main'

Setting submodule role test

See merge request !17
parents b8a4d5f8 c2714cf0
Branches
No related tags found
1 merge request!17Setting submodule role test
Pipeline #37723 passed
Showing
with 314 additions and 374 deletions
---
# image: python:3.10.15-bullseye # image: python:3.10.15-bullseye
### ###
...@@ -7,246 +9,31 @@ variables: ...@@ -7,246 +9,31 @@ variables:
AUTHOR: fejao AUTHOR: fejao
IMAGE_NAME_SYNTAX: python:3.10.15-bullseye IMAGE_NAME_SYNTAX: python:3.10.15-bullseye
IMAGE_NAME_LINT: python:3.10.15-bullseye IMAGE_NAME_LINT: python:3.10.15-bullseye
IMAGE_NAME_MOLECULE: python:3.10.15-bullseye
# IMAGE_NAME_MOLECULE: geerlingguy/docker-ubuntu2204-ansible:latest # IMAGE_NAME_MOLECULE: geerlingguy/docker-ubuntu2204-ansible:latest
IMAGE_NAME_MOLECULE: docker:dind ### PATHS
INVENTORIES_PATH: "inventories/hosts" INVENTORIES_PATH: "inventories/hosts"
PLAYBOOK_PATH_FOR_ROLE_TEST: "ci-cd/01_test.yml" PATH_PLAYBOOK_FOR_ROLE_TEST: "ci-cd/playbooks/01_test.yml"
PLAYBOOK_PATH_FOR_ROLE_DEPENDENCIES: "ci-cd/02_dependencies.yml" PATH_PLAYBOOK_FOR_ROLE_DEPENDENCIES: "ci-cd/playbooks/02_dependencies.yml"
PLAYBOOK_PATH_FOR_ROLE_CLONE_REPOSITORIES: "ci-cd/03_clone_repositories.yml" PATH_PLAYBOOK_FOR_ROLE_CLONE_REPOSITORIES: "ci-cd/playbooks/03_clone_repositories.yml"
PLAYBOOK_PATH_FOR_ROLE_DOCKER_IMAGES: "ci-cd/04_docker_images.yml" PATH_PLAYBOOK_FOR_ROLE_DOCKER_IMAGES: "ci-cd/playbooks/04_docker_images.yml"
PLAYBOOK_PATH_FOR_ROLE_DOCKER_CONTAINERS: "ci-cd/05_docker_containers.yml" PATH_PLAYBOOK_FOR_ROLE_DOCKER_CONTAINERS: "ci-cd/playbooks/05_docker_containers.yml"
PLAYBOOK_PATH_FOR_ROLE_OH_MY_BASH: "ci-cd/06_oh_my_bash.yml" PATH_PLAYBOOK_FOR_ROLE_OH_MY_BASH: "ci-cd/playbooks/06_oh_my_bash.yml"
### ###
### STAGES ### STAGES
### ###
stages: stages:
- syntax-check - before-role-trigger
- syntax-checks
- lint-tests - lint-tests
- molecule - molecule
### ###
### SCRIPTS ### TEMPLATES
###
.before_syntax_n_lint: &before_syntax_n_lint
- 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
### Correct the permissions on the build environment directory.
### See https://github.com/ansible/ansible/pull/42142/files
- chmod 700 /builds/fejao/c3infodesk-deployment
.run_syntax_check: &run_syntax_check
- ansible-playbook --syntax-check -i $INVENTORIES_PATH $ROLE_PATH
.run_lint: &run_lint
- ansible-lint $ROLE_PATH
###
### STAGE-SYNTAX-CHECK
###
syntax-test:
stage: syntax-check
image: $IMAGE_NAME_SYNTAX
variables:
ROLE_PATH: $PLAYBOOK_PATH_FOR_ROLE_TEST
before_script:
- *before_syntax_n_lint
script:
- echo "Running ansible-playbook --syntax-check tests at the role-> 'test'"
- *run_syntax_check
allow_failure: false
syntax-dependencies:
stage: syntax-check
image: $IMAGE_NAME_SYNTAX
variables:
ROLE_PATH: $PLAYBOOK_PATH_FOR_ROLE_DEPENDENCIES
before_script:
- *before_syntax_n_lint
script:
- echo "Running ansible-playbook --syntax-check tests at the role-> 'dependencies'"
- *run_syntax_check
allow_failure: false
syntax-clone-repositories:
stage: syntax-check
image: $IMAGE_NAME_SYNTAX
variables:
ROLE_PATH: $PLAYBOOK_PATH_FOR_ROLE_CLONE_REPOSITORIES
before_script:
- *before_syntax_n_lint
script:
- echo "Running ansible-playbook --syntax-check tests at the role-> 'clone_repositories'"
- *run_syntax_check
allow_failure: false
syntax-docker-images:
stage: syntax-check
image: $IMAGE_NAME_SYNTAX
variables:
ROLE_PATH: $PLAYBOOK_PATH_FOR_ROLE_DOCKER_IMAGES
before_script:
- *before_syntax_n_lint
script:
- echo "Running ansible-playbook --syntax-check tests at the role-> 'docker_images'"
- *run_syntax_check
allow_failure: false
syntax-docker-containers:
stage: syntax-check
image: $IMAGE_NAME_SYNTAX
variables:
ROLE_PATH: $PLAYBOOK_PATH_FOR_ROLE_DOCKER_CONTAINERS
before_script:
- *before_syntax_n_lint
script:
- echo "Running ansible-playbook --syntax-check tests at the role-> 'docker_containers'"
- *run_syntax_check
allow_failure: false
syntax-oh-my-bash:
stage: syntax-check
image: $IMAGE_NAME_SYNTAX
variables:
ROLE_PATH: $PLAYBOOK_PATH_FOR_ROLE_OH_MY_BASH
before_script:
- *before_syntax_n_lint
script:
- echo "Running ansible-playbook --syntax-check tests at the role-> 'docker_containers'"
- *run_syntax_check
allow_failure: false
### ###
### STAGE-LINT-TESTS include:
### # - local: ci-cd/templates/trigger-pipeline.yml
lint-test: - local: ci-cd/templates/syntax-checks.yml
stage: lint-tests - local: ci-cd/templates/lint-tests.yml
image: $IMAGE_NAME_LINT - local: ci-cd/templates/molecule.yml
variables:
ROLE_PATH: $PLAYBOOK_PATH_FOR_ROLE_TEST
before_script:
- *before_syntax_n_lint
script:
- echo "Running ansible-lint tests at the role-> 'test'"
- *run_lint
allow_failure: false
lint-dependencies:
stage: lint-tests
image: $IMAGE_NAME_LINT
variables:
ROLE_PATH: $PLAYBOOK_PATH_FOR_ROLE_DEPENDENCIES
before_script:
- *before_syntax_n_lint
script:
- echo "Running ansible-lint tests at the role-> 'dependencies'"
- *run_lint
allow_failure: false
lint-clone-repositories:
stage: lint-tests
image: $IMAGE_NAME_LINT
variables:
ROLE_PATH: $PLAYBOOK_PATH_FOR_ROLE_CLONE_REPOSITORIES
before_script:
- *before_syntax_n_lint
script:
- echo "Running ansible-lint tests at the role-> 'clone_repositories'"
- *run_lint
allow_failure: false
lint-docker-images:
stage: lint-tests
image: $IMAGE_NAME_LINT
variables:
ROLE_PATH: $PLAYBOOK_PATH_FOR_ROLE_DOCKER_IMAGES
before_script:
- *before_syntax_n_lint
script:
- echo "Running ansible-lint tests at the role-> 'docker_images'"
- *run_lint
allow_failure: false
lint-docker-containers:
stage: lint-tests
image: $IMAGE_NAME_LINT
variables:
ROLE_PATH: $PLAYBOOK_PATH_FOR_ROLE_DOCKER_CONTAINERS
before_script:
- *before_syntax_n_lint
script:
- echo "Running ansible-lint tests at the role-> 'docker_containers'"
- *run_lint
allow_failure: false
lint-oh-my-bash:
stage: lint-tests
image: $IMAGE_NAME_LINT
variables:
ROLE_PATH: $PLAYBOOK_PATH_FOR_ROLE_OH_MY_BASH
before_script:
- *before_syntax_n_lint
script:
- echo "Running ansible-lint tests at the role-> 'docker_containers'"
- *run_lint
allow_failure: false
###
### STAGE-MOLECULE --> At the moment, running DIND (docker in docker) at this instance is disable :(
###
# molecule-test:
# stage: molecule
# image: $IMAGE_NAME_MOLECULE
# ### AVAILABLE TAGS
# # https://docs.gitlab.com/ee/ci/runners/hosted_runners/linux.html#machine-types-available-for-linux---x86-64
# tags:
# - saas-linux-small-amd64
# # 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 molecule 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
# # image: geerlingguy/docker-ubuntu2204-ansible:latest
# image: $IMAGE_NAME_MOLECULE
# 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
# 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
# - pip3 install --upgrade molecule molecule-docker
# # - python3 -m pip install --user "molecule-plugins[docker]
# - pip3 install --user "molecule-plugins[docker]"
# script:
# - echo "Running ansible-lint tests at the role-> 'test'"
# - cd roles/test
# - molecule test
# allow_failure: false
[submodule "roles/c3infodesk-deployment-role-test"]
path = roles/c3infodesk-deployment-role-test
url = git@git.cccv.de:fejao/c3infodesk-deployment-role-test.git
...@@ -5,4 +5,5 @@ ...@@ -5,4 +5,5 @@
hosts: hosts:
- example_servers_group - example_servers_group
roles: roles:
- roles/test # - roles/test
- roles/c3infodesk-deployment-role-test
File moved
File moved
File moved
yamllint
ansible
ansible-dev-tools
ansible-lint
### MOLECULE
# python3 -m pip install --user "molecule-plugins[docker]"
# molecule
# ansible-core
ansible
ansible-dev-tools
ansible-lint
---
variables:
INVENTORIES_PATH: "inventories/hosts"
REQUIREMENTS_PATH: "ci-cd/python_requirements/requirements_syntax_n_lint.txt"
ENV_DIR_PATH: "/builds/fejao/c3infodesk-deployment"
###
### SCRIPTS
###
.before_script_syntax_n_lint:
before_script:
- echo "Running before_script for 'before_script_syntax_n_lint'"
- apt-get update && apt-get install -y python3-pip && apt-get clean && rm -rf /var/lib/apt/lists/*
- pip3 install -r $REQUIREMENTS_PATH
###########
# ### Correct the permissions on the build environment directory.
# ### See https://github.com/ansible/ansible/pull/42142/files
- chmod 700 $ENV_DIR_PATH
.script_syntax_check_main:
extends: .before_script_syntax_n_lint
script:
- echo "Running script for 'script_syntax_check_main'"
- ansible-playbook --syntax-check -i $INVENTORIES_PATH $PLAYBOOK_PATH
.run_lint:
extends: .before_script_syntax_n_lint
script:
- echo "Running script for 'run_lint'"
- ansible-lint $PLAYBOOK_PATH
---
###
### VARIABLES
###
variables:
AUTHOR: fejao
###
### INCLUDE
###
include:
- local: /ci-cd/scripts/syntax_n_lint.yml
###
### STAGE-LINT-TESTS
###
lint-test:
stage: lint-tests
image: $IMAGE_NAME_LINT
extends: .run_lint
variables:
PLAYBOOK_PATH: $PATH_PLAYBOOK_FOR_ROLE_TEST
# only:
# changes:
# - roles/c3infodesk-deployment-role-test
lint-dependencies:
stage: lint-tests
image: $IMAGE_NAME_LINT
extends: .run_lint
variables:
PLAYBOOK_PATH: $PATH_PLAYBOOK_FOR_ROLE_DEPENDENCIES
# only:
# changes:
# - roles/c3infodesk-deployment-role-dependencies
lint-clone-repositories:
stage: lint-tests
image: $IMAGE_NAME_LINT
extends: .run_lint
variables:
PLAYBOOK_PATH: $PATH_PLAYBOOK_FOR_ROLE_CLONE_REPOSITORIES
# only:
# changes:
# - roles/c3infodesk-deployment-role-clone-repositories
lint-docker-images:
stage: lint-tests
image: $IMAGE_NAME_LINT
extends: .run_lint
variables:
PLAYBOOK_PATH: $PATH_PLAYBOOK_FOR_ROLE_DOCKER_IMAGES
# only:
# changes:
# - roles/c3infodesk-deployment-role-docker-containers
lint-docker-containers:
stage: lint-tests
image: $IMAGE_NAME_LINT
extends: .run_lint
variables:
PLAYBOOK_PATH: $PATH_PLAYBOOK_FOR_ROLE_DOCKER_CONTAINERS
# only:
# changes:
# - roles/c3infodesk-deployment-role-docker-containers
lint-oh-my-bash:
stage: lint-tests
image: $IMAGE_NAME_LINT
extends: .run_lint
variables:
PLAYBOOK_PATH: $PATH_PLAYBOOK_FOR_ROLE_OH_MY_BASH
# only:
# changes:
# - roles/c3infodesk-deployment-role-oh-my-bash
---
###
### VARIABLES
###
variables:
AUTHOR: fejao
molecule-not-enabled:
stage: molecule
image: $IMAGE_NAME_MOLECULE
script:
- echo "This can't be done before enable DIND at the instance"
###
### STAGE-MOLECULE --> At the moment, running DIND (docker in docker) at this instance is disable :(
###
# molecule-test:
# stage: molecule
# image: $IMAGE_NAME_MOLECULE
# ### AVAILABLE TAGS
# # https://docs.gitlab.com/ee/ci/runners/hosted_runners/linux.html#machine-types-available-for-linux---x86-64
# tags:
# - saas-linux-small-amd64
# # 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 molecule 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
# # image: geerlingguy/docker-ubuntu2204-ansible:latest
# image: $IMAGE_NAME_MOLECULE
# 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
# 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
# - pip3 install --upgrade molecule molecule-docker
# # - python3 -m pip install --user "molecule-plugins[docker]
# - pip3 install --user "molecule-plugins[docker]"
# script:
# - echo "Running ansible-lint tests at the role-> 'test'"
# - cd roles/test
# - molecule test
# allow_failure: false
---
###
### VARIABLES
###
variables:
AUTHOR: fejao
###
### INCLUDE
###
include:
- local: /ci-cd/scripts/syntax_n_lint.yml
###
### STAGE-SYNTAX-CHECKS
###
syntax-test:
stage: syntax-checks
image: $IMAGE_NAME_SYNTAX
extends: .script_syntax_check_main
variables:
PLAYBOOK_PATH: $PATH_PLAYBOOK_FOR_ROLE_TEST
# only:
# changes:
# - roles/c3infodesk-deployment-role-test
# refs:
# - main
syntax-dependencies:
stage: syntax-checks
image: $IMAGE_NAME_SYNTAX
extends: .script_syntax_check_main
variables:
PLAYBOOK_PATH: $PATH_PLAYBOOK_FOR_ROLE_DEPENDENCIES
# only:
# changes:
# - roles/c3infodesk-deployment-role-dependencies
syntax-clone-repositories:
stage: syntax-checks
image: $IMAGE_NAME_SYNTAX
extends: .script_syntax_check_main
variables:
PLAYBOOK_PATH: $PATH_PLAYBOOK_FOR_ROLE_CLONE_REPOSITORIES
# only:
# changes:
# - roles/c3infodesk-deployment-role-clone-repositories
syntax-docker-images:
stage: syntax-checks
image: $IMAGE_NAME_SYNTAX
extends: .script_syntax_check_main
variables:
PLAYBOOK_PATH: $PATH_PLAYBOOK_FOR_ROLE_DOCKER_IMAGES
# only:
# changes:
# - roles/c3infodesk-deployment-role-docker-images
syntax-docker-containers:
stage: syntax-checks
image: $IMAGE_NAME_SYNTAX
extends: .script_syntax_check_main
variables:
PLAYBOOK_PATH: $PATH_PLAYBOOK_FOR_ROLE_DOCKER_CONTAINERS
# only:
# changes:
# - roles/c3infodesk-deployment-role-docker-containers
syntax-oh-my-bash:
stage: syntax-checks
image: $IMAGE_NAME_SYNTAX
extends: .script_syntax_check_main
variables:
PLAYBOOK_PATH: $PATH_PLAYBOOK_FOR_ROLE_OH_MY_BASH
# only:
# changes:
# - roles/c3infodesk-deployment-role-oh-my-bash
---
###
### VARIABLES
###
variables:
AUTHOR: fejao
trigger-pipeline:
stage: before-role-trigger
# trigger:
# include: <ChildFolder>/.gitlab-ci.yml
# trigger:
# # include: roles/c3infodesk-deployment-role-test/.gitlab-ci.yml
# include: /builds/fejao/c3infodesk-deployment/roles/c3infodesk-deployment-role-test/.gitlab-ci.yml
script:
- echo "Triggering tests for the 'test' role"
- pwd
# /builds/fejao/c3infodesk-deployment
- ls -la
- ls -la roles
- ls -la roles/c3infodesk-deployment-role-test
- ls -la roles/c3infodesk-deployment-role-test/.gitlab-ci.yml
Subproject commit ddc45d25c366878dd3f92136c54d4852562342c6
# 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:
```yaml
- hosts:
- example_servers_group
roles:
- test
```
And call the playbook as:
```bash
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 playbooks/examples/example_01_test.yml
```
### Lint
```bash
ansible-lint ci-cd/01_test.yml
```
### molecule
```bash
cd roles/test
molecule test
```
## License
MIT/BSD
## Author Information
![fejao logo](../../files/from_authors/fejao_logo_circle.png "fejao") [https://chaos.social/@fejao](https://chaos.social/@fejao)
---
# defaults file for test
var_setted_everywhere: "answer from roles/test/defaults/main.yml"
var_setted_only_defaults_main: "MESSAGE FROM roles/test/defaults/main.yml"
---
- name: MOLECULE | Converge
hosts: all
tasks:
- name: MOLECULE | CONVERGE | Call the 'test' role.
ansible.builtin.include_role:
name: test
---
dependency:
name: galaxy
driver:
name: docker
platforms:
- name: instance
image: geerlingguy/docker-ubuntu2004-ansible:latest
# privileged: true
pre_build_image: true
provisioner:
name: ansible
inventory:
###
### VARS used from the role
###
group_vars:
example_servers_group:
var_setted_only_group_vars: "group_vars_value"
var_setted_everywhere: "group_vars_value"
host_vars:
instance:
var_setted_only_host_vars: "host_vars_value"
var_setted_everywhere: "host_vars_value"
lint: |
ansible-lint --exclude molecule/default/
scenario:
name: default
create_sequence:
- dependency
- create
- prepare
check_sequence:
- dependency
- cleanup
- destroy
- create
- prepare
- converge
- check
- destroy
converge_sequence:
- dependency
- create
- prepare
- converge
destroy_sequence:
- dependency
- cleanup
- destroy
test_sequence:
# - lint
# - dependency
# - cleanup
- destroy
- syntax
- create
# - prepare
- converge
- verify
- idempotence
# - side_effect
# - cleanup
- destroy
verifier:
name: ansible
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment