You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In our last section, we started with creating our small lab using a Vagrantfile to deploy 4 machines and we used the Linux machine we created in that section as our ansible control system.
3
+
En nuestra última sección, comenzamos creando nuestro pequeño laboratorio utilizando un archivo Vagrantfile para implementar 4 máquinas, y utilizamos la máquina Linux que creamos en esa sección como nuestro sistema de control de Ansible.
4
4
5
-
We also ran through a few scenarios of playbooks and at the end we had a playbook that made our web01 and web02 individual web servers.
5
+
También ejecutamos algunos escenarios de playbooks y al final teníamos un playbook que convertía nuestros servidores web individuales web01 y web02.
6
6
7
7

8
8
9
-
### Keeping things tidy
9
+
### Manteniendo las cosas ordenadas
10
10
11
-
Before we get into further automation and deployment we should cover the ability to keep our playbook lean and tidy and how we can separate our tasks and handlers into subfolders.
11
+
Antes de adentrarnos en la automatización y el despliegue, debemos cubrir la capacidad de mantener nuestro playbook limpio y ordenado, y cómo podemos separar nuestras tareas y handlers en subcarpetas.
12
+
13
+
Vamos a copiar nuestras tareas en sus archivos dentro de una carpeta.
12
14
13
-
we are going to copy our tasks into their file within a folder.
14
15
15
16
```Yaml
16
17
- name: ensure apache is at the latest version
@@ -35,7 +36,7 @@ we are going to copy our tasks into their file within a folder.
35
36
state: started
36
37
```
37
38
38
-
and the same for the handlers.
39
+
Y lo mismo para los handlers
39
40
40
41
```Yaml
41
42
- name: restart apache
@@ -44,37 +45,37 @@ and the same for the handlers.
44
45
state: restarted
45
46
```
46
47
47
-
then within our playbook now named `playbook2.yml` we point to these files. All of which can be found at [ansible-scenario2](Days/../Configmgmt/ansible-scenario2/)
48
+
Luego, en nuestro playbook, que ahora se llama playbook2.yml, nos referimos a estos archivos. Todos ellos se pueden encontrar en [ansible-scenario2](Days/../Configmgmt/ansible-scenario2/)
48
49
49
-
You can test this on your control machine. If you have copied the files from the repository you should have noticed something changed in the "write a basic index.html file"
50
+
Puedes probar esto en tu máquina de control. Si has copiado los archivos del repositorio, deberías haber notado un cambio en "escribir un archivo "index.html" básico".
50
51
51
52

52
53
53
-
Let's find out what simple change I made. Using `curl web01:8000`
We have just tidied up our playbook and started to separate areas that could make a playbook very overwhelming at scale.
58
+
Acabamos de organizar nuestro playbook y comenzamos a separar áreas que podrían hacer que un playbook sea muy abrumador a gran escala.
58
59
59
-
### Roles and Ansible Galaxy
60
+
### Roles y Ansible Galaxy
60
61
61
-
At the moment we have deployed 4 VMs and we have configured 2 of these VMs as our webservers but we have some more specific functions namely, a database server and a loadbalancer or proxy. For us to do this and tidy up our repository, we can use roles within Ansible.
62
+
En este momento, hemos implementado 4 máquinas virtuales y hemos configurado 2 de ellas como nuestros servidores web, pero tenemos algunas funciones más específicas, como un servidor de base de datos y un equilibrador de carga o proxy. Para hacer esto y organizar nuestro repositorio, podemos usar roles en Ansible.
62
63
63
-
To do this we will use the `ansible-galaxy` command which is there to manage ansible roles in shared repositories.
64
+
Para hacer esto, utilizaremos el comando `ansible-galaxy`, que sirve para gestionar roles de Ansible en repositorios compartidos.
64
65
65
66

66
67
67
-
We are going to use `ansible-galaxy` to create a role for apache2 which is where we are going to put our specifics for our webservers.
68
+
Vamos a utilizar `ansible-galaxy` para crear un rol para Apache2, donde colocaremos nuestras especificaciones para nuestros servidores web.
68
69
69
70

70
71
71
-
The above command `ansible-galaxy init roles/apache2` will create the folder structure that we have shown above. Our next step is we need to move our existing tasks and templates to the relevant folders in the new structure.
72
+
El comando anterior `ansible-galaxy init roles/apache2` creará la estructura de carpetas que se muestra arriba. Nuestro siguiente paso es mover nuestras tareas y plantillas existentes a las carpetas relevantes en la nueva estructura.
72
73
73
74

