diff --git a/.ansible-lint b/.ansible-lint index c381cc1e12af61c9c60a29d3b87855108c21d004..751568dee0388623f91a94a8afb95fcf3cf1a66d 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 d414d9a652c61cc3231668364469cfcd363c4581..bbd7344600e011107766d42b521651865932163d 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 7e13159860dfb865d5b9359d1fe6d2b9794c3c70..55f5cee3bc109d2713ba365091207e57b4f9122d 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 da345d6b87c83e3cfd325205738a2eb92f4c34ab..eb8a83f2b53520967da4ad4d6647bf459d2b5043 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 0000000000000000000000000000000000000000..f527b2b4b90fe550095e979a10016f82ce2833cd --- /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 0000000000000000000000000000000000000000..49d71717374abd473eebce24150353c14f53630c --- /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 0000000000000000000000000000000000000000..9425ffceec9e2bce3ae69a42ff34e56c1f0a6f91 --- /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 c6b865cc581a62caf49fa509a60710c10ae95780..eb32d54344edc2850cb4850851a892a485591cd6 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 0000000000000000000000000000000000000000..ec161160a39a1eb8587ebc7f1420e1e6809e86d8 --- /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 d9c9808e98d2c474b41df434b4d1a782c3da9425..0000000000000000000000000000000000000000 --- 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 1aff7a5ea0a3a59e222994495c3dcd921e6b849c..0000000000000000000000000000000000000000 --- 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 0000000000000000000000000000000000000000..87bc50b27b96515f6fce0c50d09da47516e32a39 --- /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 0000000000000000000000000000000000000000..6580445dfeafbac7a486d833833bbd8c7d54f534 --- /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 0000000000000000000000000000000000000000..9d881c10a58e889d10b41e5a54c33565a585362b --- /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 0000000000000000000000000000000000000000..e0fd12f69b182489cc9385f8d8fd8aea07eb0987 --- /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 334f978bf48e819f43a91ba915d94136a3b40a9e..154d3d3cf553b530cfd9aa4d49618ec3a9f8e489 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 0000000000000000000000000000000000000000..54c92cd761e136546c68a6e98f8dbb71af54f843 --- /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 515d8e2062e899fc6a497d54b1ea1c04228f8c2d..c0fcdfab9ccf1010845a73f0401eb7cd5a6888dc 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 3488600d07e9c509d125d960dd42689b5761ca15..5d546986e2fb021e7fe83461ea27971b77b40b31 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 ac95b38aa9f1d4d0b088f9709587458dda590c43..7ebf6474b9752db92e9a45c13c92b1beff12c47c 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 69e69d09a3764cbf3135f758d646edaf8f79a85b..38d2833842ee1e86498fa393be66c0f392468926 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 cf87bd9ae3d237868dc6cfbd601192456dae6f7d..416d0db580ca3a17da3a5d926ab1e0447ebde8e2 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 9b2e1cd4a8cf34ddac7043e42fb4c9d0524e8741..d5ec0643af26fc7bac76ccfe4f0db54b46d85405 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 39568d46950734b8b95fbf3b00626013eb5304a9..f83f5c6e8ee3e1310bb1ea4ae6b2e319c0570720 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 dc928c134114eb763c6e4cba203221d1e45b2153..42a845ad636ee64bc2eb061d6d718bad0994c693 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: []