Merge branch 'agile611:main' into main
This commit is contained in:
15
training/handler-nginx.yml
Normal file
15
training/handler-nginx.yml
Normal file
@@ -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
|
||||
@@ -1,5 +1,5 @@
|
||||
- name: Prueba de handlers
|
||||
hosts: all
|
||||
hosts: webserver
|
||||
become: yes
|
||||
tasks:
|
||||
- name: Copiar archivo de configuración
|
||||
|
||||
5
training/import_playbooks.yml
Normal file
5
training/import_playbooks.yml
Normal file
@@ -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
|
||||
9
training/import_tasks.yml
Normal file
9
training/import_tasks.yml
Normal file
@@ -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
|
||||
@@ -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
|
||||
name: nginx # Nombre del paquete a desinstalar
|
||||
21
training/when.yml
Normal file
21
training/when.yml
Normal file
@@ -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']
|
||||
Reference in New Issue
Block a user