74
75
75
-
Copy and paste are easy to move those files but we also need to make a change to the tasks/main.yml so that we point this to the apache2_install.yml.
76
+
Copiar y pegar es fácil para mover esos archivos, pero también necesitamos hacer un cambio en tasks/main.yml para que apunte a apache2_install.yml.
76
77
77
-
We also need to change our playbook now to refer to our new role. In the playbook1.yml and playbook2.yml we determine our tasks and handlers in different ways as we changed these between the two versions. We need to change our playbook to use this role as per below:
78
+
También necesitamos cambiar nuestro playbook para que haga referencia a nuestro nuevo rol. En playbook1.yml y playbook2.yml, determinamos nuestras tareas y handlers de diferentes maneras, ya que los cambiamos entre las dos versiones. Necesitamos cambiar nuestro playbook para usar este rol de la siguiente manera:
78
79
79
80
```Yaml
80
81
- hosts: webservers
@@ -89,32 +90,33 @@ We also need to change our playbook now to refer to our new role. In the playboo
89
90
90
91

91
92
92
-
We can now run our playbook again this time with the new playbook name `ansible-playbook playbook3.yml` you will notice the depreciation, we can fix that next.
93
+
Ahora podemos ejecutar nuestro playbook nuevamente, esta vez con el nuevo nombre de playbook `ansible-playbook playbook3.yml`. Notarás la advertencia de depreciación, podemos solucionarlo después.
93
94
94
95

95
96
96
-
Ok, the depreciation although our playbook ran we should fix our ways now, to do that I have changed the include option in the tasks/main.yml to now be import_tasks as per below.
97
+
Ok, a pesar de la advertencia de depreciación, nuestro playbook se ejecutó, pero ahora debemos corregir nuestros métodos. Para hacerlo, he cambiado la opción de inclusión (include) en tasks/main.yml para que ahora sea import_tasks, como se muestra a continuación.
97
98
98
99

99
100
100
-
You can find these files in the [ansible-scenario3](Days/Configmgmt/ansible-scenario3)
101
+
Puedes encontrar estos archivos en [ansible-scenario3](Days/Configmgmt/ansible-scenario3)
101
102
102
-
We are also going to create a few more roles whilst using `ansible-galaxy` we are going to create:
103
+
También vamos a crear algunos roles más mientras usamos ansible-galaxy, vamos a crear:
103
104
104
-
- common = for all of our servers (`ansible-galaxy init roles/common`)
105
-
- nginx = for our loadbalancer (`ansible-galaxy init roles/nginx`)
105
+
- common = para todos nuestros servidores (`ansible-galaxy init roles/common`)
106
+
- nginx = para nuestro equilibrador de carga (`ansible-galaxy init roles/nginx`)
106
107
107
108

108
109
109
-
I am going to leave this one here and in the next session, we will start working on those other nodes we have deployed but have not done anything with yet.
110
+
Voy a dejarlo aquí y en la próxima sesión, comenzaremos a trabajar en esos otros nodos que hemos implementado pero aún no hemos hecho nada con ellos.
110
111
111
-
## Resources
112
+
## Recursos
112
113
113
114
- [What is Ansible](https://www.youtube.com/watch?v=1id6ERvfozo)
114
115
- [Ansible 101 - Episode 1 - Introduction to Ansible](https://www.youtube.com/watch?v=goclfp6a2IQ)
115
116
- [NetworkChuck - You need to learn Ansible right now!](https://www.youtube.com/watch?v=5hycyr-8EKs&t=955s)
116
117
- [Your complete guide to Ansible](https://www.youtube.com/playlist?list=PLnFWJCugpwfzTlIJ-JtuATD2MBBD7_m3u)
118
+
- [Chef vs Puppet vs Ansible vs Saltstack](https://vergaracarmona.es/chef-vs-puppet-vs-ansible-vs-saltstack/)
117
119
118
-
This final playlist listed above is where a lot of the code and ideas came from for this section, a great resource and walkthrough in video format.
120
+
La última lista de reproducción mencionada anteriormente es de donde provienen gran parte del código e ideas de esta sección, es un recurso excelente con una guía en formato de video.
Copy file name to clipboardExpand all lines: 2022/es/Days/day67.md
+23-22Lines changed: 23 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,16 +1,16 @@
1
-
## Using Roles & Deploying a Loadbalancer
1
+
## Uso de Roles e Implementación de un Balanceador de Carga
2
2
3
-
In the last session, we covered roles and used the `ansible-galaxy`command to help create our folder structures for some roles that we are going to use. We finished up with a much tidier working repository for our configuration code as everything is hidden away in our role folders.
3
+
En la última sesión, cubrimos los roles y utilizamos el comando `ansible-galaxy`para crear las estructuras de carpetas para algunos roles que vamos a utilizar. Terminamos con un repositorio de trabajo mucho más ordenado para nuestro código de configuración, ya que todo está oculto en nuestras carpetas de roles.
4
4
5
-
However, we have only used the apache2 role and have a working playbook3.yaml to handle our webservers.
5
+
Sin embargo, solo hemos utilizado el rol apache2 y tenemos un playbook3.yaml funcional para manejar nuestros servidores web.
6
6
7
-
At this point if you have only used `vagrant up web01 web02` now is the time to run `vagrant up loadbalancer` this will bring up another Ubuntu system that we will use as our Load Balancer/Proxy.
7
+
En este momento, si solo has ejecutado `vagrant up web01 web02`, es hora de ejecutar `vagrant up loadbalancer`. Esto iniciará otro sistema Ubuntu que utilizaremos como nuestro balanceador de carga/proxy.
8
8
9
-
We have already defined this new machine in our host's file, but we do not have the ssh key configured until it is available, so we need to also run `ssh-copy-id loadbalancer`when the system is up and ready.
9
+
Ya hemos definido esta nueva máquina en nuestro archivo de hosts, pero no tenemos configurada la clave SSH hasta que esté disponible, así que también necesitamos ejecutar `ssh-copy-id loadbalancer`cuando el sistema esté listo.
10
10
11
-
### Common role
11
+
### Rol common
12
12
13
-
I created at the end of yesterday's session the role of `common`, common will be used across all of our servers whereas the other roles are specific to use cases, now the applications I am going to install are as common as spurious and I cannot see many reasons for this to be the case but it shows the objective. In our common role folder structure, navigate to the tasks folder and you will have a main.yml. In this YAML, we need to point this to our install_tools.yml file and we do this by adding a line `- import_tasks: install_tools.yml` this used to be `include` but this is going to be depreciated soon enough so we are using import_tasks.
13
+
Al final de la sesión de ayer, creé el rol common, que se utilizará en todos nuestros servidores, mientras que los otros roles son específicos para casos de uso. Ahora, las aplicaciones que voy a instalar son tan comunes como espurias y no veo muchas razones para que esto sea así, pero esto muestra el objetivo. En la estructura de carpetas del rol common, navega hasta la carpeta tasks y tendrás un archivo main.yml. En este archivo YAML, debemos apuntar a nuestro archivo install_tools.yml y lo hacemos agregando la línea `- import_tasks: install_tools.yml`. Anteriormente, esto se hacía con `include`, pero esto se depreciará lo suficiente pronto, por lo que estamos usando import_tasks.
14
14
15
15
```Yaml
16
16
- name: "Install Common packages"
@@ -21,7 +21,7 @@ I created at the end of yesterday's session the role of `common`, common will be
21
21
- figlet
22
22
```
23
23
24
-
In our playbook, we then add in the common role for each host block.
24
+
En nuestro playbook, luego agregamos el rol common para cada bloque de host.
25
25
26
26
```Yaml
27
27
- hosts: webservers
@@ -37,11 +37,11 @@ In our playbook, we then add in the common role for each host block.
37
37
38
38
### nginx
39
39
40
-
The next phase is for us to install and configure nginx on our loadbalancer VM. Like the common folder structure, we have the nginx based on the last session.
40
+
La siguiente fase es instalar y configurar nginx en nuestra máquina de balanceo de carga (loadbalancer). Al igual que la estructura de carpetas common, tenemos la carpeta nginx basada en la sesión anterior.
41
41
42
-
First of all, we are going to add a host block to our playbook. This block will include our common role and then our new nginx role.
42
+
Primero, vamos a agregar un bloque de host a nuestro playbook. Este bloque incluirá nuestro rol common y luego nuestro nuevo rol nginx.
43
43
44
-
The playbook can be found here. [playbook4.yml](Days/../Configmgmt/ansible-scenario4/playbook4.yml)
44
+
El playbook se puede encontrar aquí: [playbook4.yml](Days/../Configmgmt/ansible-scenario4/playbook4.yml)
45
45
46
46
```Yaml
47
47
- hosts: webservers
@@ -61,23 +61,23 @@ The playbook can be found here. [playbook4.yml](Days/../Configmgmt/ansible-scena
61
61
- nginx
62
62
```
63
63
64
-
For this to mean anything, we have to define the tasks that we wish to run, in the same way, we will modify the main.yml in tasks to point to two files this time, one for installation and one for configuration.
64
+
Para que esto signifique algo, debemos definir las tareas que deseamos ejecutar. De la misma manera, modificaremos el archivo main.yml en tasks para que apunte a dos archivos en esta ocasión, uno para la instalación y otro para la configuración.
65
65
66
-
There are some other files that I have modified based on the outcome we desire, take a look in the folder [ansible-scenario4](Days/Configmgmt/ansible-scenario4) for all the files changed. You should check the folders tasks, handlers and templates in the nginx folder and you will find those additional changes and files.
66
+
Hay algunos otros archivos que he modificado en función del resultado que deseamos. Echa un vistazo a la carpeta [ansible-scenario4](Days/Configmgmt/ansible-scenario4) para ver todos los archivos modificados. Debes revisar las carpetas tasks, handlers y templates en la carpeta nginx, y encontrarás esos cambios y archivos adicionales.
67
67
68
-
### Run the updated playbook
68
+
### Ejecutar el playbook actualizado
69
69
70
-
Since yesterday we have added the common role which will now install some packages on our system and then we have also added our nginx role which includes installation and configuration.
70
+
Desde ayer, hemos agregado el rol common, que ahora instalará algunos paquetes en nuestro sistema, y también hemos agregado nuestro rol nginx, que incluye la instalación y configuración.
71
71
72
-
Let's run our playbook4.yml using the`ansible-playbook playbook4.yml`
Now that we have our webservers and loadbalancer configured we should now be able to go to http://192.168.169.134/ which is the IP address of our loadbalancer.
76
+
Ahora que hemos configurado nuestros servidores web y nuestro balanceador de carga, deberíamos poder acceder a http://192.168.169.134/, que es la dirección IP de nuestro balanceador de carga.
77
77
78
78

