playbook
unknown
plain_text
2 years ago
7.8 kB
7
Indexable
/home/control/ |_main_call.yml |_hosts.txt |_roles/ CAMBIAR HTTPD.CONF Y ESTILO CSS SI POSIBLE |_apache-serv/ |_handlers/ | |_main.yml |_templates/ | |_index.php | |_mostrar.php | |_con_dn.php | |_estilo.css | |_httpd.conf |_tasks/ | |_main.yml |_vars/ |_main.yml |_mysql-serv/ |_handlers/ | |_main.yml |_files/ | |_test_db.sql |_tasks/ | |_main.yml |_vars/ |_main.yml ---------------------------------------------------- ### hosts.txt [mysql] server-1 ansible_host=192.168.56.21 server-2 ansible_host=192.168.56.22 --------------------------------------------------------- ### main_call.yml --- - hosts: mysql name: Installation of mysql servers become: yes roles: - mysql-serv - apache-serv ---------------------------------------------------------- ### roles/apache-serv/vars/main.yml --- # vars file for apache-serv http_port: 8080 admin: ansible-devops content_dir: /webcontent apache_packages: - apache2 - libapache2-mod-wsgi - php - php-mysql ------------------------------------------------------------ ### roles/apache-serv/tasks/main.yml --- --- # tasks file for apache-serv - name: install apache2 and packages apt: name: "{{ item }}" state: present with_items: "{{ apache_packages }}" - name: sites-enabled directory file: name: /etc/httpd/conf/sites-enabled state: directory - name: copy httpd.conf template: src: ../templates/httpd.conf dest: /etc/httpd/conf/httpd.conf - name: copy index.php template: src: ../templates/index.php dest: /var/www/html/index.php - name: copy estilo.css template: src: ../templates/estilo.css dest: /var/www/html/estilo.css - name: copy mostrar.php template: src: ../templates/mostrar.php dest: /var/www/html/mostrar.php - name: copy con_db.php template: src: ../templates/con_db.php dest: /var/www/html/con_db.php notify: restart apache - name: start apache service: name: apache2 state: started enabled: yes ----------------------------------------------------- ### roles/apache-serv/handlers/main.yml --- # handlers file for apache-serv - name: restart apache service: name: apache2 state: restarted enabled: yes --------------------------------------------------------- ### roles/mysql-serv/templates/index.php <!DOCTYPE html> <html> <head> <title> Trabajo hecho por</title> <meta charset="utf-8"> <link rel="stylesheet" type="text/css" href="estilo.css"> </head> <body> <?php include("mostrar.php"); ?> </body> </html> ----------------------------------------------------------- ### roles/mysql-serv/templates/mostrar.php <?php $inc = include("con_db.php"); if ($inc) { $consulta = "SELECT * FROM grupo"; $resultado = mysqli_query($conex,$consulta); if ($resultado) { while ($row = $resultado->fetch_array()) { $alumid = $row['AlumnoID']; $nombre = $row['Nombre']; $uvus = $row['Uvus'] ?> <div> <tr> <td><?php echo $alumid; ?></td> <td><?php echo $nombre; ?></td> <td><?php echo $uvus; ?></td> </tr> </div> <?php } } } ?> ----------------------------------------------------------- ###roles/mysql-serv/templates/con_db.php <?php $conex = mysqli_connect("localhost","cimsi_user","sudo","mysqlDB"); ?> ----------------------------------------------------------- ###roles/mysql-serv/templates/estilo.css * { padding: 0; margin: 0; font-family: century gothic; color: #444 } h1 { padding: 12px; } div { padding: 10px 20px; } ----------------------------------------------------------- ###roles/mysql-serv/templates/httpd.conf # This is the main Apache HTTP server configuration file # # {{ ansible_managed }} ServerRoot "/etc/httpd" Listen {{ http_port }} Include conf.modules.d/*.conf User apache Group apache ServerAdmin {{ admin }}@{{ ansible_hostname }} <Directory /> AllowOverride none Require all denied </Directory> DocumentRoot "{{ content_dir }}" <Directory "{{ content_dir }}"> AllowOverride none # Allow open access: Require all granted </Directory> <Directory "{{ content_dir }}"> Options Indexes FollowSymLinks AllowOverride none Require all granted </Directory> <IfModule dir_module> DirectoryIndex index.html </IfModule> <Files ".ht"> Require all denied </Files> ErrorLog "logs/error_log" LogLevel warn <IfModule log_config_module> LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined LogFormat "%h %l %u %t \"%r\" %>s %b" common <IfModule logio_module> LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio </IfModule> CustomLog "logs/access_log" combined </IfModule> <IfModule /> ScriptAlias /cgi-bin/"/var/www/cgi-bin" </IfModule> <Directory "/var/www/cgi-bin"> AllowOverride none Options none Require all granted </Directory> <IfModule mime_module> TypesConfig /etc/mime.types AddType application/x-compress .Z AddType application/x-gzip .gz .tgz AddType text/html .shtml AddOutputFilter INCLUDES .shtml </IfModule> AddDefaultCharset UTF-8 <IfModule mime_magic_module> MIMEMagicFile conf/magic </IfModule> EnableSendFile on IncludeOptional conf.d/*.conf ---------------------------------------------------------- ### roles/mysql-serv/vars/main.yml --- # vars file for mysql-serv mysql_apt: - mysql-server - python3-mysqldb - libmysqlclient-dev - python-dev - python3-dev - python-pip mysql_pip: - MySQL-python mysql_user: cimsi_user mysql_passwd: sudo db_name: mysqlDB ------------------------------------------------------------ ### roles/mysql-serv/tasks/main.yml --- --- # tasks file for mysql-serv - name: Installing mySQL packages with apt apt: name: "{{ mysql_apt }}" state: present update_cache: yes - name: Installing mySQL packages with pip pip: name: "{{ mysql_pip }}" state: present - name: Start mySQL service service: name: mysql state: started enabled: yes - name: Create mySQL user mysql_user: name: "{{ mysql_user }}" password: "{{ mysql_passwd }}" priv: '*.*:ALL' host: '%' state: present - name: Create test database mysql_db: name: "{{ db_name }}" state: present - name: Add data to test database copy: src=../files/test_db.sql dest=/tmp/test_db.sql - name: Insert data into test database mysql_db: name="{{ db_name }}" state=import target=/tmp/test_db.sql login_user="{{ mysql_user }}" login_password="{{ mysql_passwd }}" notify: restart mySQL ----------------------------------------------------- ### roles/mysql-serv/handlers/main.yml --- # handlers file for mysql-serv - name: restart mySQL service: name: mysql state: restarted enabled: yes ----------------------------------------------------- ### roles/mysql-serv/files/test_db.sql --- DROP TABLE IF EXISTS grupo CREATE TABLE IF NOT EXISTS grupo ( AlumnoID int AUTO_INCREMENT, Nombre varchar(255) NOT NULL, Uvus varchar(20) NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=utf8; INSERT INTO grupo(Nombre, Uvus) VALUES('Álvaro Gómez Campos', 'alvgomcam'); INSERT INTO grupo(Nombre, Uvus) VALUES('Ignacio Hergueta Guerra', 'ignhergue'); INSERT INTO grupo(Nombre, Uvus) VALUES('Jorge Sánchez Hernández', 'jorsanher'); INSERT INTO grupo(Nombre, Uvus) VALUES('Juan Ramón Sánchez Arroyo', 'juasanarr'); INSERT INTO grupo(Nombre, Uvus) VALUES('Jose Manuel Mesonero Vega', 'josmesveg'); INSERT INTO grupo(Nombre, Uvus) VALUES('Miguel Muñoz Barrios', 'migmunbar');
Editor is loading...
Leave a Comment