From abfebdca875bdd9f3b6357b5f1223dd338bec3b7 Mon Sep 17 00:00:00 2001 From: fejao <mail@fejao.de> Date: Mon, 10 Mar 2025 20:25:33 +0100 Subject: [PATCH] Updated files --- README.md | 118 ++++++------------ defaults/main.yml | 30 ++--- meta/main.yml | 13 +- molecule/README.md | 28 ++++- ...mpose_down.yml => docker_compose_down.yml} | 4 +- ...restart.yml => docker_compose_restart.yml} | 4 +- ...mpose_stop.yml => docker_compose_stop.yml} | 4 +- ...r_compose_up.yml => docker_compose_up.yml} | 4 +- tasks/main.yml | 32 ++--- tasks/printer_host_cups_disable.yml | 40 ------ 10 files changed, 104 insertions(+), 173 deletions(-) rename tasks/{printer_compose_down.yml => docker_compose_down.yml} (68%) rename tasks/{printer_compose_restart.yml => docker_compose_restart.yml} (70%) rename tasks/{printer_compose_stop.yml => docker_compose_stop.yml} (68%) rename tasks/{printer_compose_up.yml => docker_compose_up.yml} (68%) delete mode 100644 tasks/printer_host_cups_disable.yml diff --git a/README.md b/README.md index 3abb3d5..cea3e0b 100644 --- a/README.md +++ b/README.md @@ -33,54 +33,40 @@ You need to set some configuration for this to work ## 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 +- ### c3infodesk_deployment_docker_compose_up + - This should be a **boolean** entry with the value if want or not to run the **'docker compose up'** command for the containers. + - **DEFAULT**: *false* + +- ### c3infodesk_deployment_docker_compose_restart + - This should be a **boolean** entry with the value if want or not to run the **'docker compose restart'** command for the containers. + - **DEFAULT**: *false* + +- ### c3infodesk_deployment_docker_compose_stop + - This should be a **boolean** entry with the value if want or not to run the **'docker compose stop'** command for the containers. + - **DEFAULT**: *false* + +- ### c3infodesk_deployment_docker_compose_down + - This should be a **boolean** entry with the value if want or not to run the **'docker compose down'** command for the containers. + - **DEFAULT**: *false* + +- ### Debugging the outputs + If you want to see the ouputs from the **docker compose** commands, you can set this here: + + - #### c3infodesk_deployment_docker_compose_up_debug + - This should be a **boolean** entry with the value if want or not to see the output from the **'docker compose up'** command. + - **DEFAULT**: *false* + + - #### c3infodesk_deployment_docker_compose_restart_debug + - This should be a **boolean** entry with the value if want or not to see the output from the **'docker compose restart'** command. + - **DEFAULT**: *false* + + - #### c3infodesk_deployment_docker_compose_stop_debug + - This should be a **boolean** entry with the value if want or not to see the output from the **'docker compose stop'** command. + - **DEFAULT**: *false* + + - #### c3infodesk_deployment_docker_compose_down_debug + - This should be a **boolean** entry with the value if want or not to see the output from the **'docker compose down'** command. + - **DEFAULT**: *false* ## Dependencies @@ -88,6 +74,7 @@ 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) + - [docker_xtras](https://git.cccv.de/fejao/c3infodesk-deployment-role-docker-xtras) ## Example Playbook @@ -107,7 +94,7 @@ The role dependencies are: And run the command: ```bash - ansible-playbook -i inventories/hosts playbooks/examples/05_docker_containers.yml + ansible-playbook -i inventories/hosts playbooks/example_c3infodesk_printer/c3infodesk_printer_05_docker_containers.yml ``` - ### Setting your own example @@ -118,8 +105,6 @@ The role dependencies are: 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 @@ -150,7 +135,7 @@ The role dependencies are: roles: - role: roles/c3infodesk-deployment-role-docker-containers vars: - printer_docker_compose_restart: true + c3infodesk_deployment_docker_compose_up: true ``` And call the playbook as: @@ -170,37 +155,12 @@ The role dependencies are: 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" + ansible-playbook -i <INVENTORY> <PLAYBOOK_NAME>.yml --extra-vars "c3infodesk_deployment_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 - ``` +For testing this role, please reference [how to use molecule tests](https://git.cccv.de/fejao/c3infodesk-deployment-role-docker-containers/-/tree/main/molecule) ## License diff --git a/defaults/main.yml b/defaults/main.yml index 905d5d6..9f242c0 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,26 +1,18 @@ --- # defaults file for docker-containers -# c3infodesk_project_src: "PLEASE SET THIS VARIABLE" - -### -### c3InfoDesk Printer -### +### COMPOSE UP +c3infodesk_deployment_docker_compose_up: false +c3infodesk_deployment_docker_compose_up_debug: false -### CUPS -c3infodesk_printer_host_cups_disable: false -c3infodesk_printer_host_cups_disable_debug: false -c3infodesk_printer_host_cups_mask: false +### COMPOSE RESTART +c3infodesk_deployment_docker_compose_restart: false +c3infodesk_deployment_docker_compose_restart_debug: 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 +c3infodesk_deployment_docker_compose_stop: false +c3infodesk_deployment_docker_compose_stop_debug: false + ### COMPOSE DOWN -c3infodesk_printer_docker_compose_down: false -c3infodesk_printer_docker_compose_down_debug: false +c3infodesk_deployment_docker_compose_down: false +c3infodesk_deployment_docker_compose_down_debug: false diff --git a/meta/main.yml b/meta/main.yml index 52f7a8c..77bd272 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -7,15 +7,16 @@ galaxy_info: company: cccv.de license: "MIT / BSD" min_ansible_version: '2.10' - galaxy_tags: [] + galaxy_tags: + - docker + - container + - containers + - c3infodesk + - c3infodesk-printer + - c3buttons # 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 - 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 index 4e02fc3..7c4b785 100644 --- a/molecule/README.md +++ b/molecule/README.md @@ -1,4 +1,4 @@ -## ansible molecule tests for role: docker_containers +# ansible molecule tests for role: docker_containers @@ -7,6 +7,7 @@ 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 @@ -34,9 +35,26 @@ With **ansible molecule** you can test your role locally without the need of usi ## 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 -``` +- #### 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 + ``` + + +## License + +MIT / BSD + + +## Author Information + +[https://chaos.social/@fejao](https://chaos.social/@fejao) diff --git a/tasks/printer_compose_down.yml b/tasks/docker_compose_down.yml similarity index 68% rename from tasks/printer_compose_down.yml rename to tasks/docker_compose_down.yml index 7f946d0..ed13da3 100644 --- a/tasks/printer_compose_down.yml +++ b/tasks/docker_compose_down.yml @@ -3,11 +3,11 @@ - name: COMPOSE DOWN | Run `docker compose down` community.docker.docker_compose_v2: - project_src: "{{ c3infodesk_project_src }}" + project_src: "{{ c3infodesk_deployment_paht_docker_folder }}" 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 + when: c3infodesk_deployment_docker_compose_down_debug | bool diff --git a/tasks/printer_compose_restart.yml b/tasks/docker_compose_restart.yml similarity index 70% rename from tasks/printer_compose_restart.yml rename to tasks/docker_compose_restart.yml index df26924..64ed811 100644 --- a/tasks/printer_compose_restart.yml +++ b/tasks/docker_compose_restart.yml @@ -3,11 +3,11 @@ - name: COMPOSE RESTART | Run `docker compose restart` community.docker.docker_compose_v2: - project_src: "{{ c3infodesk_project_src }}" + project_src: "{{ c3infodesk_deployment_paht_docker_folder }}" 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 + when: c3infodesk_deployment_docker_compose_restart_debug | bool diff --git a/tasks/printer_compose_stop.yml b/tasks/docker_compose_stop.yml similarity index 68% rename from tasks/printer_compose_stop.yml rename to tasks/docker_compose_stop.yml index e671330..494a221 100644 --- a/tasks/printer_compose_stop.yml +++ b/tasks/docker_compose_stop.yml @@ -3,11 +3,11 @@ - name: COMPOSE STOP | Run `docker compose stop` community.docker.docker_compose_v2: - project_src: "{{ c3infodesk_project_src }}" + project_src: "{{ c3infodesk_deployment_paht_docker_folder }}" 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 + when: c3infodesk_deployment_docker_compose_stop_debug | bool diff --git a/tasks/printer_compose_up.yml b/tasks/docker_compose_up.yml similarity index 68% rename from tasks/printer_compose_up.yml rename to tasks/docker_compose_up.yml index d576754..d8a023d 100644 --- a/tasks/printer_compose_up.yml +++ b/tasks/docker_compose_up.yml @@ -3,11 +3,11 @@ - name: COMPOSE UP | Run `docker compose up` community.docker.docker_compose_v2: - project_src: "{{ c3infodesk_printer_folder_docker }}" + project_src: "{{ c3infodesk_deployment_paht_docker_folder }}" 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 + when: c3infodesk_deployment_docker_compose_up_debug | bool diff --git a/tasks/main.yml b/tasks/main.yml index b1ca66f..7a59839 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,22 +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 tasks for 'compose up' + tags: containers_up + ansible.builtin.import_tasks: docker_compose_up.yml + when: c3infodesk_deployment_docker_compose_up | bool -- name: Running printer compose up - ansible.builtin.import_tasks: printer_compose_up.yml - when: c3infodesk_printer_docker_compose_up | bool +- name: Running tasks for 'compose restart' + ansible.builtin.import_tasks: docker_compose_restart.yml + when: c3infodesk_deployment_docker_compose_restart | bool + tags: containers_restart -- name: Running printer compose stop - ansible.builtin.import_tasks: printer_compose_stop.yml - when: c3infodesk_printer_docker_compose_stop | bool +- name: Running tasks for 'compose stop' + tags: containers_stop + ansible.builtin.import_tasks: docker_compose_stop.yml + when: c3infodesk_deployment_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 +- name: Running tasks for 'compose down' + tags: containers_down + ansible.builtin.import_tasks: docker_compose_down.yml + when: c3infodesk_deployment_docker_compose_down | bool diff --git a/tasks/printer_host_cups_disable.yml b/tasks/printer_host_cups_disable.yml deleted file mode 100644 index c6d6a48..0000000 --- a/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 -- GitLab