diff --git a/README.md b/README.md index 67c41ddc378e921d3a252e67b7aa21e6562bc4a9..7e13159860dfb865d5b9359d1fe6d2b9794c3c70 100644 --- a/README.md +++ b/README.md @@ -3,19 +3,17 @@ ## WIP -- [ ] finish the roles for deploying the **c3InfoDesk Printer** +- [x] Finish the roles for deploying the **c3InfoDesk Printer**. - [x] dependencies - [x] clone_repositories - [x] docker_images - - [ ] docker_containers -- [ ] set ansible-lint + - [x] docker_containers +- [ ] 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 +This is a repo for deploying the the printer system used at the c3infodesk for printing EXTREMILY NECESSARY documents. ---- ## Roles Here are the used roles: @@ -23,7 +21,19 @@ Here are the used roles: - [dependencies](roles/dependencies/README.md) - [clone_repositories](roles/clone_repositories/README.md) - [docker_images](roles/docker_images/README.md) - +- [docker_containers](roles/docker_containers/README.md) + +## How to use this +- 1. Clone this repo. +- 2. Edit the files. + - Set your **remote_user** configuration at the **ansible.cfg** file. + - Set your **inventories/host_vars/<TARGET_NAME>** file. +- 3. Run the playbooks + - Example for deploying the containers at the target: + ```bash + ansible-playbook -i inventories/hosts playbook_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. ## License diff --git a/inventories/host_vars/example_server.yml b/inventories/host_vars/example_server.yml index 0e1e96d3ed454a209e6a4fce335035143afd844a..18dbf7444df9b1426cde8688a0a65ef2f9c9fd07 100644 --- a/inventories/host_vars/example_server.yml +++ b/inventories/host_vars/example_server.yml @@ -28,3 +28,17 @@ c3infodesk_printer_repo_new_branch_name: "test_branch" # c3infodesk_printer_debug_create_image_cups: true # c3infodesk_printer_debug_create_image_app: true # c3infodesk_printer_debug_create_image_proxy: true + +### +### roles/docker_containers +### + +### CUPS +# c3infodesk_printer_host_cups_disable: true +# c3infodesk_printer_host_cups_mask: true + +### COMPOSE +# c3infodesk_printer_docker_compose_up: true +# c3infodesk_printer_docker_compose_stop: true +# c3infodesk_printer_docker_compose_restart: true +# c3infodesk_printer_docker_compose_down: true diff --git a/playbook_example_05_docker_containers.yml b/playbook_example_05_docker_containers.yml new file mode 100644 index 0000000000000000000000000000000000000000..c6b865cc581a62caf49fa509a60710c10ae95780 --- /dev/null +++ b/playbook_example_05_docker_containers.yml @@ -0,0 +1,11 @@ +--- + +- name: Playbook for running the role 'docker_containers' + hosts: + - example_servers_group + roles: + - role: 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/README.md b/roles/README.md new file mode 100644 index 0000000000000000000000000000000000000000..88fa728a333a4a04e897152d08ca5551396f7022 --- /dev/null +++ b/roles/README.md @@ -0,0 +1,13 @@ +# c3InfoDesk Deployment Roles + + + +## What is this? +The roles used for deploying the [c3InfoDesk Printer](https://git.cccv.de/fejao/c3infodesk-printer) + + +## Roles +- [dependencies](roles/dependencies/README.md) +- [clone_repositories](roles/clone_repositories/README.md) +- [docker_images](roles/docker_images/README.md) +- [docker_containers](roles/docker_containers/README.md) diff --git a/roles/docker_containers/README.md b/roles/docker_containers/README.md new file mode 100644 index 0000000000000000000000000000000000000000..cf87bd9ae3d237868dc6cfbd601192456dae6f7d --- /dev/null +++ b/roles/docker_containers/README.md @@ -0,0 +1,159 @@ +# 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. +- 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. + - #### 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 playbook **playbook_example_05_docker_containers.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_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: 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: 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: + - 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" + ``` + + + +## 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 new file mode 100644 index 0000000000000000000000000000000000000000..905d5d658cb72802a59dd0620f7d756b95c3c7f6 --- /dev/null +++ b/roles/docker_containers/defaults/main.yml @@ -0,0 +1,26 @@ +--- +# 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 new file mode 100644 index 0000000000000000000000000000000000000000..9831b4faeb8b2454284e25b1f04ac0c8080945f3 --- /dev/null +++ b/roles/docker_containers/meta/main.yml @@ -0,0 +1,16 @@ +galaxy_info: + role_name: docker-containers + description: Role to work with the containers for the 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 + - role: docker_images diff --git a/roles/docker_containers/tasks/main.yml b/roles/docker_containers/tasks/main.yml new file mode 100644 index 0000000000000000000000000000000000000000..b1ca66fc4f6299096b2fccd8a83b1f6f6ed1e1ff --- /dev/null +++ b/roles/docker_containers/tasks/main.yml @@ -0,0 +1,22 @@ +--- +# 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 new file mode 100644 index 0000000000000000000000000000000000000000..61c92b5dc48049e6dd7f51ffc130111b0d200495 --- /dev/null +++ b/roles/docker_containers/tasks/printer_compose_down.yml @@ -0,0 +1,14 @@ +--- +# 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 new file mode 100644 index 0000000000000000000000000000000000000000..df26924d9de57d4bd02361a0add84714fe802165 --- /dev/null +++ b/roles/docker_containers/tasks/printer_compose_restart.yml @@ -0,0 +1,13 @@ +--- +# 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 new file mode 100644 index 0000000000000000000000000000000000000000..30d8c35d65ee2b3713420c7389a6c1bba5344730 --- /dev/null +++ b/roles/docker_containers/tasks/printer_compose_stop.yml @@ -0,0 +1,14 @@ +--- +# 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 new file mode 100644 index 0000000000000000000000000000000000000000..b621ae367432433632987281105bf26c0280b842 --- /dev/null +++ b/roles/docker_containers/tasks/printer_compose_up.yml @@ -0,0 +1,14 @@ +--- +# tasks file for docker-compose up + +- name: COMPOSE UP | Run `docker compose up` + community.docker.docker_compose_v2: + # project_src: "{{ c3infodesk_project_src }}" + 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 new file mode 100644 index 0000000000000000000000000000000000000000..e5ecc25fae946b522ca7553ee934d8e4c628512c --- /dev/null +++ b/roles/docker_containers/tasks/printer_host_cups_disable.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 | DEBUG -> Print cups_status + ansible.builtin.debug: + msg: "cups_status: {{ cups_status }}" + when: c3infodesk_printer_host_cups_disable_debug | bool + +- 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' + +- name: DISABLE CUPS | Disable the running CUPS on target + ansible.builtin.command: + cmd: systemctl disable cups + become: true + # when: cups_status != 'masked' + when: + - cups_status is defined + - cups_status != 'masked' + +- name: DISABLE CUPS | Mask the running CUPS on target + ansible.builtin.command: + cmd: systemctl mask cups + become: true + # when: cups_status != 'masked' + when: + - cups_status is defined + - cups_status != 'masked' \ No newline at end of file diff --git a/roles/docker_images/README.md b/roles/docker_images/README.md index 836b1ef38593df966263c3c9ba573b8be6e84acd..39568d46950734b8b95fbf3b00626013eb5304a9 100644 --- a/roles/docker_images/README.md +++ b/roles/docker_images/README.md @@ -52,7 +52,7 @@ Here are the variables setted: ## Dependencies The role dependencies are: - [dependencies(role)](roles/dependencies/README.md) - - [clone_reposiries](roles/clone_repositories/README.md) + - [clone_repositories](roles/clone_repositories/README.md) ## Example Playbook