Skip to content

Commit

Permalink
Actualiza roles cgroups y docker para ser mas idempotentes y pasen an…
Browse files Browse the repository at this point in the history
…sible-lint.
  • Loading branch information
Jorge Medina committed Jun 29, 2024
1 parent 8a8fd30 commit de55993
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 10 deletions.
2 changes: 2 additions & 0 deletions ansible/deploy-pi-hole.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
roles:
- general-settings
- ssh-server
- cgroups
- docker
post_tasks:
- name: Limpiar paquetes del cache
ansible.builtin.apt:
Expand Down
14 changes: 12 additions & 2 deletions ansible/roles/cgroups/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
---
# handlers file for cgroups

- name: Restart server
ansible.builtin.shell: nohup bash -c "/bin/sleep 5 && /sbin/shutdown -r now" &
- name: Reiniciar si se actualiza cmdline.txt
ansible.builtin.reboot:
msg: "Reiniciando para aplicar configuración de cgroups"
reboot_timeout: 60

- name: Verificar que los cgroups están habilitados
ansible.builtin.command: grep cgroup /proc/cmdline
register: cmdline_output
changed_when: false

- name: Mostrar resultado de la verificación de cgroups
ansible.builtin.debug:
msg: "{{ cmdline_output.stdout }}"
26 changes: 18 additions & 8 deletions ansible/roles/cgroups/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
---
# tasks file for cgroups

- name: Agregar soporte cgroups de cpu y memoria al kernel
- name: Instalar paquetes necesarios para cgroups
ansible.builtin.apt:
name:
- cgroup-tools
- libcgroup2
state: present

- name: Verificar si la configuración de cgroups ya está presente
ansible.builtin.command: grep 'cgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory' /boot/firmware/cmdline.txt
register: cgroups_config_present
ignore_errors: true
changed_when: false

- name: Agregar soporte cgroups de cpu y memoria al kernel si no esta presente
ansible.builtin.lineinfile:
path: /boot/cmdline.txt
path: /boot/firmware/cmdline.txt
backrefs: true
regexp: '^(.*)rootwait$'
line: '\1rootwait cgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory'
notify: restart server

- name: Esperar a que el nodo reinicie
ansible.builtin.wait_for_connection:
timeout: 300
delay: 30
state: present
when: cgroups_config_present.rc != 0
notify: Reiniciar si se actualiza cmdline.txt
38 changes: 38 additions & 0 deletions ansible/roles/docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
docker
======

Deploy docker to run containers

Requirements
------------

Debian based system.

Role Variables
--------------

Not at the moment.

Dependencies
------------

Not at the moment.

Example Playbook
----------------

To use this role, just include it in your playbook, for example:

- hosts: servers
roles:
- docker

License
-------

MIT

Author Information
------------------

Please any question, please contact the autor at: jorge.medina@kronops.com.mx.
4 changes: 4 additions & 0 deletions ansible/roles/docker/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
# defaults file for docker

docker_release: "bookworm"
15 changes: 15 additions & 0 deletions ansible/roles/docker/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
galaxy_info:
role_name: docker
author: Jorge Medina
description: Deploy docker to run containers
company: KronOps
license: MIT
min_ansible_version: "2.9"
platforms:
- name: Debian
versions:
- bookworm
galaxy_tags:
- containers
dependencies: []
45 changes: 45 additions & 0 deletions ansible/roles/docker/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
# tasks file for docker

- name: Instalar dependencias de docker
ansible.builtin.apt:
name:
- gnupg2
- software-properties-common
- python3-setuptools
- python3-pip
- python3-websocket
- python3-docker
state: present

- name: Instalar llave de repositorio apt para docker
ansible.builtin.apt_key:
url: https://download.docker.com/linux/debian/gpg
state: present

- name: Instalar el repositorio apt para docker
ansible.builtin.apt_repository:
repo: deb [arch=arm64] https://download.docker.com/linux/debian {{ docker_release }} stable
filename: docker

- name: Instalar Docker y paquetes relacionados
ansible.builtin.apt:
name:
- docker-ce
- docker-ce-cli
- containerd.io
- docker-buildx-plugin
- docker-compose-plugin
state: present

- name: Agregar usuario ansible al grupo docker
ansible.builtin.user:
name: "{{ ansible_ssh_user }}"
append: true
groups: docker

- name: Iniciar servicio docker al arranque del sistema
ansible.builtin.service:
name: docker
state: started
enabled: true

0 comments on commit de55993

Please sign in to comment.