Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
3.3 kB
6
Indexable
Never
/pa el index:
https://html5up.net/dimension

mysql-simple
|_templates 
    |_index.php
    |_httpd.conf.j2 (lo hemos copiao de la practica de ansible)
|_db.yml (playbook)
|_ group_vars
    |_ all
----
/templates/index.php
<h1> calvo cabron </h1>
<?php
$servername = "192.168.56.21";
$username = "cimsi_user";
$password = "sudo";
$database = "mysqlDB";

// Crear conexión
$conn = new mysqli($servername, $username, $password, $database);
// Consulta SQL para obtener datos
$sql = "select @@hostname as "nombre del servidor"";
$result = $conn -> query($sql);


// Verificar conexión
if ($conn->connect_error) {
    die("Conexión fallida: " . $conn->connect_error);
}

// Consulta SQL para obtener datos
$sql = "SELECT * FROM test";
$result = $conn->query($sql);

// Mostrar datos en HTML
echo "<table border='1'>";
echo "<tr>CALVO CABRON</tr>";
while ($row = $result->fetch_assoc()) {
    echo "<tr><td>"  . $row["message"] . "</td></tr>";
}
echo "</table>";

// Cerrar conexión
$conn->close();
?>
-----

db.yml (distribuir en roles y cambiar nombres)
- name: setup Mysql with medium_db db and remote login
  become: yes
  hosts: mysql
  vars:
    http_port: 8080
    admin: ansible-devops
    content_dir: /webcontent
    httpd_packages:
      - apache2
      - libapache2-mod-wsgi
  tasks:
    - name: Installing Mysql  and dependencies
      apt:
       name: "{{item}}"
       state: present
       update_cache: yes
      loop:
       - mysql-server
       - python3-mysqldb
       - libmysqlclient-dev
       - python-dev
       - python3-dev
       - python-pip
      become: yes
    - name: Installing MySQL-python
      pip:
       name: MySQL-python
       state: present
      become: yes

    - name: start and enable mysql service
      service:
        name: mysql
        state: started
        enabled: yes   
    - name: creating mysql user (medium_post)
      mysql_user:
        name: "{{db_user}}"
        password: "{{db_pass}}"
        priv: '*.*:ALL'
        host: '%'
        state: present
    - name: creating mysqlDB
      mysql_db:
        name: "{{db_name}}"
        state: present
    - name: add data to mysqlDB
      copy: src=dump.sql dest=/tmp/dump.sql 
    - name: insert data to DB
      mysql_db: name="{{db_name}}" state=import target=/tmp/dump.sql login_user="{{db_user}}" login_password="{{ db_pass }}"
    - name: Restart mysql
      service:
        name: mysql
        state: restarted
# INSTALACION APACHE #

    - name: install apache2
      apt:
        name: "{{ item }}"
        state: present
      with_items: "{{ httpd_packages }}"
      notify: restart apache service
    - name: create site-enabled directory
      file:
        name: /etc/httpd/conf/sites-enabled
        state: directory
    - name: copy httpd.conf
      template:
        src: templates/httpd.conf.j2
        dest: /etc/httpd/conf/httpd.conf
      notify: restart apache service
    - name: copy index.html
      template:
        src: templates/index.html.j2
        dest: /var/www/html/index.html
    - name: start apache
      service:
        name: apache2
        state: started
        enabled: yes
  handlers:
    - name: restart apache service
      service:
        name: apache2
        state: restarted
        enabled: yes    
/all
db_user: cimsi_user
db_pass: sudo
db_name: mysqlDB
Leave a Comment