{"id":15205,"date":"2025-09-12T00:12:04","date_gmt":"2025-09-11T22:12:04","guid":{"rendered":"https:\/\/www.palentino.es\/blog\/?p=15205"},"modified":"2025-09-12T19:46:28","modified_gmt":"2025-09-12T17:46:28","slug":"%f0%9f%93%9a-caso-practico-como-palformacion-monta-su-plataforma-de-e-learning-con-terraform-ansible-y-zabbix","status":"publish","type":"post","link":"https:\/\/www.palentino.es\/blog\/%f0%9f%93%9a-caso-practico-como-palformacion-monta-su-plataforma-de-e-learning-con-terraform-ansible-y-zabbix\/","title":{"rendered":"&#x1f4da; Caso pr\u00e1ctico: c\u00f3mo PalFormaci\u00f3n monta su plataforma de e-learning con Terraform, Ansible y Zabbix"},"content":{"rendered":"<p>La empresa <strong>PalFormaci\u00f3n <\/strong>(ejemplo ficticio para entender el caso pr\u00e1ctico), dedicada a la formaci\u00f3n online, quiere lanzar una plataforma propia de cursos virtuales.<br \/>\nEl reto es conseguir una soluci\u00f3n que sea:<\/p>\n<ul>\n<li><strong>R\u00e1pida<\/strong>: poder desplegar entornos en minutos.<\/li>\n<li><strong>Estable<\/strong>: todos los servidores con configuraciones id\u00e9nticas.<\/li>\n<li><strong>Escalable<\/strong>: crecer cuando aumente la demanda de alumnos.<\/li>\n<li><strong>Fiable<\/strong>: con monitorizaci\u00f3n en tiempo real.<\/li>\n<\/ul>\n<p>Hasta ahora, el proceso era manual y lento: pedir servidores, instalarlos a mano (Apache, PHP, MySQL\u2026), y vigilarlos con scripts improvisados. Esto llevaba semanas y era poco sostenible.<\/p>\n<p>El objetivo: migrar a una estrategia <strong>DevOps moderna<\/strong> basada en <strong>Terraform<\/strong> (infraestructura como c\u00f3digo), <strong>Ansible<\/strong> (automatizaci\u00f3n de configuraci\u00f3n) y <strong>Zabbix<\/strong> (monitorizaci\u00f3n).<\/p>\n<p><a href=\"https:\/\/www.palentino.es\/blog\/wp-content\/uploads\/2025\/09\/flujo-operativo-palentino.gif\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-15208 size-full\" src=\"https:\/\/www.palentino.es\/blog\/wp-content\/uploads\/2025\/09\/flujo-operativo-palentino.gif\" alt=\"\" width=\"1403\" height=\"936\" \/><\/a><\/p>\n<p><!--more--><\/p>\n<hr \/>\n<h2>Paso 1: Infraestructura con Terraform<\/h2>\n<p>PalFormaci\u00f3n necesita:<\/p>\n<ul>\n<li>2 servidores web para la aplicaci\u00f3n.<\/li>\n<li>1 servidor de base de datos (MySQL).<\/li>\n<li>1 balanceador de carga (HAProxy).<\/li>\n<\/ul>\n<p>Con Terraform, esta infraestructura se define en c\u00f3digo.<\/p>\n<h3>C\u00f3digo (extracto<\/p>\n<div class=\"codecolorer-container text mac-classic\" style=\"overflow:auto;white-space:nowrap;width:635px;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/><\/div><\/td><td><div class=\"text codecolorer\">main.tf<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>)<\/h3>\n<pre>\n\n<div class=\"codecolorer-container text mac-classic language-hcl\" style=\"overflow:auto;white-space:nowrap;width:635px;height:300px;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/>5<br \/>6<br \/>7<br \/>8<br \/>9<br \/>10<br \/>11<br \/>12<br \/>13<br \/>14<br \/>15<br \/>16<br \/>17<br \/>18<br \/>19<br \/>20<br \/>21<br \/>22<br \/>23<br \/>24<br \/>25<br \/><\/div><\/td><td><div class=\"text codecolorer\">provider &quot;aws&quot; { region = &quot;us-east-1&quot; }<br \/>\n<br \/>\nvariable &quot;num_frontends&quot; { default = 2 }<br \/>\n<br \/>\nresource &quot;aws_instance&quot; &quot;web&quot; {<br \/>\n&nbsp; count = var.num_frontends<br \/>\n&nbsp; ami &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = &quot;ami-xxxxxxxx&quot; &nbsp; # Ubuntu<br \/>\n&nbsp; instance_type = &quot;t2.micro&quot;<br \/>\n&nbsp; key_name &nbsp; &nbsp; &nbsp;= &quot;mi-clave-ssh&quot;<br \/>\n&nbsp; tags = { Name = &quot;pf-web-${count.index}&quot; }<br \/>\n}<br \/>\n<br \/>\nresource &quot;aws_instance&quot; &quot;db&quot; {<br \/>\n&nbsp; ami &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = &quot;ami-xxxxxxxx&quot;<br \/>\n&nbsp; instance_type = &quot;t2.small&quot;<br \/>\n&nbsp; key_name &nbsp; &nbsp; &nbsp;= &quot;mi-clave-ssh&quot;<br \/>\n&nbsp; tags = { Name = &quot;pf-db&quot; }<br \/>\n}<br \/>\n<br \/>\nresource &quot;aws_instance&quot; &quot;lb&quot; {<br \/>\n&nbsp; ami &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = &quot;ami-xxxxxxxx&quot;<br \/>\n&nbsp; instance_type = &quot;t2.micro&quot;<br \/>\n&nbsp; key_name &nbsp; &nbsp; &nbsp;= &quot;mi-clave-ssh&quot;<br \/>\n&nbsp; tags = { Name = &quot;pf-lb&quot; }<br \/>\n}<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n\n<\/pre>\n<p>Con un simple:<\/p>\n<pre>\n\n<div class=\"codecolorer-container text mac-classic language-bash\" style=\"overflow:auto;white-space:nowrap;width:635px;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/><\/div><\/td><td><div class=\"text codecolorer\">terraform init<br \/>\nterraform apply -auto-approve<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n\n<\/pre>\n<p>&#x1f4cc; Resultado: servidores creados en AWS con sus IPs y listos para configurar.<\/p>\n<hr \/>\n<h2>Paso 2: Configuraci\u00f3n con Ansible<\/h2>\n<p>Los servidores est\u00e1n vac\u00edos. Con <strong>Ansible<\/strong> aplicamos la configuraci\u00f3n necesaria.<\/p>\n<ul>\n<li>En los <strong>web<\/strong>: Nginx + PHP + aplicaci\u00f3n PalFormaci\u00f3n.<\/li>\n<li>En el <strong>db<\/strong>: MySQL + base inicial.<\/li>\n<li>En el <strong>lb<\/strong>: HAProxy para repartir tr\u00e1fico.<\/li>\n<\/ul>\n<h3>C\u00f3digo (extracto<\/p>\n<div class=\"codecolorer-container text mac-classic\" style=\"overflow:auto;white-space:nowrap;width:635px;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/><\/div><\/td><td><div class=\"text codecolorer\">playbook.yml<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>)<\/h3>\n<pre>\n\n<div class=\"codecolorer-container text mac-classic language-yaml\" style=\"overflow:auto;white-space:nowrap;width:635px;height:300px;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/>5<br \/>6<br \/>7<br \/>8<br \/>9<br \/>10<br \/>11<br \/>12<br \/>13<br \/>14<br \/>15<br \/>16<br \/>17<br \/>18<br \/>19<br \/>20<br \/>21<br \/>22<br \/>23<br \/>24<br \/>25<br \/>26<br \/>27<br \/>28<br \/>29<br \/>30<br \/>31<br \/>32<br \/>33<br \/>34<br \/>35<br \/>36<br \/>37<br \/>38<br \/>39<br \/>40<br \/>41<br \/>42<br \/>43<br \/><\/div><\/td><td><div class=\"text codecolorer\">- hosts: web<br \/>\n&nbsp; become: yes<br \/>\n&nbsp; tasks:<br \/>\n&nbsp; &nbsp; - name: Instalar Nginx y PHP<br \/>\n&nbsp; &nbsp; &nbsp; apt:<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; name: [nginx, php-fpm, php-mysql]<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; state: present<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; update_cache: yes<br \/>\n&nbsp; &nbsp; - name: P\u00e1gina inicial<br \/>\n&nbsp; &nbsp; &nbsp; copy:<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; dest: \/var\/www\/html\/index.html<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; content: &quot;&amp;lt;h1&amp;gt;Bienvenido a PalFormaci\u00f3n&amp;lt;\/h1&amp;gt;&quot;<br \/>\n<br \/>\n- hosts: db<br \/>\n&nbsp; become: yes<br \/>\n&nbsp; tasks:<br \/>\n&nbsp; &nbsp; - name: Instalar MySQL<br \/>\n&nbsp; &nbsp; &nbsp; apt:<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; name: mysql-server<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; state: present<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; update_cache: yes<br \/>\n&nbsp; &nbsp; - name: Crear base de datos<br \/>\n&nbsp; &nbsp; &nbsp; mysql_db:<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; name: palformacion<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; state: present<br \/>\n<br \/>\n- hosts: lb<br \/>\n&nbsp; become: yes<br \/>\n&nbsp; tasks:<br \/>\n&nbsp; &nbsp; - name: Instalar HAProxy<br \/>\n&nbsp; &nbsp; &nbsp; apt:<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; name: haproxy<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; state: present<br \/>\n&nbsp; &nbsp; - name: Configurar balanceo<br \/>\n&nbsp; &nbsp; &nbsp; copy:<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; dest: \/etc\/haproxy\/haproxy.cfg<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; content: |<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; frontend http_in<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bind *:80<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; default_backend web_backend<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; backend web_backend<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; server web1 {{ hostvars['WEB1'].ansible_host }}:80 check<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; server web2 {{ hostvars['WEB2'].ansible_host }}:80 check<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n\n<\/pre>\n<p>&#x1f4cc; Resultado: en minutos la plataforma est\u00e1 online, accesible a trav\u00e9s del balanceador.<\/p>\n<hr \/>\n<h2>Paso 3: Monitorizaci\u00f3n con Zabbix<\/h2>\n<p>Una plataforma de formaci\u00f3n <strong>no puede caerse en mitad de un curso<\/strong>.<br \/>\nPor eso, PalFormaci\u00f3n instala <strong>Zabbix agent<\/strong> en cada servidor:<\/p>\n<ul>\n<li>Los <strong>web<\/strong> reportan CPU, memoria y estado de Nginx.<\/li>\n<li>El <strong>db<\/strong> env\u00eda m\u00e9tricas de MySQL.<\/li>\n<li>El <strong>lb<\/strong> informa de conexiones activas.<\/li>\n<\/ul>\n<h3>C\u00f3digo (extracto<\/p>\n<div class=\"codecolorer-container text mac-classic\" style=\"overflow:auto;white-space:nowrap;width:635px;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/><\/div><\/td><td><div class=\"text codecolorer\">playbook_zabbix.yml<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>)<\/h3>\n<pre>\n\n<div class=\"codecolorer-container text mac-classic language-yaml\" style=\"overflow:auto;white-space:nowrap;width:635px;height:300px;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/>5<br \/>6<br \/>7<br \/>8<br \/>9<br \/>10<br \/>11<br \/>12<br \/>13<br \/>14<br \/>15<br \/>16<br \/>17<br \/>18<br \/>19<br \/>20<br \/>21<br \/><\/div><\/td><td><div class=\"text codecolorer\">- hosts: all<br \/>\n&nbsp; become: yes<br \/>\n&nbsp; tasks:<br \/>\n&nbsp; &nbsp; - name: Instalar agente Zabbix<br \/>\n&nbsp; &nbsp; &nbsp; apt:<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; name: zabbix-agent<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; state: present<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; update_cache: yes<br \/>\n&nbsp; &nbsp; - name: Configurar agente<br \/>\n&nbsp; &nbsp; &nbsp; copy:<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; dest: \/etc\/zabbix\/zabbix_agentd.conf<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; content: |<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Server=zabbix.midominio.com<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Hostname={{ inventory_hostname }}<br \/>\n&nbsp; &nbsp; &nbsp; notify: restart zabbix<br \/>\n<br \/>\n&nbsp; handlers:<br \/>\n&nbsp; &nbsp; - name: restart zabbix<br \/>\n&nbsp; &nbsp; &nbsp; service:<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; name: zabbix-agent<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; state: restarted<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n\n<\/pre>\n<p>&#x1f4cc; Resultado: todos los servidores quedan monitorizados en Zabbix, con paneles y alertas en tiempo real.<\/p>\n<hr \/>\n<h2>Paso 4: Escalabilidad r\u00e1pida<\/h2>\n<p>Antes, a\u00f1adir servidores era un dolor de cabeza. Ahora basta con cambiar una variable:<\/p>\n<pre>\n\n<div class=\"codecolorer-container text mac-classic language-hcl\" style=\"overflow:auto;white-space:nowrap;width:635px;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/><\/div><\/td><td><div class=\"text codecolorer\">variable &quot;num_frontends&quot; { default = 5 }<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n\n<\/pre>\n<p>Y aplicar de nuevo:<\/p>\n<pre>\n\n<div class=\"codecolorer-container text mac-classic language-bash\" style=\"overflow:auto;white-space:nowrap;width:635px;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/><\/div><\/td><td><div class=\"text codecolorer\">terraform apply -auto-approve<br \/>\nansible-playbook -i inventory.ini playbook.yml<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n\n<\/pre>\n<p>&#x1f4cc; Resultado: Terraform crea 3 servidores adicionales, Ansible los configura y Zabbix los monitoriza. Todo listo en menos de 20 minutos.<\/p>\n<hr \/>\n<h2>Diagrama del flujo en PalFormaci\u00f3n<\/h2>\n<pre>\n\n<div class=\"codecolorer-container text mac-classic\" style=\"overflow:auto;white-space:nowrap;width:635px;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/>5<br \/>6<br \/>7<br \/>8<br \/>9<br \/><\/div><\/td><td><div class=\"text codecolorer\">+-------------------+ &nbsp; &nbsp; &nbsp; +-------------------+ &nbsp; &nbsp; &nbsp; +-------------------+<br \/>\n| &nbsp; Terraform &nbsp; &nbsp; &nbsp; | ----&amp;gt; | &nbsp; Ansible &nbsp; &nbsp; &nbsp; &nbsp; | ----&amp;gt; | &nbsp; &nbsp; Zabbix &nbsp; &nbsp; &nbsp; &nbsp;|<br \/>\n| &quot;Construye la &nbsp; &nbsp; | &nbsp; &nbsp; &nbsp; | &quot;Configura apps, &nbsp;| &nbsp; &nbsp; &nbsp; | &quot;Vigila m\u00e9tricas &nbsp;|<br \/>\n| &nbsp;infraestructura&quot; | &nbsp; &nbsp; &nbsp; | &nbsp;bases de datos&quot; &nbsp;| &nbsp; &nbsp; &nbsp; | &nbsp;y env\u00eda alertas&quot; |<br \/>\n+-------------------+ &nbsp; &nbsp; &nbsp; +-------------------+ &nbsp; &nbsp; &nbsp; +-------------------+<br \/>\n<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | Infraestructura creada | <br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | Aplicaci\u00f3n desplegada &nbsp;| <br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | Monitorizaci\u00f3n activa &nbsp;|<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n\n<\/pre>\n<hr \/>\n<h2>&#x2705; Conclusi\u00f3n<\/h2>\n<p>Con Terraform + Ansible + Zabbix, <strong>PalFormaci\u00f3n<\/strong> logra:<\/p>\n<ul>\n<li>Desplegar entornos en minutos en lugar de semanas.<\/li>\n<li>Mantener todos los servidores configurados de manera id\u00e9ntica.<\/li>\n<li>Recibir alertas en tiempo real cuando algo falla.<\/li>\n<li>Escalar su infraestructura r\u00e1pidamente con un cambio de variable.<\/li>\n<\/ul>\n<p>&#x1f449; En resumen: <strong>Terraform construye, Ansible configura y Zabbix vigila<\/strong>.<br \/>\nUna combinaci\u00f3n perfecta para cualquier empresa que quiera ofrecer formaci\u00f3n online <strong>sin interrupciones y con confianza<\/strong>.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>La empresa PalFormaci\u00f3n (ejemplo ficticio para entender el caso pr\u00e1ctico), dedicada a la formaci\u00f3n online, quiere lanzar una plataforma propia de cursos virtuales. El reto es conseguir una soluci\u00f3n que sea: R\u00e1pida: poder desplegar entornos en minutos. Estable: todos los servidores con configuraciones id\u00e9nticas. Escalable: crecer cuando aumente la demanda de alumnos. Fiable: con monitorizaci\u00f3n en tiempo real. Hasta ahora, el proceso era manual y lento: pedir servidores, instalarlos a mano (Apache, PHP, MySQL\u2026), y vigilarlos con scripts improvisados. Esto llevaba semanas y era poco sostenible. El objetivo: migrar a una estrategia DevOps moderna basada en Terraform (infraestructura como c\u00f3digo), Ansible (automatizaci\u00f3n de configuraci\u00f3n) y Zabbix (monitorizaci\u00f3n).<\/p>\n","protected":false},"author":1,"featured_media":6194,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32],"tags":[],"class_list":["post-15205","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-formacion"],"_links":{"self":[{"href":"https:\/\/www.palentino.es\/blog\/wp-json\/wp\/v2\/posts\/15205","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.palentino.es\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.palentino.es\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.palentino.es\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.palentino.es\/blog\/wp-json\/wp\/v2\/comments?post=15205"}],"version-history":[{"count":5,"href":"https:\/\/www.palentino.es\/blog\/wp-json\/wp\/v2\/posts\/15205\/revisions"}],"predecessor-version":[{"id":15211,"href":"https:\/\/www.palentino.es\/blog\/wp-json\/wp\/v2\/posts\/15205\/revisions\/15211"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.palentino.es\/blog\/wp-json\/wp\/v2\/media\/6194"}],"wp:attachment":[{"href":"https:\/\/www.palentino.es\/blog\/wp-json\/wp\/v2\/media?parent=15205"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.palentino.es\/blog\/wp-json\/wp\/v2\/categories?post=15205"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.palentino.es\/blog\/wp-json\/wp\/v2\/tags?post=15205"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}