From 822f849e9f1b2893285dfbea09659b1f797cd194 Mon Sep 17 00:00:00 2001 From: fejao <mail@fejao.de> Date: Mon, 10 Mar 2025 19:31:44 +0100 Subject: [PATCH] Updated files --- .gitignore | 1 + .yamllint | 50 +++++ README.md | 194 +++++++++++++------ ci-cd/python_requirements.txt | 4 + defaults/main.yml | 23 +++ meta/main.yml | 24 +++ molecule/README.md | 42 ++++ molecule/default/converge.yml | 15 ++ molecule/default/molecule.yml | 68 +++++++ molecule/default/pre_tasks.yml | 45 +++++ molecule/default/verify.yml | 18 ++ molecule/default/verify_populate.yml | 12 ++ molecule/default/verify_tasks.yml | 149 ++++++++++++++ tasks/debug/disable_cups_on_target_debug.yml | 17 ++ tasks/debug/folders_permissions_debug.yml | 12 ++ tasks/disable_cups_on_target.yml | 41 ++++ tasks/folders_permissions.yml | 18 ++ tasks/main.yml | 40 ++++ 18 files changed, 715 insertions(+), 58 deletions(-) create mode 100644 .gitignore create mode 100644 .yamllint create mode 100644 ci-cd/python_requirements.txt create mode 100644 defaults/main.yml create mode 100644 meta/main.yml create mode 100644 molecule/README.md create mode 100644 molecule/default/converge.yml create mode 100644 molecule/default/molecule.yml create mode 100644 molecule/default/pre_tasks.yml create mode 100644 molecule/default/verify.yml create mode 100644 molecule/default/verify_populate.yml create mode 100644 molecule/default/verify_tasks.yml create mode 100644 tasks/debug/disable_cups_on_target_debug.yml create mode 100644 tasks/debug/folders_permissions_debug.yml create mode 100644 tasks/disable_cups_on_target.yml create mode 100644 tasks/folders_permissions.yml create mode 100644 tasks/main.yml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b3c5964 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*OLD* diff --git a/.yamllint b/.yamllint new file mode 100644 index 0000000..2382bed --- /dev/null +++ b/.yamllint @@ -0,0 +1,50 @@ +--- + +# https://ansible.readthedocs.io/projects/lint/rules/yaml/ + +yaml-files: + - '*.yaml' + - '*.yml' + - '.yamllint' + +rules: + anchors: enable + # braces: enable + # braces: disable + braces: + max-spaces-inside: 1 + brackets: enable + colons: enable + commas: enable + comments: + level: warning + min-spaces-from-content: 1 + comments-indentation: false + document-end: disable + document-start: + level: warning + empty-lines: enable + empty-values: disable + float-values: disable + hyphens: enable + # indentation: enable + indentation: disable + key-duplicates: enable + key-ordering: disable + # line-length: enable + line-length: + # max: 160 + ### roles/dependencies/defaults/main.yml:72 --> 232 characters + max: 240 + new-line-at-end-of-file: enable + new-lines: enable + # octal-values: disable + quoted-strings: disable + trailing-spaces: enable + truthy: + level: warning + #### + # var_naming_pattern: "^[a-z_][a-z0-9_]*$" + # var-naming: disable + # var-naming: + # no-role-prefix: disable diff --git a/README.md b/README.md index 6e16493..3a1dfcb 100644 --- a/README.md +++ b/README.md @@ -1,93 +1,171 @@ -# c3infodesk-deployment-role-docker-xtras +# docker_xtras role -## Getting started -To make it easy for you to get started with GitLab, here's a list of recommended next steps. +This ansible-role for dealing with after the creation of the the docker images to fix/add extra tasks before starting the nedded containers. -Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)! +At the moment, the tasks included are: +- **disable the CUPS service** +- **set folders permissions**, because sometimes, mounting a countainer folder, we need to fix it's permissions before running it. -## Add your files -- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files -- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command: +## Requirements +- To have [ansible](https://docs.ansible.com/ansible/latest/installation_guide/installation_distros.html) installed at your system. -``` -cd existing_repo -git remote add origin https://git.cccv.de/fejao/c3infodesk-deployment-role-docker-xtras.git -git branch -M main -git push -uf origin main -``` -## Integrate with your tools +## 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. -- [ ] [Set up project integrations](https://git.cccv.de/fejao/c3infodesk-deployment-role-docker-xtras/-/settings/integrations) + Example: [remote_user](https://git.cccv.de/fejao/c3infodesk-deployment/-/blob/main/ansible.cfg#L227) -## Collaborate with your team +- ### 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. -- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/) -- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html) -- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically) -- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/) -- [ ] [Set auto-merge](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html) + Example: [ansible_become_pass](https://git.cccv.de/fejao/c3infodesk-deployment/-/blob/main/inventories/host_vars/example_server.yml#L5) -## Test and Deploy +- ### 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**. -Use the built-in continuous integration in GitLab. + There you can add/edit the target address/IP. -- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/) -- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/) -- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html) -- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/) -- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html) + Example: [hosts](https://git.cccv.de/fejao/c3infodesk-deployment/-/blob/main/inventories/hosts) -*** -# Editing this README +## Role Variables +Here are the variables setted: -When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template. +- ### From CUPS service + Here are the variables needed to disable the **CUPS** service at the target host. + - #### c3infodesk_deployment_repository_dest_folder + - This should be a **string** entry with the path of the folder where is located the folder from the project that you are using this role to fix things before starting the container. + - This variable is also needed for setting the [clone-repository](https://git.cccv.de/fejao/c3infodesk-deployment-role-clone-repositories) role. + - **DEFAULT**: *"/tmp/test"* -## Suggestions for a good README + - #### c3infodesk_deployment_docker_xtras_cups_disable + - This should be a **boolean** entry with the value from if you want or not to disable the **CUPS** service at the target host. + - **DEFAULT**: *false* -Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information. + - #### c3infodesk_deployment_docker_xtras_cups_mask + - This should be a **boolean** entry with the value from if you want or not to mask the **CUPS** service at the target host. + - **DEFAULT**: *false* -## Name -Choose a self-explaining name for your project. + - #### c3infodesk_deployment_docker_xtras_cups_disable_debug + - This should be a **boolean** entry with the value from if you want or not to see the **debug** outputs from setting the **CUPS** at the target host. + - **DEFAULT**: *false* -## Description -Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors. +- ### From setting the folders permissions + Here are the variables needed to change/update the folders permissions. + - #### c3infodesk_deployment_docker_xtras_fix_folders_permissions + - This should be a **boolean** entry with the value from if you want or not to fix folder permissions at the target host. + - **DEFAULT**: *false* -## Badges -On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge. + - #### c3infodesk_deployment_docker_xtras_fix_folders_permissions_debug + - This should be a **boolean** entry with the value from if you want or not to see the **debug** outputs from setting the folders permissions at the target host. + - **DEFAULT**: *false* -## Visuals -Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method. + - #### c3infodesk_deployment_docker_xtras_fix_folders_permissions_list + - This should be a **list** entry with the the information of the folders that needes to be have new permissions setted. + - This list include entries with the default keys: + - **folder_path** + - The path from the location of the **docker mounted folder** that needs new permissions. + - **folder_mode** + - This should be an **octal** entry with the mode from the folder to be updated The mode that . + - **DEFAULT**: The default values are seeted for the [c3buttons](https://git.cccv.de/fejao/c3buttons) project. + ```yaml + c3infodesk_deployment_docker_xtras_fix_folders_permissions_list: + - folder_path: docker/grafana/data + folder_mode: "0777" + ``` -## Installation -Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection. -## Usage -Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README. +## Dependencies +The role dependencies are: + - [dependencies(role)](https://git.cccv.de/fejao/c3infodesk-deployment-role-dependencies) + - [clone_repositories](https://git.cccv.de/fejao/c3infodesk-deployment-role-clone-repositories) + - [docker_images](https://git.cccv.de/fejao/c3infodesk-deployment-role-docker-images) -## Support -Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc. -## Roadmap -If you have ideas for releases in the future, it is a good idea to list them in the README. +## Example Playbook -## Contributing -State if you are open to contributions and what your requirements are for accepting them. +- ### Using the provided example + For using the example playbook **[playbooks/examples/example_04_docker_images.yml](https://git.cccv.de/fejao/c3infodesk-deployment/-/blob/main/playbooks/examples/example_04_docker_images.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. -For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self. -You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser. + And run the command: + ```bash + ansible-playbook -i inventories/hosts playbooks/examples/example_04_docker_images.yml + ``` + +- ### Setting your own 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** + + ```yaml + - hosts: + - test_servers + roles: + - roles/c3infodesk-deployment-role-docker-xtras + ``` + + And call the playbook as: + + ```bash + ansible-playbook -i <INVENTORY> <PLAYBOOK_NAME>.yml + ``` + + +## 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/). + + - #### Setting *DIND (docker in docker)* + You might have to set *DIND (docker in docker)* at your system, for linux, you can create the file **/etc/docker/daemon.json** + + - ##### Enabling DIND at your system + And add the content and restart docker. + + ```json + { + "exec-opts": ["native.cgroupdriver=systemd"], + "features": { + "buildkit": true + }, + "experimental": true, + "cgroup-parent": "docker.slice" + } + ``` + +- ### Using the molecule tests + + - #### Configuring the *HOST_VAR_FILE_NAME* variable + For using the molecule tests you should pass the **HOST_VAR_FILE_NAME** environment variable, or the default value for testing is: **example_printer.yml** + + For the values that can be used, you can lool at the files at the **inventories/host_vars** folder. + + - ##### Molecule test example + Just go to the root of the role **roles/x3infodesk-deployment-role-dependencies** and run the command, here is an example for using the **HOST_VAR_FILE_NAME** as *example_buttons.yml*: + ```bash + HOST_VAR_FILE_NAME="example_buttons.yml" molecule test + ``` -## Authors and acknowledgment -Show your appreciation to those who have contributed to the project. ## License -For open source projects, say how it is licensed. -## Project status -If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers. +MIT / BSD + + +## Author Information +[https://chaos.social/@fejao](https://chaos.social/@fejao) diff --git a/ci-cd/python_requirements.txt b/ci-cd/python_requirements.txt new file mode 100644 index 0000000..b5e3d77 --- /dev/null +++ b/ci-cd/python_requirements.txt @@ -0,0 +1,4 @@ +yamllint +# ansible +# ansible-dev-tools +# ansible-lint diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..24da113 --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,23 @@ +--- +# defaults file for docker-xtras + +### +### c3infodesk-deployment-role-clone-repositories +### +c3infodesk_deployment_repository_dest_folder: "/tmp/test" + +### +### CUPS +### +c3infodesk_deployment_docker_xtras_cups_disable: false +c3infodesk_deployment_docker_xtras_cups_mask: false +c3infodesk_deployment_docker_xtras_cups_disable_debug: false + +### +### FOLDER PERMISSIONS +### +c3infodesk_deployment_docker_xtras_fix_folders_permissions: false +c3infodesk_deployment_docker_xtras_fix_folders_permissions_debug: false +c3infodesk_deployment_docker_xtras_fix_folders_permissions_list: + - folder_path: docker/grafana/data + folder_mode: "0777" diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..1c4888f --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,24 @@ +--- + +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: + - docker + - cups + - folder + - permission + - folder-permission + - c3infodesk + - c3infodesk-printer + - c3buttons + +# dependencies: [] +dependencies: + - role: c3infodesk-deployment-role-dependencies + - role: c3infodesk-deployment-role-clone-repositories + - role: c3infodesk-deployment-role-docker-images diff --git a/molecule/README.md b/molecule/README.md new file mode 100644 index 0000000..4e02fc3 --- /dev/null +++ b/molecule/README.md @@ -0,0 +1,42 @@ +## 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/molecule/default/converge.yml b/molecule/default/converge.yml new file mode 100644 index 0000000..f40355a --- /dev/null +++ b/molecule/default/converge.yml @@ -0,0 +1,15 @@ +--- + +- name: MOLECULE | CONVERGE | Setting tasks for converge... + hosts: all + + pre_tasks: + - name: MOLECULE | CONVERGE | PRE-TASKS | Import tasks... + tags: import_pre_tasks + ansible.builtin.import_tasks: pre_tasks.yml + + tasks: + - name: MOLECULE | CONVERGE | TASKS | Call the 'docker_xtras' role. + tags: execute_role + ansible.builtin.include_role: + name: c3infodesk-deployment-role-docker-xtras diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml new file mode 100644 index 0000000..b7d14b7 --- /dev/null +++ b/molecule/default/molecule.yml @@ -0,0 +1,68 @@ +--- + +dependency: + name: galaxy + +driver: + name: docker + +platforms: + - name: molecule_docker_xtras + ### 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/molecule/default/pre_tasks.yml b/molecule/default/pre_tasks.yml new file mode 100644 index 0000000..41b1198 --- /dev/null +++ b/molecule/default/pre_tasks.yml @@ -0,0 +1,45 @@ +--- +# This is the pre-tasks shared between converge and verify. + +- name: MOLECULE | PRE-TASKS | VARIABLES + tags: variables + vars: + # molecule_debug_outputs: true + molecule_debug_outputs: false + block: + - name: MOLECULE | PRE-TASKS | VARIABLES | From -> ../../defaults + ansible.builtin.include_vars: + dir: ../../defaults + depth: 1 + extensions: + - 'yml' + + - name: MOLECULE | PRE-TASKS | VARIABLES | From -> ../../../../roles/c3infodesk-deployment-role-dependencies/defaults + ansible.builtin.include_vars: + dir: ../../../../roles/c3infodesk-deployment-role-dependencies/defaults + depth: 1 + extensions: + - 'yml' + + - name: MOLECULE | PRE-TASKS | SET FACT | Read the parsed 'HOST_VAR_FILE_NAME' env var or set the default to 'host_var_file_name' variable. + ansible.builtin.set_fact: + host_var_file_name: "../../../../inventories/host_vars/{{ lookup('ansible.builtin.env', 'HOST_VAR_FILE_NAME') | default('example_printer.yml', True) }}" + + - name: MOLECULE | PRE-TASKS | DEBUG | Value from 'host_var_file_name' fact. + ansible.builtin.debug: + msg: "molecule_debug_outputs: {{ host_var_file_name }}" + when: molecule_debug_outputs | bool + + - name: MOLECULE | PRE-TASKS | VARIABLES | From -> 'host_vars_from_proj_path' variable. + ansible.builtin.include_vars: + file: "{{ host_var_file_name }}" + + - name: MOLECULE | PRE-TASKS | DEBUG | Value from 'c3infodesk_deployment_repository_url' variable. + ansible.builtin.debug: + msg: "molecule_debug_outputs: {{ c3infodesk_deployment_repository_url }}" + when: molecule_debug_outputs | bool + + ### c3infodesk-deployment-role-docker-images + - name: MOLECULE | CONVERGE | PRE-TASKS | INSTALL | Install the python pip requests package. + ansible.builtin.pip: + name: requests diff --git a/molecule/default/verify.yml b/molecule/default/verify.yml new file mode 100644 index 0000000..cb336c4 --- /dev/null +++ b/molecule/default/verify.yml @@ -0,0 +1,18 @@ +--- + +- name: VERIFY | Test role for debugging variables. + hosts: all + + pre_tasks: + - name: MOLECULE | VERIFY | PRE-TASKS | Import tasks... + tags: import_pre_tasks + ansible.builtin.import_tasks: pre_tasks.yml + + tasks: + - name: MOLECULE | VERIFY | POPULATE + tags: import_verify_populate + ansible.builtin.import_tasks: verify_populate.yml + + - name: MOLECULE | VERIFY | TASKS + tags: import_verify_tasks + ansible.builtin.import_tasks: verify_tasks.yml diff --git a/molecule/default/verify_populate.yml b/molecule/default/verify_populate.yml new file mode 100644 index 0000000..c84c2a2 --- /dev/null +++ b/molecule/default/verify_populate.yml @@ -0,0 +1,12 @@ +--- +# This is the file for populating the facts before verify + +- name: MOLECULE | VERIFY | USER + tags: populate + block: + - 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: diff --git a/molecule/default/verify_tasks.yml b/molecule/default/verify_tasks.yml new file mode 100644 index 0000000..93acca0 --- /dev/null +++ b/molecule/default/verify_tasks.yml @@ -0,0 +1,149 @@ +--- +# This is the tasks to be runned from the verify.yml file + +### +### DEPENDENCIES - PACKAGES +### +- name: MOLECULE | VERIFY | PACKAGES | Check that the packages from 'os_dependencies_packages' are installed. + tags: + - install_packages + - role_dependency_needed + 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 + +### +### DEPENDENCIES - DOCKER +### +- name: MOLECULE | VERIFY | DOCKER + tags: + - install_docker + - role_dependency_needed + vars: + verify_package_name_docker: 'docker' + verify_package_name_docker_ce: 'docker-ce' + verify_package_name_docker_compose: 'docker-compose' + verify_package_name_docker_compose_plugin: 'docker-compose-plugin' + block: + - name: MOLECULE | VERIFY | DOCKER | Is installed. + ansible.builtin.debug: + msg: "Package: 'docker' is installed" + failed_when: + - verify_package_name_docker not in ansible_facts.packages + - verify_package_name_docker_ce not in ansible_facts.packages + when: docker_set_to_install | bool + + - name: MOLECULE | VERIFY | DOCKER | docker-compose is installed. + ansible.builtin.debug: + msg: "Package: 'docker-cokmpose' is installed" + failed_when: + - verify_package_name_docker_compose not in ansible_facts.packages + - verify_package_name_docker_compose_plugin not in ansible_facts.packages + when: docker_set_to_install | bool + + - name: MOLECULE | VERIFY | DOCKER | Get docker service state. + ansible.builtin.systemd: + name: "docker" + register: docker_service + when: docker_set_to_install | bool + + - name: MOLECULE | VERIFY | DOCKER | Check that docker is running. + ansible.builtin.debug: + msg: "Docker IS running..." + failed_when: "'active' != docker_service.status.ActiveState" + when: docker_set_to_install | bool + +### +### DEPENDENCIES - DOCKER USERS +### +- name: MOLECULE | VERIFY | USER + tags: + - install_docker_users + - role_dependency_needed + block: + - name: MOLECULE | VERIFY | USER | Get added users infos. + ansible.builtin.user: + name: "{{ item }}" + loop: "{{ docker_users }}" + check_mode: true + register: test_users + + - name: MOLECULE | VERIFY | USER | 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 | USER | 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 | USER | 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" + +### +### CLONE REPOSITORIES +### +- name: MOLECULE | VERIFY | REPOSITORY + tags: + - clone_repositories + - role_dependency_needed + block: + - name: MOLECULE | VERIFY | REPOSITORY | Get if the repository was cloned. + ansible.builtin.git: + repo: "{{ c3infodesk_deployment_repository_url }}" + dest: "{{ c3infodesk_deployment_repository_dest_folder }}" + version: main + clone: false + update: false + register: check_repository + + - name: MOLECULE | VERIFY | REPOSITORY | Checking if the repository was cloned. + ansible.builtin.debug: + msg: "Repository: '{{ c3infodesk_deployment_repository_url }}' cloned..." + failed_when: check_repository.changed | bool + +### +### DOCKER IMAGES +### +- name: MOLECULE | VERIFY | IMAGES | Check if the Docker images are on the system. + tags: + - build_images + - role_dependency_needed + community.docker.docker_image_info: + name: "{{ item.docker_image_name }}" + with_items: "{{ c3infodesk_deployment_docker_images_list }}" + +### +### DOCKER XTRAS +### +- name: MOLECULE | VERIFY | XTRAS + tags: docker_xtras + block: + - name: MOLECULE | VERIFY | XTRAS | CUPS | Get that the CUPS service is disable. + tags: cups_disable + ansible.builtin.debug: + msg: "The service: 'cups.service' is not setted" + failed_when: "'cups.service' in ansible_facts.services" + when: c3infodesk_deployment_docker_xtras_cups_disable | bool + + - name: MOLECULE | VERIFY | XTRAS | PERMISSIONS | Get that the folders permissions are correctly setted. + tags: folders_permissions + ansible.builtin.stat: + path: "{{ c3infodesk_deployment_repository_dest_folder }}/{{ item.folder_path }}" + register: folder_stats + failed_when: folder_stats.stat.mode != item.folder_mode + with_items: "{{ c3infodesk_deployment_docker_xtras_fix_folders_permissions_list }}" + when: c3infodesk_deployment_docker_xtras_fix_folders_permissions | bool diff --git a/tasks/debug/disable_cups_on_target_debug.yml b/tasks/debug/disable_cups_on_target_debug.yml new file mode 100644 index 0000000..965eaf7 --- /dev/null +++ b/tasks/debug/disable_cups_on_target_debug.yml @@ -0,0 +1,17 @@ +--- +# tasks file for debugging disabling CUPS on target system + +- name: DISABLE CUPS | DEBUG + tags: cups_disable_debug + block: + - name: DISABLE CUPS | DEBUG | Populate service facts for be sure that CUPS is disable. + ansible.builtin.service_facts: + + - name: DISABLE CUPS | DEBUG | Checks that the CUPS is masked. + ansible.builtin.debug: + msg: > + {% if ansible_facts.services['cups.service'] is defined %} + "The CUPS service was marked as '{{ ansible_facts.services['cups.service'].status }}'" + {% else %} + "The CUPS service was not found at the system" + {% endif %} diff --git a/tasks/debug/folders_permissions_debug.yml b/tasks/debug/folders_permissions_debug.yml new file mode 100644 index 0000000..ecad916 --- /dev/null +++ b/tasks/debug/folders_permissions_debug.yml @@ -0,0 +1,12 @@ +--- +# tasks file for debugging fixing the docker folder permissions + +- name: FOLDERS PERMISSIONS | DEBUG | Gets the folder stats. + ansible.builtin.stat: + path: "{{ c3infodesk_deployment_repository_dest_folder }}/{{ folder_path }}" + register: folder_stats + +- name: FOLDERS PERMISSIONS | DEBUG | Display the new folder mode. + ansible.builtin.debug: + msg: "Folder with path: '{{ folder_stats.stat.path }}' have mode setted to: '{{ folder_stats.stat.mode}}'" + failed_when: folder_stats.stat.mode != folder_mode diff --git a/tasks/disable_cups_on_target.yml b/tasks/disable_cups_on_target.yml new file mode 100644 index 0000000..8e52cb3 --- /dev/null +++ b/tasks/disable_cups_on_target.yml @@ -0,0 +1,41 @@ +--- +# 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' + - c3infodesk_deployment_docker_xtras_cups_mask | bool + register: ret_mask_cups + changed_when: ret_mask_cups.rc != 0 diff --git a/tasks/folders_permissions.yml b/tasks/folders_permissions.yml new file mode 100644 index 0000000..74fd92e --- /dev/null +++ b/tasks/folders_permissions.yml @@ -0,0 +1,18 @@ +--- +# tasks file for fixing the docker folder permissions + +- name: FOLDERS PERMISSIONS | Gets the folder stats before changing mode. + ansible.builtin.stat: + path: "{{ c3infodesk_deployment_repository_dest_folder }}/{{ folder_path }}" + register: folder_stats + +- name: FOLDERS PERMISSIONS | Before setting folder permissions. + ansible.builtin.debug: + msg: "Setting folder with path: '{{ c3infodesk_deployment_repository_dest_folder }}/{{ folder_path }}' from mode: '{{ folder_stats.stat.mode}}' to new mode: '{{ folder_mode }}'" + when: folder_stats.stat.exists | bool + +- name: FOLDERS PERMISSIONS | Fixing the folder permission. + ansible.builtin.file: + state: directory + path: "{{ c3infodesk_deployment_repository_dest_folder }}/{{ folder_path }}" + mode: "{{ folder_mode }}" diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..0a2e94f --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,40 @@ +--- +# tasks file for docker-xtras + +### +### CUPS +### +- name: Disabling CUPS on target host. + tags: cups_disable + ansible.builtin.import_tasks: disable_cups_on_target.yml + when: c3infodesk_deployment_docker_xtras_cups_disable | bool + +- name: Debugging disabling CUPS on target host. + tags: + - cups_disable + - cups_disable_debug + ansible.builtin.import_tasks: debug/disable_cups_on_target_debug.yml + when: c3infodesk_deployment_docker_xtras_cups_disable_debug | bool + +### +### FOLDER PERMISSIONS +### +- name: Fixing the folders permissions used by docker. + tags: folders_permissions + ansible.builtin.include_tasks: folders_permissions.yml + vars: + folder_path: "{{ item.folder_path }}" + folder_mode: "{{ item.folder_mode }}" + with_items: "{{ c3infodesk_deployment_docker_xtras_fix_folders_permissions_list }}" + when: c3infodesk_deployment_docker_xtras_fix_folders_permissions | bool + +- name: Debugging folders permissions on target host. + tags: + - folders_permissions + - folders_permissions_debug + ansible.builtin.include_tasks: debug/folders_permissions_debug.yml + vars: + folder_path: "{{ item.folder_path }}" + folder_mode: "{{ item.folder_mode }}" + with_items: "{{ c3infodesk_deployment_docker_xtras_fix_folders_permissions_list }}" + when: c3infodesk_deployment_docker_xtras_fix_folders_permissions_debug | bool -- GitLab