diff --git a/training/practica-3-jinja2/apache2/README.md b/training/practica-3-jinja2/apache2/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/training/practica-3-jinja2/apache2/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/training/practica-3-jinja2/apache2/defaults/main.yml b/training/practica-3-jinja2/apache2/defaults/main.yml new file mode 100644 index 0000000..b292d8c --- /dev/null +++ b/training/practica-3-jinja2/apache2/defaults/main.yml @@ -0,0 +1,3 @@ +#SPDX-License-Identifier: MIT-0 +--- +# defaults file for apache2 diff --git a/training/practica-3-jinja2/apache2/files/hosts.conf b/training/practica-3-jinja2/apache2/files/hosts.conf new file mode 100644 index 0000000..77e8ded --- /dev/null +++ b/training/practica-3-jinja2/apache2/files/hosts.conf @@ -0,0 +1,16 @@ + + ServerAdmin webmaster@exemple.com + ServerName exemple.com + ServerAlias www.exemple.com + + DocumentRoot /var/www/exemple.com/public_html + + ErrorLog ${APACHE_LOG_DIR}/exemple.com_error.log + CustomLog ${APACHE_LOG_DIR}/exemple.com_access.log combined + + + Options Indexes FollowSymLinks + AllowOverride All + Require all granted + + \ No newline at end of file diff --git a/training/practica-3-jinja2/apache2/handlers/main.yml b/training/practica-3-jinja2/apache2/handlers/main.yml new file mode 100644 index 0000000..8b9a530 --- /dev/null +++ b/training/practica-3-jinja2/apache2/handlers/main.yml @@ -0,0 +1,10 @@ +#SPDX-License-Identifier: MIT-0 +--- +# handlers file for apache2 +#Notifica a la tarea de reinicio de Apache2 si este archivo cambia +- name: Reiniciar Apache2 + ansible.builtin.service: + name: apache2 #Nombre del servicio a reiniciar + state: restarted #Reinicia el servicio + when: ansible_facts.services['apache2.service'].state == 'running' #Solo si el servicio está corriendo + #when: ansible_facts.services['apache2'].state == 'running' #Condición para versiones antiguas \ No newline at end of file diff --git a/training/practica-3-jinja2/apache2/meta/main.yml b/training/practica-3-jinja2/apache2/meta/main.yml new file mode 100644 index 0000000..36b9858 --- /dev/null +++ b/training/practica-3-jinja2/apache2/meta/main.yml @@ -0,0 +1,35 @@ +#SPDX-License-Identifier: MIT-0 +galaxy_info: + author: your name + description: your role description + company: your company (optional) + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Choose a valid license ID from https://spdx.org - some suggested licenses: + # - BSD-3-Clause (default) + # - MIT + # - GPL-2.0-or-later + # - GPL-3.0-only + # - Apache-2.0 + # - CC-BY-4.0 + license: license (GPL-2.0-or-later, MIT, etc) + + min_ansible_version: 2.1 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. diff --git a/training/practica-3-jinja2/apache2/tasks/main.yml b/training/practica-3-jinja2/apache2/tasks/main.yml new file mode 100644 index 0000000..8d607a3 --- /dev/null +++ b/training/practica-3-jinja2/apache2/tasks/main.yml @@ -0,0 +1,32 @@ +#SPDX-License-Identifier: MIT-0 +--- +# tasks file for apache2 +#Instalar un servidor web (Apache2). +- name: Instalación de Apache2 + ansible.builtin.package: + name: "{{ item }}" #Nombre del paquete a instalar + state: present #Asegura que el paquete esté instalado + with_items: #Itera sobre una lista de paquetes + - apache2 #Servidor web Apache + - apache2-utils #Utilidades de Apache + - libapache2-mod-php #Módulo de PHP para Apache + - apache2-suexec-custom #Módulo de Apache para ejecutar scripts con permisos de usuario personalizado + - apache2-suexec-pristine #Módulo de Apache para ejecutar scripts con permisos de usuario prístino + +#Asegurar de que el servicio de Apache2 està corriendo y habilitado. +- name: Asegurar que Apache2 está corriendo + ansible.builtin.service: + name: apache2 #Nombre del servicio a gestionar + state: started #Asegura que el servicio esté en ejecución + enabled: yes #Habilita el servicio para que se inicie al arrancar el sistema + +#Copia el archivo de configuración hosts de Apache2 al directorio correspondiente +- name: Copiar archivo de configuración de hosts de Apache2 + ansible.builtin.copy: + src: ../files/hosts.conf #Ruta al archivo de configuración local + dest: /etc/apache2/sites-available/000-default.conf #Ruta de destino en el servidor + owner: www-data #Propietario del archivo + group: www-data #Grupo del archivo + mode: '0644' #Permisos del archivo + notify: + - Reiniciar Apache2 #Notifica a la tarea de reinicio de Apache2 si este archivo cambia \ No newline at end of file diff --git a/training/practica-3-jinja2/apache2/tests/inventory b/training/practica-3-jinja2/apache2/tests/inventory new file mode 100644 index 0000000..03ca42f --- /dev/null +++ b/training/practica-3-jinja2/apache2/tests/inventory @@ -0,0 +1,3 @@ +#SPDX-License-Identifier: MIT-0 +localhost + diff --git a/training/practica-3-jinja2/apache2/tests/test.yml b/training/practica-3-jinja2/apache2/tests/test.yml new file mode 100644 index 0000000..2918a18 --- /dev/null +++ b/training/practica-3-jinja2/apache2/tests/test.yml @@ -0,0 +1,6 @@ +#SPDX-License-Identifier: MIT-0 +--- +- hosts: localhost + remote_user: root + roles: + - apache2 diff --git a/training/practica-3-jinja2/apache2/vars/main.yml b/training/practica-3-jinja2/apache2/vars/main.yml new file mode 100644 index 0000000..b79cb1f --- /dev/null +++ b/training/practica-3-jinja2/apache2/vars/main.yml @@ -0,0 +1,3 @@ +#SPDX-License-Identifier: MIT-0 +--- +# vars file for apache2 diff --git a/training/practica-3-jinja2/inventory b/training/practica-3-jinja2/inventory new file mode 100644 index 0000000..b876044 --- /dev/null +++ b/training/practica-3-jinja2/inventory @@ -0,0 +1,8 @@ +[database] +192.168.11.20 + +[loadbalancer] +192.168.11.30 + +[webserver] +192.168.11.40 diff --git a/training/practica-3-jinja2/main.yml b/training/practica-3-jinja2/main.yml new file mode 100644 index 0000000..8e287e8 --- /dev/null +++ b/training/practica-3-jinja2/main.yml @@ -0,0 +1,14 @@ +- become: yes + hosts: webserver + roles: + - role: apache2 + - role: php + + hosts: database + roles: + - role: mariadb + + hosts: loadbalancer + roles: + - role: nginx + - role: users \ No newline at end of file diff --git a/training/practica-3-jinja2/mariadb/README.md b/training/practica-3-jinja2/mariadb/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/training/practica-3-jinja2/mariadb/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/training/practica-3-jinja2/mariadb/defaults/main.yml b/training/practica-3-jinja2/mariadb/defaults/main.yml new file mode 100644 index 0000000..00ae815 --- /dev/null +++ b/training/practica-3-jinja2/mariadb/defaults/main.yml @@ -0,0 +1,3 @@ +#SPDX-License-Identifier: MIT-0 +--- +# defaults file for mariadb diff --git a/training/practica-3-jinja2/mariadb/handlers/main.yml b/training/practica-3-jinja2/mariadb/handlers/main.yml new file mode 100644 index 0000000..d4c5ca4 --- /dev/null +++ b/training/practica-3-jinja2/mariadb/handlers/main.yml @@ -0,0 +1,3 @@ +#SPDX-License-Identifier: MIT-0 +--- +# handlers file for mariadb diff --git a/training/practica-3-jinja2/mariadb/meta/main.yml b/training/practica-3-jinja2/mariadb/meta/main.yml new file mode 100644 index 0000000..36b9858 --- /dev/null +++ b/training/practica-3-jinja2/mariadb/meta/main.yml @@ -0,0 +1,35 @@ +#SPDX-License-Identifier: MIT-0 +galaxy_info: + author: your name + description: your role description + company: your company (optional) + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Choose a valid license ID from https://spdx.org - some suggested licenses: + # - BSD-3-Clause (default) + # - MIT + # - GPL-2.0-or-later + # - GPL-3.0-only + # - Apache-2.0 + # - CC-BY-4.0 + license: license (GPL-2.0-or-later, MIT, etc) + + min_ansible_version: 2.1 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. diff --git a/training/practica-3-jinja2/mariadb/tasks/main.yml b/training/practica-3-jinja2/mariadb/tasks/main.yml new file mode 100644 index 0000000..1b8c1f8 --- /dev/null +++ b/training/practica-3-jinja2/mariadb/tasks/main.yml @@ -0,0 +1,11 @@ +#SPDX-License-Identifier: MIT-0 +--- +# tasks file for mariadb +#Instalar un servidor web (Apache2). +- name: Instalación de MariaDB + ansible.builtin.package: + name: "{{ item }}" #Nombre del paquete a instalar + state: present #Asegura que el paquete esté instalado + with_items: #Itera sobre una lista de paquetes + - mariadb-client #Cliente de base de datos MariaDB + - mariadb-server #Servidor de base de datos MariaDB \ No newline at end of file diff --git a/training/practica-3-jinja2/mariadb/tests/inventory b/training/practica-3-jinja2/mariadb/tests/inventory new file mode 100644 index 0000000..03ca42f --- /dev/null +++ b/training/practica-3-jinja2/mariadb/tests/inventory @@ -0,0 +1,3 @@ +#SPDX-License-Identifier: MIT-0 +localhost + diff --git a/training/practica-3-jinja2/mariadb/tests/test.yml b/training/practica-3-jinja2/mariadb/tests/test.yml new file mode 100644 index 0000000..8b214cd --- /dev/null +++ b/training/practica-3-jinja2/mariadb/tests/test.yml @@ -0,0 +1,6 @@ +#SPDX-License-Identifier: MIT-0 +--- +- hosts: localhost + remote_user: root + roles: + - mariadb diff --git a/training/practica-3-jinja2/mariadb/vars/main.yml b/training/practica-3-jinja2/mariadb/vars/main.yml new file mode 100644 index 0000000..f4ec27d --- /dev/null +++ b/training/practica-3-jinja2/mariadb/vars/main.yml @@ -0,0 +1,3 @@ +#SPDX-License-Identifier: MIT-0 +--- +# vars file for mariadb diff --git a/training/practica-3-jinja2/nginx/README.md b/training/practica-3-jinja2/nginx/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/training/practica-3-jinja2/nginx/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/training/practica-3-jinja2/nginx/defaults/main.yml b/training/practica-3-jinja2/nginx/defaults/main.yml new file mode 100644 index 0000000..940142c --- /dev/null +++ b/training/practica-3-jinja2/nginx/defaults/main.yml @@ -0,0 +1,3 @@ +#SPDX-License-Identifier: MIT-0 +--- +# defaults file for nginx diff --git a/training/practica-3-jinja2/nginx/files/nginx.conf b/training/practica-3-jinja2/nginx/files/nginx.conf new file mode 100644 index 0000000..a41ce98 --- /dev/null +++ b/training/practica-3-jinja2/nginx/files/nginx.conf @@ -0,0 +1,56 @@ +# Archivo de configuración nginx.conf + +user www-data; +worker_processes auto; +pid /run/nginx.pid; +include /etc/nginx/modules-enabled/*.conf; + +events { + worker_connections 768; + # multi_accept on; +} + +http { + + ## + # Configuración básica + ## + + sendfile on; + tcp_nopush on; + tcp_nodelay on; + keepalive_timeout 65; + types_hash_max_size 2048; + + include /etc/nginx/mime.types; + default_type application/octet-stream; + + ## + # Configuración de logs + ## + + access_log /var/log/nginx/access.log; + error_log /var/log/nginx/error.log; + + ## + # Gzip settings + ## + + gzip on; + gzip_disable "msie6"; + + # Configuración de virtual host + server { + listen 80 default_server; + listen [::]:80 default_server; + + root /var/www/html; + index index.html index.htm index.nginx-debian.html; + + server_name _; + + location / { + try_files $uri $uri/ =404; + } + } +} \ No newline at end of file diff --git a/training/practica-3-jinja2/nginx/handlers/main.yml b/training/practica-3-jinja2/nginx/handlers/main.yml new file mode 100644 index 0000000..eeede3c --- /dev/null +++ b/training/practica-3-jinja2/nginx/handlers/main.yml @@ -0,0 +1,9 @@ +#SPDX-License-Identifier: MIT-0 +--- +# handlers file for nginx +- name: Reiniciar Nginx + ansible.builtin.service: + name: nginx #Nombre del servicio a reiniciar + state: restarted #Reinicia el servicio + when: ansible_facts.services['nginx.service'].state == 'running' #Solo si el servicio está corriendo + #when: ansible_facts.services['nginx'].state == 'running' #Condición para versiones antiguas \ No newline at end of file diff --git a/training/practica-3-jinja2/nginx/meta/main.yml b/training/practica-3-jinja2/nginx/meta/main.yml new file mode 100644 index 0000000..36b9858 --- /dev/null +++ b/training/practica-3-jinja2/nginx/meta/main.yml @@ -0,0 +1,35 @@ +#SPDX-License-Identifier: MIT-0 +galaxy_info: + author: your name + description: your role description + company: your company (optional) + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Choose a valid license ID from https://spdx.org - some suggested licenses: + # - BSD-3-Clause (default) + # - MIT + # - GPL-2.0-or-later + # - GPL-3.0-only + # - Apache-2.0 + # - CC-BY-4.0 + license: license (GPL-2.0-or-later, MIT, etc) + + min_ansible_version: 2.1 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. diff --git a/training/practica-3-jinja2/nginx/tasks/main.yml b/training/practica-3-jinja2/nginx/tasks/main.yml new file mode 100644 index 0000000..ef46a19 --- /dev/null +++ b/training/practica-3-jinja2/nginx/tasks/main.yml @@ -0,0 +1,46 @@ +#SPDX-License-Identifier: MIT-0 +--- +# tasks file for nginx +# Asegurar que Apache2 está detenido antes de instalar Nginx +- name: Asegurar que Apache2 está detenido + ansible.builtin.service: + name: apache2 #Nombre del servicio a gestionar + state: stopped #Asegura que el servicio esté detenido + +#Instalar un servidor web (Nginx). +- name: Instalación de Nginx + ansible.builtin.package: + name: "{{ item }}" #Nombre del paquete a instalar + state: present #Asegura que el paquete esté instalado + with_items: #Itera sobre una lista de paquetes + - nginx #Servidor web Nginx + - nginx-extras #Paquete adicional de Nginx con características extra + +#Asegurar de que el servicio de Nginx està corriendo y habilitado. +- name: Asegurar que Nginx está corriendo + ansible.builtin.service: + name: nginx #Nombre del servicio a gestionar + state: started #Asegura que el servicio esté en ejecución + enabled: yes #Habilita el servicio para que se inicie al arrancar el sistema + +#Copia el archivo de configuración hosts de Nginx al directorio correspondiente +- name: Copiar archivo de configuración de hosts de Nginx + ansible.builtin.copy: + src: ../files/nginx.conf #Ruta al archivo de configuración local + dest: /etc/nginx/sites-available/default #Ruta de destino en el servidor + owner: www-data #Propietario del archivo + group: www-data #Grupo del archivo + mode: '0644' #Permisos del archivo + notify: + - Reiniciar Nginx #Notifica a la tarea de reinicio de Nginx si este archivo cambia + +#Vamos a parar Nginx si está corriendo +- name: Comprueba el estado de Nginx + ansible.builtin.service_facts: #Recopila información sobre los servicios +- name: Detener Nginx si está activo + ansible.builtin.service: + name: nginx + state: stopped + when: ansible_facts.services['nginx.service'].state == 'running' + #Condición para versiones antiguas para detener Nginx solo si está corriendo + #when: ansible_facts.services['nginx'].state == 'running' diff --git a/training/practica-3-jinja2/nginx/tests/inventory b/training/practica-3-jinja2/nginx/tests/inventory new file mode 100644 index 0000000..03ca42f --- /dev/null +++ b/training/practica-3-jinja2/nginx/tests/inventory @@ -0,0 +1,3 @@ +#SPDX-License-Identifier: MIT-0 +localhost + diff --git a/training/practica-3-jinja2/nginx/tests/test.yml b/training/practica-3-jinja2/nginx/tests/test.yml new file mode 100644 index 0000000..410fda6 --- /dev/null +++ b/training/practica-3-jinja2/nginx/tests/test.yml @@ -0,0 +1,6 @@ +#SPDX-License-Identifier: MIT-0 +--- +- hosts: localhost + remote_user: root + roles: + - nginx diff --git a/training/practica-3-jinja2/nginx/vars/main.yml b/training/practica-3-jinja2/nginx/vars/main.yml new file mode 100644 index 0000000..78c85e6 --- /dev/null +++ b/training/practica-3-jinja2/nginx/vars/main.yml @@ -0,0 +1,3 @@ +#SPDX-License-Identifier: MIT-0 +--- +# vars file for nginx diff --git a/training/practica-3-jinja2/php/README.md b/training/practica-3-jinja2/php/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/training/practica-3-jinja2/php/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/training/practica-3-jinja2/php/defaults/main.yml b/training/practica-3-jinja2/php/defaults/main.yml new file mode 100644 index 0000000..b0d5c70 --- /dev/null +++ b/training/practica-3-jinja2/php/defaults/main.yml @@ -0,0 +1,3 @@ +#SPDX-License-Identifier: MIT-0 +--- +# defaults file for php diff --git a/training/practica-3-jinja2/php/handlers/main.yml b/training/practica-3-jinja2/php/handlers/main.yml new file mode 100644 index 0000000..3587f40 --- /dev/null +++ b/training/practica-3-jinja2/php/handlers/main.yml @@ -0,0 +1,3 @@ +#SPDX-License-Identifier: MIT-0 +--- +# handlers file for php diff --git a/training/practica-3-jinja2/php/meta/main.yml b/training/practica-3-jinja2/php/meta/main.yml new file mode 100644 index 0000000..36b9858 --- /dev/null +++ b/training/practica-3-jinja2/php/meta/main.yml @@ -0,0 +1,35 @@ +#SPDX-License-Identifier: MIT-0 +galaxy_info: + author: your name + description: your role description + company: your company (optional) + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Choose a valid license ID from https://spdx.org - some suggested licenses: + # - BSD-3-Clause (default) + # - MIT + # - GPL-2.0-or-later + # - GPL-3.0-only + # - Apache-2.0 + # - CC-BY-4.0 + license: license (GPL-2.0-or-later, MIT, etc) + + min_ansible_version: 2.1 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. diff --git a/training/practica-3-jinja2/php/tasks/main.yml b/training/practica-3-jinja2/php/tasks/main.yml new file mode 100644 index 0000000..2b9ea08 --- /dev/null +++ b/training/practica-3-jinja2/php/tasks/main.yml @@ -0,0 +1,31 @@ +#SPDX-License-Identifier: MIT-0 +--- +# tasks file for php +#Instalar PHP +- name: Instalación de PHP + ansible.builtin.package: + name: "{{ item }}" #Nombre del paquete a instalar + state: present #Asegura que el paquete esté instalado + with_items: #Itera sobre una lista de paquetes + - php #Paquete PHP + - php-curl #Extensión PHP para cURL + - php-gd #Extensión PHP para gráficos y manipulación de imágenes + - php-mbstring #Extensión PHP para manejo de cadenas multibyte + - php-memcached #Extensión PHP para Memcached + - php-mysql #Extensión PHP para MySQL + - php-tcpdf #Extensión PHP para TCPDF + - php-xml #Extensión PHP para XML + - php-zip #Extensión PHP para manejo de archivos ZIP + notify: + - Reiniciar Apache2 #Notifica a la tarea de reinicio de Apache2 + +#Ver si PHP está instalado correctamente +- name: Verificar la instalación de PHP + ansible.builtin.command: php -v + register: php_version_output + changed_when: false + +# Mostrar la versión de PHP instalada +- name: Mostrar la versión de PHP instalada + ansible.builtin.debug: + msg: "Versión de PHP instalada: {{ php_version_output.stdout }}" \ No newline at end of file diff --git a/training/practica-3-jinja2/php/tests/inventory b/training/practica-3-jinja2/php/tests/inventory new file mode 100644 index 0000000..03ca42f --- /dev/null +++ b/training/practica-3-jinja2/php/tests/inventory @@ -0,0 +1,3 @@ +#SPDX-License-Identifier: MIT-0 +localhost + diff --git a/training/practica-3-jinja2/php/tests/test.yml b/training/practica-3-jinja2/php/tests/test.yml new file mode 100644 index 0000000..e435275 --- /dev/null +++ b/training/practica-3-jinja2/php/tests/test.yml @@ -0,0 +1,6 @@ +#SPDX-License-Identifier: MIT-0 +--- +- hosts: localhost + remote_user: root + roles: + - php diff --git a/training/practica-3-jinja2/php/vars/main.yml b/training/practica-3-jinja2/php/vars/main.yml new file mode 100644 index 0000000..77cf9d4 --- /dev/null +++ b/training/practica-3-jinja2/php/vars/main.yml @@ -0,0 +1,3 @@ +#SPDX-License-Identifier: MIT-0 +--- +# vars file for php diff --git a/training/practica-3-jinja2/users/README.md b/training/practica-3-jinja2/users/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/training/practica-3-jinja2/users/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/training/practica-3-jinja2/users/defaults/main.yml b/training/practica-3-jinja2/users/defaults/main.yml new file mode 100644 index 0000000..5a499b8 --- /dev/null +++ b/training/practica-3-jinja2/users/defaults/main.yml @@ -0,0 +1,3 @@ +#SPDX-License-Identifier: MIT-0 +--- +# defaults file for users diff --git a/training/practica-3-jinja2/users/handlers/main.yml b/training/practica-3-jinja2/users/handlers/main.yml new file mode 100644 index 0000000..1720077 --- /dev/null +++ b/training/practica-3-jinja2/users/handlers/main.yml @@ -0,0 +1,3 @@ +#SPDX-License-Identifier: MIT-0 +--- +# handlers file for users diff --git a/training/practica-3-jinja2/users/meta/main.yml b/training/practica-3-jinja2/users/meta/main.yml new file mode 100644 index 0000000..36b9858 --- /dev/null +++ b/training/practica-3-jinja2/users/meta/main.yml @@ -0,0 +1,35 @@ +#SPDX-License-Identifier: MIT-0 +galaxy_info: + author: your name + description: your role description + company: your company (optional) + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Choose a valid license ID from https://spdx.org - some suggested licenses: + # - BSD-3-Clause (default) + # - MIT + # - GPL-2.0-or-later + # - GPL-3.0-only + # - Apache-2.0 + # - CC-BY-4.0 + license: license (GPL-2.0-or-later, MIT, etc) + + min_ansible_version: 2.1 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. diff --git a/training/practica-3-jinja2/users/tasks/main.yml b/training/practica-3-jinja2/users/tasks/main.yml new file mode 100644 index 0000000..07882bd --- /dev/null +++ b/training/practica-3-jinja2/users/tasks/main.yml @@ -0,0 +1,13 @@ +#SPDX-License-Identifier: MIT-0 +--- +# tasks file for users +- name: Generar hash de la contraseña en el controlador (local) + ansible.builtin.set_fact: + hashed_password: "{{ user_password | password_hash('sha512') }}" + +- name: Crear usuarios con contraseña + ansible.builtin.user: + name: "{{ item }}" + password: "{{ hashed_password }}" + state: present + loop: "{{ user_list }}" \ No newline at end of file diff --git a/training/practica-3-jinja2/users/tests/inventory b/training/practica-3-jinja2/users/tests/inventory new file mode 100644 index 0000000..03ca42f --- /dev/null +++ b/training/practica-3-jinja2/users/tests/inventory @@ -0,0 +1,3 @@ +#SPDX-License-Identifier: MIT-0 +localhost + diff --git a/training/practica-3-jinja2/users/tests/test.yml b/training/practica-3-jinja2/users/tests/test.yml new file mode 100644 index 0000000..4e234a5 --- /dev/null +++ b/training/practica-3-jinja2/users/tests/test.yml @@ -0,0 +1,6 @@ +#SPDX-License-Identifier: MIT-0 +--- +- hosts: localhost + remote_user: root + roles: + - users diff --git a/training/practica-3-jinja2/users/vars/main.yml b/training/practica-3-jinja2/users/vars/main.yml new file mode 100644 index 0000000..aeb4b55 --- /dev/null +++ b/training/practica-3-jinja2/users/vars/main.yml @@ -0,0 +1,8 @@ +#SPDX-License-Identifier: MIT-0 +--- +# vars file for users +user_list: + - user1 + - user2 + - user3 +user_password: "password" # Contraseña en texto plano \ No newline at end of file