79
79
80
-
If you are following along and you do not have this state then it could be down to the server IP addresses you have in your environment. The file can be found in `templates\mysite.j2` and looks similar to the below: You would need to update with your web server IP addresses.
80
+
Si estás siguiendo los pasos y no tienes este resultado, podría deberse a las direcciones IP de los servidores que tienes en tu entorno. El archivo se puede encontrar en `templates\mysite.j2` y se ve similar al siguiente: Debes actualizarlo con las direcciones IP de tus servidores web.
81
81
82
82
```J2
83
83
upstream webservers {
@@ -94,19 +94,20 @@ If you are following along and you do not have this state then it could be down
94
94
}
95
95
```
96
96
97
-
I am pretty confident that what we have installed is all good but let's use an ad-hoc command using ansible to check these common tools installation.
97
+
Estoy bastante seguro de que lo que hemos instalado está todo bien, pero vamos a usar un comando ad-hoc con ansible para verificar la instalación de estas herramientas comunes.
98
98
99
99
`ansible loadbalancer -m command -a neofetch`
100
100
101
101

102
102
103
-
## Resources
103
+
## Recursos
104
104
105
105
- [What is Ansible](https://www.youtube.com/watch?v=1id6ERvfozo)
106
106
- [Ansible 101 - Episode 1 - Introduction to Ansible](https://www.youtube.com/watch?v=goclfp6a2IQ)
107
107
- [NetworkChuck - You need to learn Ansible right now!](https://www.youtube.com/watch?v=5hycyr-8EKs&t=955s)
108
108
- [Your complete guide to Ansible](https://www.youtube.com/playlist?list=PLnFWJCugpwfzTlIJ-JtuATD2MBBD7_m3u)
109
+
- [Chef vs Puppet vs Ansible vs Saltstack](https://vergaracarmona.es/chef-vs-puppet-vs-ansible-vs-saltstack/)
109
110
110
-
This final playlist listed above is where a lot of the code and ideas came from for this section, a great resource and walkthrough in video format.
111
+
La lista de reproducción final mencionada anteriormente es de donde proviene gran parte del código y las ideas para esta sección, es un recurso excelente y una guía en formato de video.
0 commit comments