diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c4e7fd9fec2a44586f3ea0ea8f095267f41f355e..cfc917a1905ea9e56bfa99fe8d2e389b217fb6c7 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -64,17 +64,6 @@ include: - local: ci-cd/templates/all-roles-b4-merge.yml rules: - if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "main" - # - if: $CI_COMMIT_REF_NAME == "main" - #### - # rules: - # ### WORKS - # # - if: $CI_COMMIT_REF_NAME == "main" - # ### - # # - if: $CI_PIPELINE_SOURCE == "merge_request_event" - # ### - # # - if: '$CI_PIPELINE_SOURCE == "push" || $CI_PIPELINE_SOURCE == "merge_request_event"' - # #### - # - if: $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_APPROVED == true ### ### TEST PARSED VARS FROM UPSTREAM diff --git a/.gitmodules b/.gitmodules index 86c8d23b1db58cb5f4241af8b756df6053cacf6d..5f283b72243acc71ba946bfdfc55a3ad3c5d611d 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,3 +10,6 @@ [submodule "roles/c3infodesk-deployment-role-docker-images"] path = roles/c3infodesk-deployment-role-docker-images url = git@git.cccv.de:fejao/c3infodesk-deployment-role-docker-images.git +[submodule "roles/c3infodesk-deployment-role-docker-containers"] + path = roles/c3infodesk-deployment-role-docker-containers + url = git@git.cccv.de:fejao/c3infodesk-deployment-role-docker-containers.git diff --git a/ci-cd/playbooks/05_docker_containers.yml b/ci-cd/playbooks/05_docker_containers.yml index eb32d54344edc2850cb4850851a892a485591cd6..a60022a484fb5a887da3b08e1bfc3a2ef367de04 100644 --- a/ci-cd/playbooks/05_docker_containers.yml +++ b/ci-cd/playbooks/05_docker_containers.yml @@ -4,7 +4,8 @@ hosts: - example_servers_group roles: - - role: roles/docker_containers + # - role: roles/docker_containers + - role: roles/c3infodesk-deployment-role-docker-images vars: c3infodesk_printer_host_cups_disable: true c3infodesk_printer_host_cups_mask: true diff --git a/ci-cd/templates/all-roles-b4-merge.yml b/ci-cd/templates/all-roles-b4-merge.yml index 06911f9188c119753899c88beafba33d69ced0ec..bd7b10170bce9e8fbe87ae8cbdb7adacf2623944 100644 --- a/ci-cd/templates/all-roles-b4-merge.yml +++ b/ci-cd/templates/all-roles-b4-merge.yml @@ -14,5 +14,5 @@ include: - local: ci-cd/templates/role-dependencies.yml - local: ci-cd/templates/role-clone-repositories.yml - local: ci-cd/templates/role-docker-images.yml - # - local: ci-cd/templates/role-docker-containers.yml + - local: ci-cd/templates/role-docker-containers.yml # - local: ci-cd/templates/role-oh-my-bash.yml diff --git a/roles/c3infodesk-deployment-role-docker-containers b/roles/c3infodesk-deployment-role-docker-containers new file mode 160000 index 0000000000000000000000000000000000000000..c027f03ed45fe3ee0c2d19e14ddc1513c660a8f3 --- /dev/null +++ b/roles/c3infodesk-deployment-role-docker-containers @@ -0,0 +1 @@ +Subproject commit c027f03ed45fe3ee0c2d19e14ddc1513c660a8f3 diff --git a/roles/docker_containers/README.md b/roles/docker_containers/README.md deleted file mode 100644 index 10fbf22262a0c88fff0c742f5d31a7cc1dcf7f69..0000000000000000000000000000000000000000 --- a/roles/docker_containers/README.md +++ /dev/null @@ -1,212 +0,0 @@ -# docker-containers role - -This is a ansible-role for dealing with the containers from **c3infodesk**. - -## Requirements -- To have [ansible](https://docs.ansible.com/ansible/latest/installation_guide/installation_distros.html) installed at your system. - - -## Configuration -You need to set some configuration for this to work -- ### ansible.cfg - You have to edit the **ansible.cfg** file to your needs for accessing your target. - - #### remote_user - You need to set the **remote_user** configuration for accessing the target host. - - Example: [remote_user](https://git.cccv.de/fejao/c3infodesk-deployment/-/blob/main/ansible.cfg#L227) - -- ### HOST_VARS - In order to access your target host, you need to create/edit your **inventories/host_vars/<YOUR_HOST_NAME>.yml** - - #### ansible_become_pass - You need to set the **sudo** password from the user setted on **remote_user** for installing packages and etc. at the target. - - Example: [ansible_become_pass](https://git.cccv.de/fejao/c3infodesk-deployment/-/blob/main/inventories/host_vars/example_server.yml#L5) - -- ### HOSTS - You need to provide a group in which your target belongs to with the same name setted for **inventories/host_vars/<YOUR_HOST_NAME>.yml**. - - There you can add/edit the target address/IP. - - Example: [hosts](https://git.cccv.de/fejao/c3infodesk-deployment/-/blob/main/inventories/hosts) - - -## Role Variables -Here are the variables to setted from this role: - -- ### From: inventories/host_vars/<TARGET_NAME> - Here are the variables that you should be changing for your own deployment. - - - #### CUPS - Here you can set the variables if you want to **disable** and/or **mask** the CUPS service at the target. - - **c3infodesk_printer_host_cups_disable**: DEFAULT=<NOT_SETTED> - - **c3infodesk_printer_host_cups_mask**: DEFAULT=<NOT_SETTED> - - #### COMPOSE - Here you can set the variables if you want to set the **docker compose command** to up/stop/restart/down - - **c3infodesk_printer_docker_compose_up**: DEFAULT=<NOT_SETTED> - - **c3infodesk_printer_docker_compose_stop**: DEFAULT=<NOT_SETTED> - - **c3infodesk_printer_docker_compose_restart**: DEFAULT=<NOT_SETTED> - - **c3infodesk_printer_docker_compose_down**: DEFAULT=<NOT_SETTED> - -- ### From: inventories/group_vars/<TARGET_GROUP> - Please don't cahnge the default values at this file. If you need to update them, use the **inventories/host_vars/<TARGET_NAME>** file. - - At the moment, there's **NO VARIABLES** setted at the **group_vars** for this role. - -- ### From: roles/clone-repositories/defaults/main.yml - Don't change the values at this file, if you need to change them, change it at the **inventories/host_vars/<TARGET_NAME>** file - - #### CUPS - - **c3infodesk_printer_host_cups_disable**: DEFAULT=false - - If you want to disable the CUPS service at the target system - - **c3infodesk_printer_host_cups_disable_debug**: DEFAULT=false - - If you want to debug disabling CUPS at the target system - - **c3infodesk_printer_host_cups_mask**: DEFAULT=false - - If you want to mask the CUPS service at the target system - - #### COMPOSE UP - - **c3infodesk_printer_docker_compose_up**: DEFAULT=false - - If you want to run the command: "docker compose up" at the target host - - **c3infodesk_printer_docker_compose_up_debug**: DEFAULT=false - - If you want to debug running the command: "docker compose up" at the target host - - #### COMPOSE STOP - - **c3infodesk_printer_docker_compose_stop**: DEFAULT=false - - If you want to run the command: "docker compose stop" at the target host - - **c3infodesk_printer_docker_compose_stop_debug**: DEFAULT=false - - If you want to debug running the command: "docker compose stop" at the target host - - #### COMPOSE RESTART - - **c3infodesk_printer_docker_compose_restart**: DEFAULT=false - - If you want to run the command: "docker compose restart" at the target host - - **c3infodesk_printer_docker_compose_restart_debug**: DEFAULT=false - - If you want to debug running the command: "docker compose restart" at the target host - - #### COMPOSE DOWN - - **c3infodesk_printer_docker_compose_down**: DEFAULT=false - - If you want to run the command: "docker compose down" at the target host - - **c3infodesk_printer_docker_compose_down_debug**: DEFAULT=false - - If you want to debug running the command: "docker compose down" at the target host - - -## Dependencies -The role dependencies are: - - [dependencies(role)](roles/dependencies/README.md) - - [clone_repositories](roles/clone_repositories/README.md) - - [docker_images](roles/docker_images/README.md) - - -## Example Playbook - -- ### What this example will deploy - This role will deploy all the containers setted on the [docker-compose.yml](https://git.cccv.de/fejao/c3infodesk-printer/-/blob/main/docker/docker-compose.yml) file. - **PLEASE CHANGE THE VALEUS** setted at this file on the target to your own. - - 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 example playbook **[playbooks/examples/example_05_docker_containers.yml](https://git.cccv.de/fejao/c3infodesk-deployment/-/blob/main/playbooks/examples/example_05_docker_containers.yml)** file you only need to: - - Change the user at the **[ansible.cfg](https://git.cccv.de/fejao/c3infodesk-deployment/-/blob/main/ansible.cfg)** file at the field **[remote_user](https://git.cccv.de/fejao/c3infodesk-deployment/-/blob/main/ansible.cfg#L227)** for acessing your target. - - Update the file **[inventories/host_vars/example_server.yml](https://git.cccv.de/fejao/c3infodesk-deployment/-/blob/main/inventories/host_vars/example_server.yml)** and change the value for **[ansible_become_pass](https://git.cccv.de/fejao/c3infodesk-deployment/-/blob/main/inventories/host_vars/example_server.yml#L5)** from the **[remote_user](https://git.cccv.de/fejao/c3infodesk-deployment/-/blob/main/ansible.cfg#L227)** - - Update the **[inventories/hosts](https://git.cccv.de/fejao/c3infodesk-deployment/-/blob/main/inventories/hosts)** file and change the **[example_server](https://git.cccv.de/fejao/c3infodesk-deployment/-/blob/main/inventories/hosts#L2)** with the IP address from your target. - - - And run the command: - ```bash - ansible-playbook -i inventories/hosts playbooks/examples/05_docker_containers.yml - ``` - -- ### Setting your own example - - - #### Deploying a new system example - After setting your variables at **inventories/host_vars/<HOST_NAME>**, you can add this role to your playbook as a regular role. - - Here is an example using the **<HOST_NAME>** as **test_servers** - - You will need to set this variables fro a new deployment: - - **c3infodesk_printer_host_cups_disable**: true - - **c3infodesk_printer_host_cups_mask**: true - - **c3infodesk_printer_docker_compose_up**: true - - ```yaml - - 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 - ``` - - And call the playbook as: - ```bash - ansible-playbook -i <INVENTORY> <PLAYBOOK_NAME>.yml - ``` - - - #### Restarting the containers example - - Here is an example for adding this role for your playbook for **restarting** the **c3infodesk-printer** containers: - - We are using the **<HOST_NAME>** as **test_servers** for example. - - ```yaml - - hosts: - - test_servers - roles: - - role: roles/docker-containers - vars: - printer_docker_compose_restart: true - ``` - - And call the playbook as: - - ```bash - ansible-playbook -i <INVENTORY> <PLAYBOOK_NAME>.yml - ``` - - Or you can also pass it using the **role variables**. So your playbook file should looks like: - - ```yaml - - hosts: - - test_servers - roles: - - roles/docker-containers - ``` - - And call it passing the variable, for example, restarting the containers from **c3infodesk-printer**. - ```bash - ansible-playbook -i <INVENTORY> <PLAYBOOK_NAME>.yml --extra-vars "printer_docker_compose_restart=true" - ``` - - -## Testing -You can test this locally using **DIND (docker in docker)** at your own computer using [ansible molecule](https://ansible.readthedocs.io/projects/molecule/installation/) - -- ### Testing requirements - You need docker installed at your system and the [ansible molecule](https://ansible.readthedocs.io/projects/molecule/installation/). - - You might have to set DIND at your system, for linux, you can create the file **/etc/docker/daemon.json** - - And add the content and restart docker. - - ```json - { - "exec-opts": ["native.cgroupdriver=systemd"], - "features": { - "buildkit": true - }, - "experimental": true, - "cgroup-parent": "docker.slice" - } - ``` - -- ### Using molecule - Just go to the root of the role **roles/dependencies** and run the command: - - ```bash - molecule test - ``` - - -## License - -MIT / BSD - - -## Author Information - [https://chaos.social/@fejao](https://chaos.social/@fejao) diff --git a/roles/docker_containers/defaults/main.yml b/roles/docker_containers/defaults/main.yml deleted file mode 100644 index 905d5d658cb72802a59dd0620f7d756b95c3c7f6..0000000000000000000000000000000000000000 --- a/roles/docker_containers/defaults/main.yml +++ /dev/null @@ -1,26 +0,0 @@ ---- -# defaults file for docker-containers - -# c3infodesk_project_src: "PLEASE SET THIS VARIABLE" - -### -### c3InfoDesk Printer -### - -### CUPS -c3infodesk_printer_host_cups_disable: false -c3infodesk_printer_host_cups_disable_debug: false -c3infodesk_printer_host_cups_mask: false - -### COMPOSE UP -c3infodesk_printer_docker_compose_up: false -c3infodesk_printer_docker_compose_up_debug: false -### COMPOSE STOP -c3infodesk_printer_docker_compose_stop: false -c3infodesk_printer_docker_compose_stop_debug: false -### COMPOSE RESTART -c3infodesk_printer_docker_compose_restart: false -c3infodesk_printer_docker_compose_restart_debug: false -### COMPOSE DOWN -c3infodesk_printer_docker_compose_down: false -c3infodesk_printer_docker_compose_down_debug: false diff --git a/roles/docker_containers/meta/main.yml b/roles/docker_containers/meta/main.yml deleted file mode 100644 index d5ec0643af26fc7bac76ccfe4f0db54b46d85405..0000000000000000000000000000000000000000 --- a/roles/docker_containers/meta/main.yml +++ /dev/null @@ -1,18 +0,0 @@ ---- - -galaxy_info: - role_name: docker_containers - description: Role to work with the containers for the c3InfoDesk sytems - author: fejao - company: cccv.de - license: "MIT / BSD" - min_ansible_version: '2.10' - galaxy_tags: [] - -# dependencies: [] - # List your role dependencies here, one per line. Be sure to remove the '[]' above, - # if you add dependencies to this list. -dependencies: - - role: dependencies - - role: clone_repositories - - role: docker_images diff --git a/roles/docker_containers/molecule/README.md b/roles/docker_containers/molecule/README.md deleted file mode 100644 index 4e02fc32861788f357b8d26e017c3718081b32e3..0000000000000000000000000000000000000000 --- a/roles/docker_containers/molecule/README.md +++ /dev/null @@ -1,42 +0,0 @@ -## ansible molecule tests for role: docker_containers - - - -## Why to use it -It's allways a good idea to test your things. - -With **ansible molecule** you can test your role locally without the need of using a **real server** but a local **docker container**. - -## Dependencies - -- ### molecule - You need to have [ansible molecule](https://ansible.readthedocs.io/projects/molecule/installation/) installed. - -- ### DIND (docker in docker) - For using the tests, you will to have **docker** installed locally and and set it for using **DIND (docker in docker)** - - - - ### DIND linux - You have to create/edit the file **/etc/docker/daemon.json** with the content: - - ```json - { - "exec-opts": ["native.cgroupdriver=systemd"], - "features": { - "buildkit": true - }, - "experimental": true, - "cgroup-parent": "docker.slice" - } - ``` - - -## Configuration -There's not much for configuring for using the tests - -## Running the tests -For running the **molecule tests** you just need to run the command: - -```bash -molecule test -``` diff --git a/roles/docker_containers/molecule/default/cleanup.yml b/roles/docker_containers/molecule/default/cleanup.yml deleted file mode 100644 index a0c59f7ae1cfbd233b15f830b43d7b7c4f733c19..0000000000000000000000000000000000000000 --- a/roles/docker_containers/molecule/default/cleanup.yml +++ /dev/null @@ -1,77 +0,0 @@ ---- - -- name: MOLECULE | Cleanup - hosts: all - vars: - package_name_docker: 'docker' - package_name_docker_ce: 'docker-ce' - package_name_docker_compose: 'docker-compose' - package_name_docker_compose_plugin: 'docker-compose-plugin' - container_name_cups: 'c3printing-cups' - container_name_app: 'c3printing-app' - container_name_proxy: 'c3printing-proxy' - container_name_influxdb: 'c3printing-influxdb' - - pre_tasks: - ### - ### VARIABLES - ### - - name: MOLECULE | CLEANUP | PRE-TASKS | VARIABLES | From -> ../../defaults - ansible.builtin.include_vars: - dir: ../../defaults - depth: 1 - extensions: - - 'yml' - - - name: MOLECULE | CLEANUP | PRE-TASKS | VARIABLES | From -> ../../../../roles/dependencies/defaults - ansible.builtin.include_vars: - dir: ../../../../roles/dependencies/defaults - depth: 1 - extensions: - - 'yml' - - - name: MOLECULE | CLEANUP | PRE-TASKS | VARIABLES | From -> ../../../../roles/clone_repositories/defaults - ansible.builtin.include_vars: - dir: ../../../../roles/clone_repositories/defaults - depth: 1 - extensions: - - 'yml' - - - name: MOLECULE | CLEANUP | PRE-TASKS | VARIABLES | From -> ../../../../roles/docker_images/defaults - ansible.builtin.include_vars: - dir: ../../../../roles/docker_images/defaults - depth: 1 - extensions: - - 'yml' - - - name: MOLECULE | CLEANUP | PRE-TASKS | VARIABLES | From -> ../../../../inventories/group_vars - ansible.builtin.include_vars: - dir: ../../../../inventories/group_vars - extensions: - - 'yml' - - - name: MOLECULE | CLEANUP | PRE-TASKS | VARIABLES | From -> ../../../../inventories/host_vars - ansible.builtin.include_vars: - dir: ../../../../inventories/host_vars - extensions: - - 'yml' - - ### - ### DOCKER COMPOSE - ### - - name: MOLECULE | CLEANUP | PRE-TASKS | DOCKER | Remove all running containers. - community.docker.docker_compose_v2: - project_src: "{{ c3infodesk_printer_folder_docker }}" - # state: absent - state: absent - register: ret_docker_compose_down - - - name: MOLECULE | CLEANUP | PRE-TASKS | DOCKER | Output from removing all containers. - ansible.builtin.debug: - var: ret_docker_compose_down - when: c3infodesk_printer_docker_compose_up_debug | bool - - # - name: MOLECULE | CLEANUP | PRE-TASKS | DOCKER | raise error. - # ansible.builtin.debug: - # msg: "ERROR RAISED" - # failed_when: true diff --git a/roles/docker_containers/molecule/default/converge.yml b/roles/docker_containers/molecule/default/converge.yml deleted file mode 100644 index e879983c5ead45931ca4c6b7dbd1a0cf421762c0..0000000000000000000000000000000000000000 --- a/roles/docker_containers/molecule/default/converge.yml +++ /dev/null @@ -1,60 +0,0 @@ ---- - -- name: MOLECULE | Converge - hosts: all - pre_tasks: - ### - ### VARIABLES - ### - - name: MOLECULE | COVERGE | PRE-TASKS | VARIABLES | From -> ../../defaults - ansible.builtin.include_vars: - dir: ../../defaults - depth: 1 - extensions: - - 'yml' - - - name: MOLECULE | CONVERGE | PRE-TASKS | VARIABLES | From -> ../../../../roles/dependencies/defaults - ansible.builtin.include_vars: - dir: ../../../../roles/dependencies/defaults - depth: 1 - extensions: - - 'yml' - - - name: MOLECULE | CONVERGE | PRE-TASKS | VARIABLES | From -> ../../../../roles/clone_repositories/defaults - ansible.builtin.include_vars: - dir: ../../../../roles/clone_repositories/defaults - depth: 1 - extensions: - - 'yml' - - - name: MOLECULE | CONVERGE | PRE-TASKS | VARIABLES | From -> ../../../../roles/docker_images/defaults - ansible.builtin.include_vars: - dir: ../../../../roles/docker_images/defaults - depth: 1 - extensions: - - 'yml' - - - name: MOLECULE | COVERGE | PRE-TASKS | VARIABLES | From -> ../../../../inventories/group_vars - ansible.builtin.include_vars: - dir: ../../../../inventories/group_vars - extensions: - - 'yml' - - - name: MOLECULE | COVERGE | PRE-TASKS | VARIABLES | From -> ../../../../inventories/host_vars - ansible.builtin.include_vars: - dir: ../../../../inventories/host_vars - extensions: - - 'yml' - - - name: MOLECULE | COVERGE | PRE-TASKS | Install python 'requests' package - ansible.builtin.pip: - name: requests - - tasks: - - name: MOLECULE | CONVERGE | Call the 'clone_repositories' role for starting the containers. - vars: - c3infodesk_printer_host_cups_disable: true - c3infodesk_printer_host_cups_mask: true - c3infodesk_printer_docker_compose_up: true - ansible.builtin.include_role: - name: docker_containers diff --git a/roles/docker_containers/molecule/default/molecule.yml b/roles/docker_containers/molecule/default/molecule.yml deleted file mode 100644 index 9f0ed1648ae1810341f18334365227fce2af91b5..0000000000000000000000000000000000000000 --- a/roles/docker_containers/molecule/default/molecule.yml +++ /dev/null @@ -1,68 +0,0 @@ ---- - -dependency: - name: galaxy - -driver: - name: docker - -platforms: - - name: molecule_docker_containers - ### At the moment I'm not running at the latest kernel, please use always with a older kernel than the host - # image: docker.io/geerlingguy/docker-ubuntu2204-ansible - image: geerlingguy/docker-ubuntu2204-ansible:latest - command: /usr/sbin/init - pre_build_image: true - cgroupns_mode: host - privileged: true - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:rw - - /var/lib/containerd - -provisioner: - name: ansible - -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 diff --git a/roles/docker_containers/molecule/default/verify.yml b/roles/docker_containers/molecule/default/verify.yml deleted file mode 100644 index e10ed4d77ce5230dd02ebe76101ebaebe6ba4d3c..0000000000000000000000000000000000000000 --- a/roles/docker_containers/molecule/default/verify.yml +++ /dev/null @@ -1,248 +0,0 @@ ---- - -- name: MOLECULE | Verify - hosts: all - vars: - package_name_docker: 'docker' - package_name_docker_ce: 'docker-ce' - package_name_docker_compose: 'docker-compose' - package_name_docker_compose_plugin: 'docker-compose-plugin' - container_name_cups: 'c3printing-cups' - container_name_app: 'c3printing-app' - container_name_proxy: 'c3printing-proxy' - # container_name_influxdb: 'c3printing-influxdb' - - pre_tasks: - - name: MOLECULE | VERIFY | PRE-TASKS | VARIABLES | From -> ../../defaults - ansible.builtin.include_vars: - dir: ../../defaults - depth: 1 - extensions: - - 'yml' - - - name: MOLECULE | VERIFY | PRE-TASKS | VARIABLES | From -> ../../../../roles/dependencies/defaults - ansible.builtin.include_vars: - dir: ../../../../roles/dependencies/defaults - depth: 1 - extensions: - - 'yml' - - - name: MOLECULE | VERIFY | PRE-TASKS | VARIABLES | From -> ../../../../roles/clone_repositories/defaults - ansible.builtin.include_vars: - dir: ../../../../roles/clone_repositories/defaults - depth: 1 - extensions: - - 'yml' - - - name: MOLECULE | VERIFY | PRE-TASKS | VARIABLES | From -> ../../../../roles/docker_images/defaults - ansible.builtin.include_vars: - dir: ../../../../roles/docker_images/defaults - depth: 1 - extensions: - - 'yml' - - - name: MOLECULE | VERIFY | PRE-TASKS | VARIABLES | From -> ../../../../inventories/group_vars - ansible.builtin.include_vars: - dir: ../../../../inventories/group_vars - extensions: - - 'yml' - - - name: MOLECULE | VERIFY | PRE-TASKS | VARIABLES | From -> ../../../../inventories/host_vars - ansible.builtin.include_vars: - dir: ../../../../inventories/host_vars - extensions: - - 'yml' - - tasks: - ### - ### POPULATE - ### - - name: MOLECULE | VERIFY | POPULATE | Gather the package facts - ansible.builtin.package_facts: - manager: auto - - - name: MOLECULE | VERIFY | POPULATE | Gather service facts - ansible.builtin.service_facts: - - ### - ### TESTS - PACKAGES - ### - - name: MOLECULE | VERIFY | TEST | Check that the packages from 'os_dependencies_packages' are installed. - ansible.builtin.debug: - msg: "Package: '{{ package_name }}' is installed" - loop: "{{ os_dependencies_packages }}" - loop_control: - loop_var: package_name - failed_when: package_name not in ansible_facts.packages - - - name: MOLECULE | VERIFY | TEST | Check that docker is installed. - ansible.builtin.debug: - msg: "Package: 'docker' is installed" - failed_when: - - package_name_docker not in ansible_facts.packages - - package_name_docker_ce not in ansible_facts.packages - - - name: MOLECULE | VERIFY | TEST | Check that docker-compose is installed. - ansible.builtin.debug: - msg: "Package: 'docker-cokmpose' is installed" - failed_when: - - package_name_docker_compose not in ansible_facts.packages - - package_name_docker_compose_plugin not in ansible_facts.packages - - ### - ### TESTS - DOCKER - ### - - name: MOLECULE | VERIFY | TEST | Get docker service state. - ansible.builtin.systemd: - name: "docker" - register: docker_service - - - name: MOLECULE | VERIFY | TEST | Check that docker is running. - ansible.builtin.debug: - msg: "Docker IS running..." - failed_when: "'active' != docker_service.status.ActiveState" - - ### - ### TESTS - ADDED USERS - ### - - name: MOLECULE | VERIFY | TEST | Get added users infos. - ansible.builtin.user: - name: "{{ item }}" - loop: "{{ docker_users }}" - check_mode: true - register: test_users - - - name: MOLECULE | VERIFY | TEST | Check if users exists - ansible.builtin.debug: - msg: "User {{ item.item }} {{ 'exists' if item.state | d('') == 'present' else 'does not exist' }}" - loop: "{{ test_users.results }}" - loop_control: - label: "{{ item.item }}" - - - name: MOLECULE | VERIFY | TEST | Get the groups that the users belongs to. - ansible.builtin.command: - cmd: "id -Gn {{ item.item }}" - loop: "{{ test_users.results }}" - loop_control: - label: "{{ item.item }}" - register: user_groups - changed_when: false - - - name: MOLECULE | VERIFY | TEST | Check that the users are at the 'docker' group. - ansible.builtin.debug: - msg: "User '{{ item.item.item }}' belongs to the docker group" - with_items: "{{ user_groups.results }}" - failed_when: "'docker' not in item.stdout" - - ### - ### TESTS - CLONE REPOSITORY - PRINTER - ### - - name: MOLECULE | VERIFY | TEST | Get if the repository was cloned. - ansible.builtin.git: - repo: "{{ c3infodesk_printer_repo_url }}" - dest: "{{ c3infodesk_printer_folder }}" - version: main - clone: false - update: false - register: check_repository - - - name: MOLECULE | VERIFY | TEST | Checking if the repository was cloned. - ansible.builtin.debug: - msg: "Repository: '{{ c3infodesk_printer_repo_url }}' cloned..." - failed_when: check_repository.changed | bool - - ### - ### TESTS - DOCKER IMAGES - ### - - name: MOLECULE | VERIFY | TEST | Get if the image is created for 'cups'. - community.docker.docker_image_info: - name: "{{ c3infodesk_printer_docker_img_cups_name }}" - register: result_check_image_cups - - - name: MOLECULE | VERIFY | TEST | Check the image creation from 'cups'. - ansible.builtin.debug: - msg: "Image for 'cups' exists" - when: result_check_image_cups.images | length > 0 - - - name: MOLECULE | VERIFY | TEST | Get if the image is created for 'app'. - community.docker.docker_image_info: - name: "{{ c3infodesk_printer_docker_img_app_name }}" - register: result_check_image_app - - - name: MOLECULE | VERIFY | TEST | Check the image creation from 'app'. - ansible.builtin.debug: - msg: "Image for 'app' exists" - when: result_check_image_app.images | length > 0 - - - name: MOLECULE | VERIFY | TEST | Get if the image is created for 'proxy'. - community.docker.docker_image_info: - name: "{{ c3infodesk_printer_docker_img_proxy_name }}" - register: result_check_image_proxy - - - name: MOLECULE | VERIFY | TEST | Check the image creation from 'proxy'. - ansible.builtin.debug: - msg: "Image for 'proxy' exists" - when: result_check_image_proxy.images | length > 0 - - ### - ### TESTS - DOCKER CONTAINERS - CUPS DISABLE - ### - - - name: MOLECULE | VERIFY | TEST | Get that the CUPS service is disable. - ansible.builtin.debug: - msg: "The service: 'cups.service' is not setted" - failed_when: "'cups.service' in ansible_facts.services" - - ### - ### TESTS - DOCKER CONTAINERS - CUPS - ### - - name: MOLECULE | VERIFY | TEST | CONTAINER CUPS | Get infos on the container. - community.docker.docker_container_info: - name: "{{ container_name_cups }}" - register: ret_container_cups - - - name: MOLECULE | VERIFY | TEST | CONTAINER CUPS | Check that the container exists. - ansible.builtin.debug: - msg: "The container '{{ container_name_cups }}' {{ 'exists' if ret_container_cups.exists else 'does not exist' }}" - failed_when: ret_container_cups.exists | bool is not true - - - name: MOLECULE | VERIFY | TEST | CONTAINER CUPS | Check that the container is running. - ansible.builtin.debug: - msg: "The container '{{ container_name_cups }}' is running" - failed_when: ret_container_cups.container.State.Status != 'running' - - ### - ### TESTS - DOCKER CONTAINERS - APP - ### - - name: MOLECULE | VERIFY | TEST | CONTAINER APP | Get infos on the container. - community.docker.docker_container_info: - name: "{{ container_name_app }}" - register: ret_container_app - - - name: MOLECULE | VERIFY | TEST | CONTAINER APP | Check that the container exists. - ansible.builtin.debug: - msg: "The container '{{ container_name_app }}' {{ 'exists' if ret_container_app.exists else 'does not exist' }}" - failed_when: ret_container_app.exists | bool is not true - - - name: MOLECULE | VERIFY | TEST | CONTAINER APP | Check that the container is running. - ansible.builtin.debug: - msg: "The container '{{ container_name_app }}' is running" - failed_when: ret_container_app.container.State.Status != 'running' - - ### - ### TESTS - DOCKER CONTAINERS - PROXY - ### - - name: MOLECULE | VERIFY | TEST | CONTAINER PROXY | Get infos on the container. - community.docker.docker_container_info: - name: "{{ container_name_proxy }}" - register: ret_container_proxy - - - name: MOLECULE | VERIFY | TEST | CONTAINER PROXY | Check that the container exists. - ansible.builtin.debug: - msg: "The container '{{ container_name_proxy }}' {{ 'exists' if ret_container_proxy.exists else 'does not exist' }}" - failed_when: ret_container_proxy.exists | bool is not true - - - name: MOLECULE | VERIFY | TEST | CONTAINER PROXY | Check that the container is running. - ansible.builtin.debug: - msg: "The container '{{ container_name_proxy }}' is running" - failed_when: ret_container_proxy.container.State.Status != 'running' diff --git a/roles/docker_containers/tasks/main.yml b/roles/docker_containers/tasks/main.yml deleted file mode 100644 index b1ca66fc4f6299096b2fccd8a83b1f6f6ed1e1ff..0000000000000000000000000000000000000000 --- a/roles/docker_containers/tasks/main.yml +++ /dev/null @@ -1,22 +0,0 @@ ---- -# tasks file for docker-containers - -- name: Disabling CUPS on target host - ansible.builtin.import_tasks: printer_host_cups_disable.yml - when: c3infodesk_printer_host_cups_disable | bool - -- name: Running printer compose up - ansible.builtin.import_tasks: printer_compose_up.yml - when: c3infodesk_printer_docker_compose_up | bool - -- name: Running printer compose stop - ansible.builtin.import_tasks: printer_compose_stop.yml - when: c3infodesk_printer_docker_compose_stop | bool - -- name: Running printer compose restart - ansible.builtin.import_tasks: printer_compose_restart.yml - when: c3infodesk_printer_docker_compose_restart | bool - -- name: Running printer compose down - ansible.builtin.import_tasks: printer_compose_down.yml - when: c3infodesk_printer_docker_compose_down | bool diff --git a/roles/docker_containers/tasks/printer_compose_down.yml b/roles/docker_containers/tasks/printer_compose_down.yml deleted file mode 100644 index 7f946d0b3a590e578d796146c203250a1ccdf64d..0000000000000000000000000000000000000000 --- a/roles/docker_containers/tasks/printer_compose_down.yml +++ /dev/null @@ -1,13 +0,0 @@ ---- -# tasks file for docker-compose down - -- name: COMPOSE DOWN | Run `docker compose down` - community.docker.docker_compose_v2: - project_src: "{{ c3infodesk_project_src }}" - state: absent - register: ret_docker_compose_down - -- name: COMPOSE DOWN | Output compose down - ansible.builtin.debug: - var: ret_docker_compose_down - when: c3infodesk_printer_docker_compose_down_debug | bool diff --git a/roles/docker_containers/tasks/printer_compose_restart.yml b/roles/docker_containers/tasks/printer_compose_restart.yml deleted file mode 100644 index df26924d9de57d4bd02361a0add84714fe802165..0000000000000000000000000000000000000000 --- a/roles/docker_containers/tasks/printer_compose_restart.yml +++ /dev/null @@ -1,13 +0,0 @@ ---- -# tasks file for docker-compose restart - -- name: COMPOSE RESTART | Run `docker compose restart` - community.docker.docker_compose_v2: - project_src: "{{ c3infodesk_project_src }}" - state: restarted - register: ret_docker_compose_restart - -- name: COMPOSE RESTART | Output compose restart - ansible.builtin.debug: - var: ret_docker_compose_restart - when: c3infodesk_printer_docker_compose_restart_debug | bool diff --git a/roles/docker_containers/tasks/printer_compose_stop.yml b/roles/docker_containers/tasks/printer_compose_stop.yml deleted file mode 100644 index e671330c11603bb2ba5f073d6a7072f68b5f4db9..0000000000000000000000000000000000000000 --- a/roles/docker_containers/tasks/printer_compose_stop.yml +++ /dev/null @@ -1,13 +0,0 @@ ---- -# tasks file for docker-compose stop - -- name: COMPOSE STOP | Run `docker compose stop` - community.docker.docker_compose_v2: - project_src: "{{ c3infodesk_project_src }}" - state: stopped - register: ret_docker_compose_stop - -- name: COMPOSE STOP | Output compose stop - ansible.builtin.debug: - var: ret_docker_compose_stop - when: c3infodesk_printer_docker_compose_stop_debug | bool diff --git a/roles/docker_containers/tasks/printer_compose_up.yml b/roles/docker_containers/tasks/printer_compose_up.yml deleted file mode 100644 index d576754ea0b9c511d878a30e6255f0b901887e22..0000000000000000000000000000000000000000 --- a/roles/docker_containers/tasks/printer_compose_up.yml +++ /dev/null @@ -1,13 +0,0 @@ ---- -# tasks file for docker-compose up - -- name: COMPOSE UP | Run `docker compose up` - community.docker.docker_compose_v2: - project_src: "{{ c3infodesk_printer_folder_docker }}" - state: present - register: ret_docker_compose_up - -- name: COMPOSE UP | Output compose up - ansible.builtin.debug: - var: ret_docker_compose_up - when: c3infodesk_printer_docker_compose_up_debug | bool diff --git a/roles/docker_containers/tasks/printer_host_cups_disable.yml b/roles/docker_containers/tasks/printer_host_cups_disable.yml deleted file mode 100644 index c6d6a482736c4a94c745b089c53e41e8661265b8..0000000000000000000000000000000000000000 --- a/roles/docker_containers/tasks/printer_host_cups_disable.yml +++ /dev/null @@ -1,40 +0,0 @@ ---- -# tasks file for disabling CUPS on target system - -- name: DISABLE CUPS | Populate service facts - ansible.builtin.service_facts: - -- name: DISABLE CUPS | Setting fact from cups status - ansible.builtin.set_fact: - cups_status: "{{ ansible_facts.services['cups.service'].status }}" - when: ansible_facts.services['cups.service'].status is defined - -- name: DISABLE CUPS | Stop the running CUPS on target - ansible.builtin.command: - cmd: systemctl stop cups - become: true - when: - - cups_status is defined - - cups_status != 'masked' - register: ret_stop_cups - changed_when: ret_stop_cups.rc != 0 - -- name: DISABLE CUPS | Disable the running CUPS on target - ansible.builtin.command: - cmd: systemctl disable cups - become: true - when: - - cups_status is defined - - cups_status != 'masked' - register: ret_disable_cups - changed_when: ret_disable_cups.rc != 0 - -- name: DISABLE CUPS | Mask the running CUPS on target - ansible.builtin.command: - cmd: systemctl mask cups - become: true - when: - - cups_status is defined - - cups_status != 'masked' - register: ret_mask_cups - changed_when: ret_mask_cups.rc != 0