diff --git a/training/handler-nginx.yml b/training/handler-nginx.yml new file mode 100644 index 0000000..61b68cb --- /dev/null +++ b/training/handler-nginx.yml @@ -0,0 +1,15 @@ +- name: Prueba de handlers + hosts: webserver + become: yes + tasks: + - name: Copiar archivo de configuración + copy: + src: nginx.conf + dest: /etc/nginx/nginx.conf + notify: + - Reiniciar Nginx + handlers: + - name: Reiniciar Nginx + service: + name: nginx + state: restarted \ No newline at end of file diff --git a/training/handlers.yml b/training/handlers.yml index 02d808c..61b68cb 100644 --- a/training/handlers.yml +++ b/training/handlers.yml @@ -1,5 +1,5 @@ - name: Prueba de handlers - hosts: all + hosts: webserver become: yes tasks: - name: Copiar archivo de configuración diff --git a/training/import_playbooks.yml b/training/import_playbooks.yml new file mode 100644 index 0000000..d5df768 --- /dev/null +++ b/training/import_playbooks.yml @@ -0,0 +1,5 @@ +# import_playbook soporta handlers correctamente. +# Por lo tanto, este playbook importa otros playbooks que contienen handlers. +- import_playbook: install-nginx.yml +- import_playbook: handler-nginx.yml +- import_playbook: uninstall-nginx.yml \ No newline at end of file diff --git a/training/import_tasks.yml b/training/import_tasks.yml new file mode 100644 index 0000000..f74c202 --- /dev/null +++ b/training/import_tasks.yml @@ -0,0 +1,9 @@ +# Solo admite tasks y no soporte handlers correctamente. +# Por lo tanto, este playbook importa otros playbooks que contienen solo tasks. +- name: gestiones nginx + hosts: webserver + become: yes + tasks: + - import_task: nginx.yml + - import_task: nginx-handlers.yml + - import_task: uninstall-nginx.yml \ No newline at end of file diff --git a/training/uninstall-nginx.yml b/training/uninstall-nginx.yml index 42c39ec..31b1a45 100644 --- a/training/uninstall-nginx.yml +++ b/training/uninstall-nginx.yml @@ -9,5 +9,4 @@ - name: Desinstalar Paquete Nginx # Desinstalar el paquete Nginx usando apt apt: - name: nginx # Nombre del paquete a desinstalar - state: absent # Asegurarse de que el paquete esté ausente \ No newline at end of file + name: nginx # Nombre del paquete a desinstalar \ No newline at end of file diff --git a/training/when.yml b/training/when.yml new file mode 100644 index 0000000..ad6ea06 --- /dev/null +++ b/training/when.yml @@ -0,0 +1,21 @@ +- name: Instala Nginx cuando la maquina tenga la ip 192.168.11.40 + hosts: all + become: yes + tasks: + - name: Obtener la dirección IP de la interfaz eth1 + command: ip addr show eth1 + register: ip_output + + - name: Extraer la dirección IP de la salida del comando + set_fact: + ip_address: "{{ ip_output.stdout | regex_search('inet (\\d+\\.\\d+\\.\\d+\\.\\d+)', '\\1') }}" + + - name: Imprimir la dirección IP obtenida + debug: + msg: "La dirección IP de eth1 es {{ ip_address }}" + + - name: Instalar Nginx si la IP es 192.168.11.40 + apt: + name: nginx + state: present + when: ip_address == ['192.168.11.40'] \ No newline at end of file