Instalación de Grafana, Prometheus y Pi-hole con Ansible en Raspberry Pi
Se describe el proceso para instalar estas aplicaciones en Raspberry Pi:
uname -r
Devuelve el siguiente resultado sobre la version del SO:
6.1.0-rpi6-rpi-v8
Para configurar tu red y monitorearla con Grafana, Prometheus y Pi-hole usando Ansible, sigue estos pasos:
- Instala ansible:
- Clona el repositorio:
- Para instalar Docker Compose manualmente:
pipx install --include-deps ansible
pipx upgrade --include-injected ansible
git clone https://github.com/geerlingguy/internet-pi.git
cd internet-pi/
cp example.inventory.ini inventory.ini
cp example.config.yml config.yml
nano inventory.ini
nano config.yml
sudo ansible-playbook main.yml
Yo he tenido problemas al ejecutar el playbook porque daba el siguiente error al instalar docker-compose:
TASK [Install Docker Compose using Pip.] *************************************************************************
fatal: [127.0.0.1]: FAILED! => {"changed": false, "cmd": ["/usr/local/bin/pip3", "install", "docker-compose"], "msg": "\n:stderr: error: externally-managed-environment\n\n× This environment is externally managed\n╰─> To install Python packages system-wide, try apt install\n python3-xyz, where xyz is the package you are trying to\n install.\n \n If you wish to install a non-Debian-packaged Python package,\n create a virtual environment using python3 -m venv path/to/venv.\n Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make\n sure you have python3-full installed.\n \n For more information visit http://rptl.io/venv\n\nnote: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.\nhint: See PEP 668 for the detailed specification.\nDEPRECATION: Loading egg at /usr/local/lib/python3.11/dist-packages/vilib-0.2.0-py3.11.egg is deprecated. pip 24.3 will enforce this behaviour change. A possible replacement is to use pip for package installation.. Discussion can be found at https://github.com/pypa/pip/issues/12330\n"}
Para solucionarlo he intentado instalar docker-compose manualmente, pero tambien da el siguiente error:
pip install docker-compose
error: externally-managed-environment
× This environment is externally managed
╰─> To install Python packages system-wide, try apt install
python3-xyz, where xyz is the package you are trying to
install.
If you wish to install a non-Debian-packaged Python package,
create a virtual environment using python3 -m venv path/to/venv.
Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make
sure you have python3-full installed.
For more information visit http://rptl.io/venv
note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
hint: See PEP 668 for the detailed specification.
Tambien lo intento instalar con:
pipx install docker-compose
pero tambien da error:
Fatal error from pip prevented installation. Full pip output in file:
/.local/pipx/logs/cmd_2023-11-14_22.35.44_pip_errors.log
pip seemed to fail to build package:
PyYAML6,>=3.10
Some possibly relevant errors from pip install:
error: subprocess-exited-with-error
AttributeError: cython_sources
Error installing docker-compose.
Entonces sigo las instrucciones descritas en este enlace para instalar docker-compose en un entorno virtual
python3 -m venv /ruta/a/tu/entorno_virtual
source /ruta/a/tu/entorno_virtual/bin/activate
pip install PyYAML==5.4.1
pipx install docker-compose
Después de seguir estos pasos, deberías tener instalados Grafana, Prometheus, Pi-hole y Docker Compose para monitorear tu red.
Recuerda ajustar los comandos según tu entorno y las necesidades específicas de tu configuración.
Despues modifica el archivo docker.yml para actualizar el path al comando de instalacion a la nueva ubicacion en el entorno virtual
nano tasks/docker.yml
El archivo docker.yml contiene pip3 como ejecutable, para que se ejecute pip3 en el entorno virtual, modifica el path del executable:
- name: Install Docker Compose using Pip.
ansible.builtin.pip:
name: docker-compose
state: present
executable: /ruta/a/tu/entorno_virtual/bin/pip3
Ahora activamos el entorno virtual y ejecutamos el playbook:
source ~/python-venv/bin/activate
ansible-playbook ~/internet-pi/main.yml