diff --git a/README.md b/README.md index 02bb93bb3d56e535a9305777d735c1b2192f0fab..67c41ddc378e921d3a252e67b7aa21e6562bc4a9 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ - [ ] finish the roles for deploying the **c3InfoDesk Printer** - [x] dependencies - [x] clone_repositories - - [ ] docker_images + - [x] docker_images - [ ] docker_containers - [ ] set ansible-lint @@ -22,6 +22,7 @@ Here are the used roles: - [dependencies](roles/dependencies/README.md) - [clone_repositories](roles/clone_repositories/README.md) +- [docker_images](roles/docker_images/README.md) ## License diff --git a/inventories/group_vars/example_servers_group.yml b/inventories/group_vars/example_servers_group.yml index e8051e2afa5377d08071b986deec37f3bfa70a0a..1dc584343f20d724f59c6e3855a7ed555535dca9 100644 --- a/inventories/group_vars/example_servers_group.yml +++ b/inventories/group_vars/example_servers_group.yml @@ -11,3 +11,17 @@ var_setted_only_group_vars: "MESSAGE FROM GROUP_VARS ONLY" ### roles/clone_repositories ### c3infodesk_printer_folder: "Coding/c3infodesk-printer" + +### +### roles/docker_images +### +c3infodesk_printer_folder_docker: "Coding/c3infodesk-printer/docker" +c3infodesk_printer_folder_docker_cups: "Coding/c3infodesk-printer/docker/cups" +c3infodesk_printer_folder_docker_app: "Coding/c3infodesk-printer/docker/app" +c3infodesk_printer_folder_docker_proxy: "Coding/c3infodesk-printer/docker/proxy" +c3infodesk_printer_docker_img_cups_name: "c3printing-cups" +c3infodesk_printer_docker_img_cups_tag: "latest" +c3infodesk_printer_docker_img_app_name: "c3printing-app" +c3infodesk_printer_docker_img_app_tag: "latest" +c3infodesk_printer_docker_img_proxy_name: "c3printing-proxy" +c3infodesk_printer_docker_img_proxy_tag: "latest" diff --git a/inventories/host_vars/example_server.yml b/inventories/host_vars/example_server.yml index 23035ee9caf0c2aaa20c17272bf026cb3d3df90f..0e1e96d3ed454a209e6a4fce335035143afd844a 100644 --- a/inventories/host_vars/example_server.yml +++ b/inventories/host_vars/example_server.yml @@ -20,3 +20,11 @@ docker_users: [test-user] ### # c3infodesk_printer_repo_clone: true c3infodesk_printer_repo_new_branch_name: "test_branch" + +### +### roles/docker_images +### +# Set this variables, only if you need to debug creating the docker images +# c3infodesk_printer_debug_create_image_cups: true +# c3infodesk_printer_debug_create_image_app: true +# c3infodesk_printer_debug_create_image_proxy: true diff --git a/playbook_example_03_clone_repositories.yml b/playbook_example_03_clone_repositories.yml index d9aff5b431fc38d820852812a5bcc089af276a30..b6b3636df84c3a3c94ddb36327f241e1cd0ad645 100644 --- a/playbook_example_03_clone_repositories.yml +++ b/playbook_example_03_clone_repositories.yml @@ -4,5 +4,4 @@ - hosts: - example_servers_group roles: - # - dependencies - clone_repositories diff --git a/playbook_example_04_docker_images.yml b/playbook_example_04_docker_images.yml new file mode 100644 index 0000000000000000000000000000000000000000..0a2c733dcf3618d098ada07b8cc5155eab36be18 --- /dev/null +++ b/playbook_example_04_docker_images.yml @@ -0,0 +1,7 @@ +--- +# Runs example for + +- hosts: + - example_servers_group + roles: + - docker_images diff --git a/roles/clone_repositories/meta/main.yml b/roles/clone_repositories/meta/main.yml index 74aa718b57d6ee2fe3843bb79f9c2075bd3f8371..6de0edd4594c450da430b82e3eea8b1221d805a4 100644 --- a/roles/clone_repositories/meta/main.yml +++ b/roles/clone_repositories/meta/main.yml @@ -1,33 +1,11 @@ galaxy_info: - author: your name - description: your role description - company: your company (optional) - - # If the issue tracker for your role is not on github, uncomment the - # next line and provide a value - # issue_tracker_url: http://example.com/issue/tracker - - # Choose a valid license ID from https://spdx.org - some suggested licenses: - # - BSD-3-Clause (default) - # - MIT - # - GPL-2.0-or-later - # - GPL-3.0-only - # - Apache-2.0 - # - CC-BY-4.0 + role_name: clone_repositories + description: Role to clone the repositories used from c3InfoDesk sytems + author: fejao + company: cccv.de license: license (GPL-2.0-or-later, MIT, etc) - - min_ansible_version: 2.1 - - # If this a Container Enabled role, provide the minimum Ansible Container version. - # min_ansible_container_version: - + min_ansible_version: 2.10 galaxy_tags: [] - # List tags for your role here, one per line. A tag is a keyword that describes - # and categorizes the role. Users find roles by searching for tags. Be sure to - # remove the '[]' above, if you add tags to this list. - # - # NOTE: A tag is limited to a single word comprised of alphanumeric characters. - # Maximum 20 tags per role. # dependencies: [] # List your role dependencies here, one per line. Be sure to remove the '[]' above, diff --git a/roles/dependencies/meta/main.yml b/roles/dependencies/meta/main.yml index 18601867cd9960907f68ff85c3aaafee8c56e9b4..1fbb9870ec80182a8b918028ed41f7ec57044bb8 100644 --- a/roles/dependencies/meta/main.yml +++ b/roles/dependencies/meta/main.yml @@ -4,7 +4,7 @@ galaxy_info: author: fejao company: cccv.de license: license (GPL-2.0-or-later, MIT, etc) - min_ansible_version: 2.1 + min_ansible_version: 2.10 galaxy_tags: [] dependencies: [] diff --git a/roles/docker_images/README.md b/roles/docker_images/README.md new file mode 100644 index 0000000000000000000000000000000000000000..836b1ef38593df966263c3c9ba573b8be6e84acd --- /dev/null +++ b/roles/docker_images/README.md @@ -0,0 +1,96 @@ +# docker_images + +This ansible-role for dealing with creating the docker images necessary for deploying the system used from **c3infodesk**. + +## Requirements +- To have [ansible](https://docs.ansible.com/ansible/latest/installation_guide/installation_distros.html) installed at your system. +- Set your **remote_user** configuration at the **ansible.cfg** file. +- Set your **inventories/host_vars/<TARGET_NAME>** file. + +## Role Variables +Here are the variables setted: + +- ### From: inventories/host_vars/<TARGET_NAME> + Here are the variables that you should be changing for your own deployment. + - **c3infodesk_printer_debug_create_image_cups**: DEFAULT=<NOT_SETTED> + - If you want to debug the output from creating the image for CUPS + - **c3infodesk_printer_debug_create_image_app**: DEFAULT=<NOT_SETTED> + - If you want to debug the output from creating the image for the APP + - **c3infodesk_printer_debug_create_image_proxy**: DEFAULT=<NOT_SETTED> + - If you want to debug the output from creating the image for the PROXY + +- ### 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. + - **c3infodesk_printer_folder_docker**: DEFAULT="Coding/c3infodesk-printer/docker" + - The folder where the configuration from docker used for the system + - **c3infodesk_printer_folder_docker_cups**: DEFAULT="Coding/c3infodesk-printer/docker/cups" + - The folder where the configuration from docker CUPS used for the system + - **c3infodesk_printer_folder_docker_app**: DEFAULT="Coding/c3infodesk-printer/docker/app" + - The folder where the configuration from docker APP used for the system + - **c3infodesk_printer_folder_docker_proxy**: DEFAULT="Coding/c3infodesk-printer/docker/proxy" + - The folder where the configuration from docker PROXY used for the system + - **c3infodesk_printer_docker_img_cups_name**: DEFAULT="c3printing-cups" + - The name of the image to be set for the CUPS + - **c3infodesk_printer_docker_img_cups_tag**: DEFAULT="latest" + - The tag name/number to be setted for the CUPS image + - **c3infodesk_printer_docker_img_app_name**: DEFAULT="c3printing-app" + - The name of the image to be set for the APP + - **c3infodesk_printer_docker_img_app_tag**: DEFAULT="latest" + - The tag name/number to be setted for the APP image + - **c3infodesk_printer_docker_img_proxy_name**: DEFAULT="c3printing-proxy" + - The name of the image to be set for the PROXY + - **c3infodesk_printer_docker_img_proxy_tag**: DEFAULT="latest" + - The tag name/number to be setted for the PROXY image + +- ### 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 + - **c3infodesk_printer_debug_create_image_cups**: DEFAULT=false + - **c3infodesk_printer_debug_create_image_app**: DEFAULT=false + - **c3infodesk_printer_debug_create_image_proxy**: DEFAULT=false + + +## Dependencies +The role dependencies are: + - [dependencies(role)](roles/dependencies/README.md) + - [clone_reposiries](roles/clone_repositories/README.md) + + +## Example Playbook + +- ### Using the provided example + For using the playbook **playbook_example_04_docker_images.yml** file you only nned 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 +``` + +- ### 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: + - docker_images +``` + + And call the playbook as: + +```bash +ansible-playbook -i <INVENTORY> <PLAYBOOK_NAME>.yml +``` + + +## License + +MIT / BSD + + +## Author Information + [https://chaos.social/@fejao](https://chaos.social/@fejao) diff --git a/roles/docker_images/defaults/main.yml b/roles/docker_images/defaults/main.yml new file mode 100644 index 0000000000000000000000000000000000000000..9bc853f42f21773ce0a07d59323bcce0334bb5f8 --- /dev/null +++ b/roles/docker_images/defaults/main.yml @@ -0,0 +1,6 @@ +--- +# defaults file for docker-images + +c3infodesk_printer_debug_create_image_cups: false +c3infodesk_printer_debug_create_image_app: false +c3infodesk_printer_debug_create_image_proxy: false diff --git a/roles/docker_images/meta/main.yml b/roles/docker_images/meta/main.yml new file mode 100644 index 0000000000000000000000000000000000000000..fcbd3befeaabeaad3d22b8fb9814ea1597e0474b --- /dev/null +++ b/roles/docker_images/meta/main.yml @@ -0,0 +1,15 @@ +galaxy_info: + role_name: docker_images + description: Role to clone the repositories used from c3InfoDesk sytems + author: fejao + company: cccv.de + license: license (GPL-2.0-or-later, MIT, etc) + 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 diff --git a/roles/docker_images/tasks/docker_image_app.yml b/roles/docker_images/tasks/docker_image_app.yml new file mode 100644 index 0000000000000000000000000000000000000000..983fa24c5601b9b21bf884707085b856673f2a4f --- /dev/null +++ b/roles/docker_images/tasks/docker_image_app.yml @@ -0,0 +1,27 @@ +--- +# Creates the c3infodesk-app docker image + +- name: APP | Check if the image already exists on the system + community.docker.docker_image_info: + name: "{{ c3infodesk_printer_docker_img_app_name }}" + register: result_check_image + +- name: APP | Check image exists answer + ansible.builtin.debug: + msg: "Image already exists on target" + when: result_check_image.images | length > 0 + +- name: APP | Build the docker image + ansible.builtin.command: + cmd: docker build . -t "{{ c3infodesk_printer_docker_img_app_name }}":"{{ c3infodesk_printer_docker_img_app_tag }}" -f docker/app/Dockerfile + args: + chdir: "{{ c3infodesk_printer_folder }}" + register: build_img_result + when: result_check_image.images | length <= 0 + +- name: APP | DEBUG -> Output from creating the docker image + ansible.builtin.debug: + msg: "{{ build_img_result }}" + when: + - c3infodesk_printer_debug_create_image_app | bool + - build_img_result is defined \ No newline at end of file diff --git a/roles/docker_images/tasks/docker_image_cups.yml b/roles/docker_images/tasks/docker_image_cups.yml new file mode 100644 index 0000000000000000000000000000000000000000..a2810b2b8fdee68a75c66c7ee48eac5efc22d37b --- /dev/null +++ b/roles/docker_images/tasks/docker_image_cups.yml @@ -0,0 +1,32 @@ +--- +# Creates the c3infodesk-cups docker image + +### +### LINKS +### +# https://docs.ansible.com/ansible/latest/collections/community/docker/docker_image_module.html + +- name: CUPS | Check if the image already exists on the system + community.docker.docker_image_info: + name: "{{ c3infodesk_printer_docker_img_cups_name }}" + register: result_check_image + +- name: CUPS | Check image exists answer + ansible.builtin.debug: + msg: "Image already exists on target" + when: result_check_image.images | length > 0 + +- name: CUPS | Build the docker image + ansible.builtin.command: + cmd: docker build . -t "{{ c3infodesk_printer_docker_img_cups_name }}":"{{ c3infodesk_printer_docker_img_cups_tag }}" -f docker/cups/Dockerfile + args: + chdir: "{{ c3infodesk_printer_folder }}" + register: build_img_result + when: result_check_image.images | length <= 0 + +- name: CUPS | DEBUG -> Output from creating the docker image + ansible.builtin.debug: + msg: "{{ build_img_result }}" + when: + - c3infodesk_printer_debug_create_image_cups | bool + - build_img_result is defined \ No newline at end of file diff --git a/roles/docker_images/tasks/docker_image_proxy.yml b/roles/docker_images/tasks/docker_image_proxy.yml new file mode 100644 index 0000000000000000000000000000000000000000..961a43d72e1198c05be5f5666b3825b8023bb308 --- /dev/null +++ b/roles/docker_images/tasks/docker_image_proxy.yml @@ -0,0 +1,27 @@ +--- +# Creates the c3infodesk-proxy docker image + +- name: PROXY | Check if the image already exists on the system + community.docker.docker_image_info: + name: "{{ c3infodesk_printer_docker_img_proxy_name }}" + register: result_check_image + +- name: PROXY | Check image exists answer + ansible.builtin.debug: + msg: "Image already exists on target" + when: result_check_image.images | length > 0 + +- name: PROXY | Build the docker image + ansible.builtin.command: + cmd: docker build . -t "{{ c3infodesk_printer_docker_img_proxy_name }}":"{{ c3infodesk_printer_docker_img_proxy_tag }}" -f docker/proxy/Dockerfile + args: + chdir: "{{ c3infodesk_printer_folder }}" + register: build_img_result + when: result_check_image.images | length <= 0 + +- name: PROXY | DEBUG -> Output from creating the docker image + ansible.builtin.debug: + msg: "{{ build_img_result }}" + when: + - c3infodesk_printer_debug_create_image_cups | bool + - build_img_result is defined \ No newline at end of file diff --git a/roles/docker_images/tasks/main.yml b/roles/docker_images/tasks/main.yml new file mode 100644 index 0000000000000000000000000000000000000000..c925fcbae643d0cf2151c604b8f803956ae7bdd9 --- /dev/null +++ b/roles/docker_images/tasks/main.yml @@ -0,0 +1,6 @@ +--- +# tasks file for docker-images + +- import_tasks: docker_image_cups.yml +- import_tasks: docker_image_app.yml +- import_tasks: docker_image_proxy.yml