From 1928702a429728b48decefb1bfd63d4db84d279a Mon Sep 17 00:00:00 2001 From: fejao <mail@fejao.de> Date: Mon, 27 Jan 2025 23:21:27 +0000 Subject: [PATCH] Moving files 01 --- .ansible-lint | 2 + .gitlab-ci.yml | 108 +++++++++++------- README.md | 21 +++- .../01_test.yml | 4 +- ci-cd/02_dependencies.yml | 8 ++ ci-cd/03_clone_repositories.yml | 8 ++ ci-cd/04_docker_images.yml | 8 ++ .../05_docker_containers.yml | 4 +- requirements.txt => ci-cd/requirements.txt | 0 files/README.md | 4 + playbook_example_02_dependencies.yml | 8 -- playbook_example_03_clone_repositories.yml | 8 -- playbooks/README.md | 4 + playbooks/examples/example_01_test.yml | 8 ++ .../examples/example_02_dependencies.yml | 8 ++ .../example_03_clone_repositories.yml | 8 ++ .../examples/example_04_docker_images.yml | 2 +- .../examples/example_05_docker_containers.yml | 11 ++ roles/clone_repositories/README.md | 4 +- roles/clone_repositories/meta/main.yml | 2 +- roles/dependencies/README.md | 4 +- roles/dependencies/meta/main.yml | 2 +- roles/docker_containers/README.md | 6 +- roles/docker_containers/meta/main.yml | 2 +- roles/docker_images/README.md | 4 +- roles/docker_images/meta/main.yml | 2 +- 26 files changed, 171 insertions(+), 79 deletions(-) rename playbook_example_01_test.yml => ci-cd/01_test.yml (51%) create mode 100644 ci-cd/02_dependencies.yml create mode 100644 ci-cd/03_clone_repositories.yml create mode 100644 ci-cd/04_docker_images.yml rename playbook_example_05_docker_containers.yml => ci-cd/05_docker_containers.yml (68%) rename requirements.txt => ci-cd/requirements.txt (100%) create mode 100644 files/README.md delete mode 100644 playbook_example_02_dependencies.yml delete mode 100644 playbook_example_03_clone_repositories.yml create mode 100644 playbooks/README.md create mode 100644 playbooks/examples/example_01_test.yml create mode 100644 playbooks/examples/example_02_dependencies.yml create mode 100644 playbooks/examples/example_03_clone_repositories.yml rename playbook_example_04_docker_images.yml => playbooks/examples/example_04_docker_images.yml (59%) create mode 100644 playbooks/examples/example_05_docker_containers.yml diff --git a/.ansible-lint b/.ansible-lint index c381cc1..751568d 100644 --- a/.ansible-lint +++ b/.ansible-lint @@ -57,6 +57,8 @@ skip_list: - loop-var-prefix[missing] ### Sometimes, it is need to run as command... - command-instead-of-module + ### For not having the playbooks on the root path + - role-name[path] # Ansible-lint does not automatically load rules that have the 'opt-in' tag. # You must enable opt-in rules by listing each rule 'id' below. diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d414d9a..bbd7344 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,99 +1,123 @@ image: python:3.10.15-bullseye -# image: ansible:latest variables: - TEST_VAR_BUILD: "Building the application..." - DOC_PATH_TMP: tmp_docs - DOC_NAME: c3InfoDesk Printing - DOC_AUTHOR: fejao - DOC_VERSION: 1.0.0 - DOC_LANGUAGE: english - # DOC_RETENTION: 1 day # <--- DON'T WORK :( + AUTHOR: fejao ##### ##### ##### - PLAYBOOK_NAME_FOR_ROLE_TEST: "playbook_example_01_test.yml" - PLAYBOOK_NAME_FOR_ROLE_DEPENDENCIES: "playbook_example_02_dependencies.yml" - PLAYBOOK_NAME_FOR_ROLE_CLONE_REPOSITORIES: "playbook_example_03_clone_repositories.yml" - PLAYBOOK_NAME_FOR_ROLE_DOCKER_IMAGES: "playbook_example_04_docker_images.yml" - PLAYBOOK_NAME_FOR_ROLE_DOCKER_CONTAINERS: "playbook_example_05_docker_containers.yml" + INVENTORIES_PATH: "inventories/hosts" + PLAYBOOK_PATH_FOR_ROLE_TEST: "ci-cd/01_test.yml" + PLAYBOOK_PATH_FOR_ROLE_DEPENDENCIES: "ci-cd/02_dependencies.yml" + PLAYBOOK_PATH_FOR_ROLE_CLONE_REPOSITORIES: "ci-cd/03_clone_repositories.yml" + PLAYBOOK_PATH_FOR_ROLE_DOCKER_IMAGES: "ci-cd/04_docker_images.yml" + PLAYBOOK_PATH_FOR_ROLE_DOCKER_CONTAINERS: "ci-cd/05_docker_containers.yml" stages: - - debug - - build - - test + - syntax-check - lint-tests - - docs - - deploy ### -### DEBUG +### SYNTAX-CHECK ### -runner-debug: - stage: debug +syntax-check-test: + stage: syntax-check + 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 "Testing local gitlab-runner config..." - - echo $PWD - - echo "list local folder..." - - ls -hal + - 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 -### -### BUILD -### -build: - stage: build +syntax-check-dependencies: + stage: syntax-check + 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-check-clone-repositories: + stage: syntax-check + 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 "Here should be the images build and pushed" + - 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-check-docker-images: + stage: syntax-check + 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-check-docker-containers: + stage: syntax-check + 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 ### -### TESTS +### LINT-TESTS ### role-test: stage: lint-tests before_script: - apt-get update && apt-get install -y python3-pip && apt-get clean && rm -rf /var/lib/apt/lists/* - - pip3 install -r requirements.txt + - pip3 install -r ci-cd/requirements.txt script: - echo "Running ansible-lint tests at the role-> 'test'" - - ansible-lint $PLAYBOOK_NAME_FOR_ROLE_TEST + - ansible-lint $PLAYBOOK_PATH_FOR_ROLE_TEST allow_failure: false role-dependencies: stage: lint-tests before_script: - apt-get update && apt-get install -y python3-pip && apt-get clean && rm -rf /var/lib/apt/lists/* - - pip3 install -r requirements.txt + - pip3 install -r ci-cd/requirements.txt script: - echo "Running ansible-lint tests at the role-> 'dependencies'" - - ansible-lint $PLAYBOOK_NAME_FOR_ROLE_DEPENDENCIES + - ansible-lint $PLAYBOOK_PATH_FOR_ROLE_DEPENDENCIES allow_failure: false role-clone-repositories: stage: lint-tests before_script: - apt-get update && apt-get install -y python3-pip && apt-get clean && rm -rf /var/lib/apt/lists/* - - pip3 install -r requirements.txt + - pip3 install -r ci-cd/requirements.txt script: - echo "Running ansible-lint tests at the role-> 'clone_repositories'" - - ansible-lint $PLAYBOOK_NAME_FOR_ROLE_CLONE_REPOSITORIES + - ansible-lint $PLAYBOOK_PATH_FOR_ROLE_CLONE_REPOSITORIES allow_failure: false role-docker-images: stage: lint-tests before_script: - apt-get update && apt-get install -y python3-pip && apt-get clean && rm -rf /var/lib/apt/lists/* - - pip3 install -r requirements.txt + - pip3 install -r ci-cd/requirements.txt script: - echo "Running ansible-lint tests at the role-> 'docker_images'" - - ansible-lint $PLAYBOOK_NAME_FOR_ROLE_DOCKER_IMAGES + - ansible-lint $PLAYBOOK_PATH_FOR_ROLE_DOCKER_IMAGES allow_failure: false role-docker-containers: stage: lint-tests before_script: - apt-get update && apt-get install -y python3-pip && apt-get clean && rm -rf /var/lib/apt/lists/* - - pip3 install -r requirements.txt + - pip3 install -r ci-cd/requirements.txt script: - echo "Running ansible-lint tests at the role-> 'docker_containers'" - - ansible-lint $PLAYBOOK_NAME_FOR_ROLE_DOCKER_CONTAINERS + - ansible-lint $PLAYBOOK_PATH_FOR_ROLE_DOCKER_CONTAINERS allow_failure: false diff --git a/README.md b/README.md index 7e13159..55f5cee 100644 --- a/README.md +++ b/README.md @@ -8,12 +8,14 @@ - [x] clone_repositories - [x] docker_images - [x] docker_containers -- [ ] Set ansible-lint for the roles. +- [x] Set ansible-lint for the roles. ## What is this? This is a repo for deploying the the printer system used at the c3infodesk for printing EXTREMILY NECESSARY documents. +## Dependencies +To have [ansible](https://docs.ansible.com/ansible/latest/installation_guide/installation_distros.html) installed at your system. ## Roles Here are the used roles: @@ -31,9 +33,22 @@ Here are the used roles: - 3. Run the playbooks - Example for deploying the containers at the target: ```bash - ansible-playbook -i inventories/hosts playbook_example_05_docker_containers.yml + ansible-playbook -i inventories/hosts playbooks/examples/example_05_docker_containers.yml + ``` +- 4. Change the default environment variables setted from the [docker-compose.yml](https://git.cccv.de/fejao/c3infodesk-printer/-/blob/main/docker/docker-compose.yml) file to your needs and recreate the containers. You might need to login at the **target** for doing it so. + +## Local testing +At the moment, the only tests setted CI-CD are. +- ansible-playbook syntax-check + - + ```bash + ansible-playbook --syntax-check -i <YOUR_INVENTORY> <YOUR_PLAYBOOK_NAME> + ``` +- ansible-lint + - + ```bash + ansible-lint <YOUR_PLAYBOOK_NAME> ``` -- 4. Change the default environment variables setted from the [docker-compose.yml](https://git.cccv.de/fejao/c3infodesk-printer/-/blob/main/docker/docker-compose.yml) file to your needs and recreate the containers. ## License diff --git a/playbook_example_01_test.yml b/ci-cd/01_test.yml similarity index 51% rename from playbook_example_01_test.yml rename to ci-cd/01_test.yml index da345d6..eb8a83f 100644 --- a/playbook_example_01_test.yml +++ b/ci-cd/01_test.yml @@ -1,8 +1,8 @@ --- # Runs the role test -- name: Playbook for running the role 'test' +- name: CI-CD playbook for running the role 'test' hosts: - example_servers_group roles: - - test + - roles/test diff --git a/ci-cd/02_dependencies.yml b/ci-cd/02_dependencies.yml new file mode 100644 index 0000000..f527b2b --- /dev/null +++ b/ci-cd/02_dependencies.yml @@ -0,0 +1,8 @@ +--- +# Runs example for + +- name: CI-CD playbook for running the role 'dependencies' + hosts: + - example_servers_group + roles: + - roles/dependencies diff --git a/ci-cd/03_clone_repositories.yml b/ci-cd/03_clone_repositories.yml new file mode 100644 index 0000000..49d7171 --- /dev/null +++ b/ci-cd/03_clone_repositories.yml @@ -0,0 +1,8 @@ +--- +# Runs example for + +- name: CI-CD playbook for running the role 'clone_repositories' + hosts: + - example_servers_group + roles: + - roles/clone_repositories diff --git a/ci-cd/04_docker_images.yml b/ci-cd/04_docker_images.yml new file mode 100644 index 0000000..9425ffc --- /dev/null +++ b/ci-cd/04_docker_images.yml @@ -0,0 +1,8 @@ +--- +# Runs example for + +- name: CI-CD playbook for running the role 'docker_images' + hosts: + - example_servers_group + roles: + - roles/docker_images diff --git a/playbook_example_05_docker_containers.yml b/ci-cd/05_docker_containers.yml similarity index 68% rename from playbook_example_05_docker_containers.yml rename to ci-cd/05_docker_containers.yml index c6b865c..eb32d54 100644 --- a/playbook_example_05_docker_containers.yml +++ b/ci-cd/05_docker_containers.yml @@ -1,10 +1,10 @@ --- -- name: Playbook for running the role 'docker_containers' +- name: CI-CD playbook for running the role 'docker_containers' hosts: - example_servers_group roles: - - role: docker_containers + - role: roles/docker_containers vars: c3infodesk_printer_host_cups_disable: true c3infodesk_printer_host_cups_mask: true diff --git a/requirements.txt b/ci-cd/requirements.txt similarity index 100% rename from requirements.txt rename to ci-cd/requirements.txt diff --git a/files/README.md b/files/README.md new file mode 100644 index 0000000..ec16116 --- /dev/null +++ b/files/README.md @@ -0,0 +1,4 @@ +# Files + +## Adding files +If you need to add files, use this folder diff --git a/playbook_example_02_dependencies.yml b/playbook_example_02_dependencies.yml deleted file mode 100644 index d9c9808..0000000 --- a/playbook_example_02_dependencies.yml +++ /dev/null @@ -1,8 +0,0 @@ ---- -# Runs example for - -- name: Playbook for running the role 'dependencies' - hosts: - - example_servers_group - roles: - - dependencies diff --git a/playbook_example_03_clone_repositories.yml b/playbook_example_03_clone_repositories.yml deleted file mode 100644 index 1aff7a5..0000000 --- a/playbook_example_03_clone_repositories.yml +++ /dev/null @@ -1,8 +0,0 @@ ---- -# Runs example for - -- name: Playbook for running the role 'clone_repositories' - hosts: - - example_servers_group - roles: - - clone_repositories diff --git a/playbooks/README.md b/playbooks/README.md new file mode 100644 index 0000000..87bc50b --- /dev/null +++ b/playbooks/README.md @@ -0,0 +1,4 @@ +# Playbooks + +## Using the playbooks +foo diff --git a/playbooks/examples/example_01_test.yml b/playbooks/examples/example_01_test.yml new file mode 100644 index 0000000..6580445 --- /dev/null +++ b/playbooks/examples/example_01_test.yml @@ -0,0 +1,8 @@ +--- +# Runs the role test + +- name: Example playbook for running the role 'test' + hosts: + - example_servers_group + roles: + - roles/test diff --git a/playbooks/examples/example_02_dependencies.yml b/playbooks/examples/example_02_dependencies.yml new file mode 100644 index 0000000..9d881c1 --- /dev/null +++ b/playbooks/examples/example_02_dependencies.yml @@ -0,0 +1,8 @@ +--- +# Runs example for + +- name: Example playbook for running the role 'dependencies' + hosts: + - example_servers_group + roles: + - roles/dependencies diff --git a/playbooks/examples/example_03_clone_repositories.yml b/playbooks/examples/example_03_clone_repositories.yml new file mode 100644 index 0000000..e0fd12f --- /dev/null +++ b/playbooks/examples/example_03_clone_repositories.yml @@ -0,0 +1,8 @@ +--- +# Runs example for + +- name: Example playbook for running the role 'clone_repositories' + hosts: + - example_servers_group + roles: + - roles/clone_repositories diff --git a/playbook_example_04_docker_images.yml b/playbooks/examples/example_04_docker_images.yml similarity index 59% rename from playbook_example_04_docker_images.yml rename to playbooks/examples/example_04_docker_images.yml index 334f978..154d3d3 100644 --- a/playbook_example_04_docker_images.yml +++ b/playbooks/examples/example_04_docker_images.yml @@ -1,7 +1,7 @@ --- # Runs example for -- name: Playbook for running the role 'docker_images' +- name: Example playbook for running the role 'docker_images' hosts: - example_servers_group roles: diff --git a/playbooks/examples/example_05_docker_containers.yml b/playbooks/examples/example_05_docker_containers.yml new file mode 100644 index 0000000..54c92cd --- /dev/null +++ b/playbooks/examples/example_05_docker_containers.yml @@ -0,0 +1,11 @@ +--- + +- name: Example playbook for running the role 'docker_containers' + hosts: + - example_servers_group + roles: + - role: roles/docker_containers + vars: + c3infodesk_printer_host_cups_disable: true + c3infodesk_printer_host_cups_mask: true + c3infodesk_printer_docker_compose_up: true diff --git a/roles/clone_repositories/README.md b/roles/clone_repositories/README.md index 515d8e2..c0fcdfa 100644 --- a/roles/clone_repositories/README.md +++ b/roles/clone_repositories/README.md @@ -36,14 +36,14 @@ The role dependencies are: ## Example Playbook - ### Using the provided example - For using the playbook **playbook_example_03_clone_repositories.yml** file you only nned to: + For using the playbook **playbooks/examples/example_03_clone_repositories.yml** file you only need to: - Change the user at the **ansible.cfg** file at the field **remote_user** for acessing your target. - Update the file **inventories/host_vars/example_server.yml** and change the value for **ansible_become_pass** from the **remote_user** - Update the **inventories/hosts** file and change the **example_server** with the IP address from your target. And run the command: ```bash -ansible-playbook -i inventories/hosts playbook_example_03_clone_repositories.yml +ansible-playbook -i inventories/hosts playbooks/examples/example_03_clone_repositories.yml ``` - ### Setting your own example diff --git a/roles/clone_repositories/meta/main.yml b/roles/clone_repositories/meta/main.yml index 3488600..5d54698 100644 --- a/roles/clone_repositories/meta/main.yml +++ b/roles/clone_repositories/meta/main.yml @@ -5,7 +5,7 @@ galaxy_info: description: Role to clone the repositories used from c3InfoDesk sytems author: fejao company: cccv.de - license: MIT + license: "MIT / BSD" min_ansible_version: '2.10' galaxy_tags: [] diff --git a/roles/dependencies/README.md b/roles/dependencies/README.md index ac95b38..7ebf647 100644 --- a/roles/dependencies/README.md +++ b/roles/dependencies/README.md @@ -78,14 +78,14 @@ This role have no dependency from any another role. ## Example Playbook - ### Using the provided example - For using the playbook **playbook_example_02_dependencies.yml** file you only nned to: + For using the example playbook **playbooks/examples/example_02_dependencies.yml** file you only need to: - Change the user at the **ansible.cfg** file at the field **remote_user** for acessing your target. - Update the file **inventories/host_vars/example_server.yml** and change the value for **ansible_become_pass** from the **remote_user** - Update the **inventories/hosts** file and change the **example_server** with the IP address from your target. And run the command: ```bash -ansible-playbook -i inventories/hosts playbook_example_02_dependencies.yml +ansible-playbook -i inventories/hosts playbooks/examples/example_02_dependencies.yml ``` - ### Setting your own example diff --git a/roles/dependencies/meta/main.yml b/roles/dependencies/meta/main.yml index 69e69d0..38d2833 100644 --- a/roles/dependencies/meta/main.yml +++ b/roles/dependencies/meta/main.yml @@ -5,7 +5,7 @@ galaxy_info: description: Role to install the dependencies from the c3InfoDesk sytems author: fejao company: cccv.de - license: MIT + license: "MIT / BSD" min_ansible_version: '2.10' galaxy_tags: [] diff --git a/roles/docker_containers/README.md b/roles/docker_containers/README.md index cf87bd9..416d0db 100644 --- a/roles/docker_containers/README.md +++ b/roles/docker_containers/README.md @@ -75,14 +75,14 @@ The role dependencies are: The **docker-compose.yml** file can be founded at the location setted from the **c3infodesk_printer_folder** path variable. The default is: **"~/Coding/c3infodesk-printer"** folder - ### Using the provided example - For using the playbook **playbook_example_05_docker_containers.yml** file you only nned to: + For using the playbook **playbooks/examples/playbook_example_05_docker_containers.yml** file you only need to: - Change the user at the **ansible.cfg** file at the field **remote_user** for acessing your target. - Update the file **inventories/host_vars/example_server.yml** and change the value for **ansible_become_pass** from the **remote_user**. - Update the **inventories/hosts** file and change the **example_server** with the IP address from your target. And run the command: ```bash - ansible-playbook -i inventories/hosts playbook_example_05_docker_containers.yml + ansible-playbook -i inventories/hosts playbooks/examples/05_docker_containers.yml ``` - ### Setting your own example @@ -134,7 +134,7 @@ The role dependencies are: ansible-playbook -i <INVENTORY> <PLAYBOOK_NAME>.yml ``` - Or you can also pass it using the **role variables**. So your playbook file should looks like: + Or you can also pass it using the **role variables**. So your playbook file should looks like: ```yaml - hosts: diff --git a/roles/docker_containers/meta/main.yml b/roles/docker_containers/meta/main.yml index 9b2e1cd..d5ec064 100644 --- a/roles/docker_containers/meta/main.yml +++ b/roles/docker_containers/meta/main.yml @@ -5,7 +5,7 @@ galaxy_info: description: Role to work with the containers for the c3InfoDesk sytems author: fejao company: cccv.de - license: MIT + license: "MIT / BSD" min_ansible_version: '2.10' galaxy_tags: [] diff --git a/roles/docker_images/README.md b/roles/docker_images/README.md index 39568d4..f83f5c6 100644 --- a/roles/docker_images/README.md +++ b/roles/docker_images/README.md @@ -58,14 +58,14 @@ The role dependencies are: ## Example Playbook - ### Using the provided example - For using the playbook **playbook_example_04_docker_images.yml** file you only nned to: + For using the playbook **playbook/examples/example_04_docker_images.yml** file you only need to: - Change the user at the **ansible.cfg** file at the field **remote_user** for acessing your target. - Update the file **inventories/host_vars/example_server.yml** and change the value for **ansible_become_pass** from the **remote_user** - Update the **inventories/hosts** file and change the **example_server** with the IP address from your target. And run the command: ```bash -ansible-playbook -i inventories/hosts playbook_example_04_docker_images.yml +ansible-playbook -i inventories/hosts playbooks/examples/example_04_docker_images.yml ``` - ### Setting your own example diff --git a/roles/docker_images/meta/main.yml b/roles/docker_images/meta/main.yml index dc928c1..42a845a 100644 --- a/roles/docker_images/meta/main.yml +++ b/roles/docker_images/meta/main.yml @@ -5,7 +5,7 @@ galaxy_info: description: Role to clone the repositories used from c3InfoDesk sytems author: fejao company: cccv.de - license: MIT + license: "MIT / BSD" min_ansible_version: '2.10' galaxy_tags: [] -- GitLab