From 9f0082b1f2dc3330e1695c8221c3b8ef07ee2863 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Ccameron=2Edesrayaud=E2=80=9D?= Date: Wed, 15 Dec 2021 09:56:20 +0100 Subject: [PATCH] =?UTF-8?q?Ansible=20version=20finalis=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Mission2/{ => ansible}/hosts | 0 Mission2/ansible/mysql-dump.yml | 10 ++++ .../mysql-setup.yml} | 2 +- Mission2/{ => ansible}/playbook.yml | 0 .../ansible/roles/mysql/handlers/main.yml | 6 +++ Mission2/ansible/roles/mysql/tasks/main.yml | 49 +++++++++++++++++++ .../{ => ansible}/roles/mysql/vars/debian.yml | 0 .../roles/mysql_dump/handlers/main.yml | 4 ++ .../ansible/roles/mysql_dump/tasks/main.yml | 15 ++++++ .../roles/mysql_inject/handlers/main.yml | 0 .../ansible/roles/mysql_inject/tasks/main.yml | 14 ++++++ .../roles/tomcat/defaults/main.yml | 0 .../roles/tomcat/handlers/main.yml | 0 .../roles/tomcat/tasks/main.yaml | 0 .../tomcat/tasks/tomcat-setup-Debian.yml | 0 .../roles/tomcat/templates/context.xml.j2 | 0 .../tomcat/templates/tomcat-users.xml.j2 | 0 .../roles/tomcat/templates/tomcat.service.j2 | 0 .../roles/tomcat/vars/Debian.yml | 0 Mission2/{ => ansible}/tomcat-setup.yml | 0 .../roles/mariadb_create_dump/tasks/main.yml | 6 --- .../roles/mariadb_inject_dump/tasks/main.yml | 5 -- Mission2/roles/mysql/handlers/main.yml | 22 --------- Mission2/roles/mysql/tasks/main.yml | 39 --------------- Mission2/roles/openjdk/tasks/main.yml | 8 --- 25 files changed, 99 insertions(+), 81 deletions(-) rename Mission2/{ => ansible}/hosts (100%) create mode 100644 Mission2/ansible/mysql-dump.yml rename Mission2/{mariadb-setup.yml => ansible/mysql-setup.yml} (79%) rename Mission2/{ => ansible}/playbook.yml (100%) create mode 100644 Mission2/ansible/roles/mysql/handlers/main.yml create mode 100644 Mission2/ansible/roles/mysql/tasks/main.yml rename Mission2/{ => ansible}/roles/mysql/vars/debian.yml (100%) create mode 100644 Mission2/ansible/roles/mysql_dump/handlers/main.yml create mode 100644 Mission2/ansible/roles/mysql_dump/tasks/main.yml create mode 100644 Mission2/ansible/roles/mysql_inject/handlers/main.yml create mode 100644 Mission2/ansible/roles/mysql_inject/tasks/main.yml rename Mission2/{ => ansible}/roles/tomcat/defaults/main.yml (100%) rename Mission2/{ => ansible}/roles/tomcat/handlers/main.yml (100%) rename Mission2/{ => ansible}/roles/tomcat/tasks/main.yaml (100%) rename Mission2/{ => ansible}/roles/tomcat/tasks/tomcat-setup-Debian.yml (100%) rename Mission2/{ => ansible}/roles/tomcat/templates/context.xml.j2 (100%) rename Mission2/{ => ansible}/roles/tomcat/templates/tomcat-users.xml.j2 (100%) rename Mission2/{ => ansible}/roles/tomcat/templates/tomcat.service.j2 (100%) rename Mission2/{ => ansible}/roles/tomcat/vars/Debian.yml (100%) rename Mission2/{ => ansible}/tomcat-setup.yml (100%) delete mode 100644 Mission2/roles/mariadb_create_dump/tasks/main.yml delete mode 100644 Mission2/roles/mariadb_inject_dump/tasks/main.yml delete mode 100644 Mission2/roles/mysql/handlers/main.yml delete mode 100644 Mission2/roles/mysql/tasks/main.yml delete mode 100644 Mission2/roles/openjdk/tasks/main.yml diff --git a/Mission2/hosts b/Mission2/ansible/hosts similarity index 100% rename from Mission2/hosts rename to Mission2/ansible/hosts diff --git a/Mission2/ansible/mysql-dump.yml b/Mission2/ansible/mysql-dump.yml new file mode 100644 index 0000000..24b8a2d --- /dev/null +++ b/Mission2/ansible/mysql-dump.yml @@ -0,0 +1,10 @@ +--- +- name: mysql dump playbook + hosts: test + become: yes + become_method: sudo + remote_user: root + + roles: + - mysql_dump + diff --git a/Mission2/mariadb-setup.yml b/Mission2/ansible/mysql-setup.yml similarity index 79% rename from Mission2/mariadb-setup.yml rename to Mission2/ansible/mysql-setup.yml index aa644a5..eb1b22a 100644 --- a/Mission2/mariadb-setup.yml +++ b/Mission2/ansible/mysql-setup.yml @@ -1,5 +1,5 @@ --- -- name: Tomcat playbook +- name: MariaDB playbook hosts: test become: yes become_method: sudo diff --git a/Mission2/playbook.yml b/Mission2/ansible/playbook.yml similarity index 100% rename from Mission2/playbook.yml rename to Mission2/ansible/playbook.yml diff --git a/Mission2/ansible/roles/mysql/handlers/main.yml b/Mission2/ansible/roles/mysql/handlers/main.yml new file mode 100644 index 0000000..2574d84 --- /dev/null +++ b/Mission2/ansible/roles/mysql/handlers/main.yml @@ -0,0 +1,6 @@ +--- +- name: restart mariadb + service: + name: mariadb + state: restarted + diff --git a/Mission2/ansible/roles/mysql/tasks/main.yml b/Mission2/ansible/roles/mysql/tasks/main.yml new file mode 100644 index 0000000..95e30b5 --- /dev/null +++ b/Mission2/ansible/roles/mysql/tasks/main.yml @@ -0,0 +1,49 @@ +--- +- name: "MYSQL - update cache" + apt: + update_cache: yes + +- name: "MYSQL - installation" + apt: + name: mariadb-server + state: latest + +- name: "PYTHON3 - installation" + apt: + name: python3-pymysql + state: latest + +- name: "MYSQL - démarrage de mysql" + service: + name: "mysqld" + state: started + enabled: yes + +- name: "MYSQL - creation base de données" + community.mysql.mysql_db: + name: sdis29 + state: present + login_unix_socket: /var/run/mysqld/mysqld.sock + check_implicit_admin: yes + +- name: "MYSQL - creation utilisateur" + mysql_user: + name: "dev" + password: "Azerty1+" + priv: "*.*:ALL" + host: "localhost" + login_unix_socket: /var/run/mysqld/mysqld.sock + +- name: copie de la base de donnée + copy: + src: ~/sauvegarde/sql/sdis29-dump.sql + dest: /tmp/ + +- name: Importation de la base de données + mysql_db: + name: sdis29 + state: import + target: /tmp/sdis29.sql + login_user: dev + login_password: Azerty1+ + login_unix_socket: /var/run/mysqld/mysqld.sock diff --git a/Mission2/roles/mysql/vars/debian.yml b/Mission2/ansible/roles/mysql/vars/debian.yml similarity index 100% rename from Mission2/roles/mysql/vars/debian.yml rename to Mission2/ansible/roles/mysql/vars/debian.yml diff --git a/Mission2/ansible/roles/mysql_dump/handlers/main.yml b/Mission2/ansible/roles/mysql_dump/handlers/main.yml new file mode 100644 index 0000000..93da618 --- /dev/null +++ b/Mission2/ansible/roles/mysql_dump/handlers/main.yml @@ -0,0 +1,4 @@ +- name: Restart mysqld + ansible.builtin.service: + name: mysqld + state: restarted diff --git a/Mission2/ansible/roles/mysql_dump/tasks/main.yml b/Mission2/ansible/roles/mysql_dump/tasks/main.yml new file mode 100644 index 0000000..29486a2 --- /dev/null +++ b/Mission2/ansible/roles/mysql_dump/tasks/main.yml @@ -0,0 +1,15 @@ +- name: exportation de la base de données + mysql_db: + name: sdis29 + state: dump + target: /tmp/sdis29-dump.sql + login_user: dev + login_password: Azerty1+ + login_unix_socket: /var/run/mysqld/mysqld.sock + +- name: importation du dump de la base de donnée + ansible.builtin.fetch: + src: /tmp/sdis29-dump.sql + dest: /root/sauvegarde/sql/ + flat: yes + diff --git a/Mission2/ansible/roles/mysql_inject/handlers/main.yml b/Mission2/ansible/roles/mysql_inject/handlers/main.yml new file mode 100644 index 0000000..e69de29 diff --git a/Mission2/ansible/roles/mysql_inject/tasks/main.yml b/Mission2/ansible/roles/mysql_inject/tasks/main.yml new file mode 100644 index 0000000..4665e80 --- /dev/null +++ b/Mission2/ansible/roles/mysql_inject/tasks/main.yml @@ -0,0 +1,14 @@ +- name: copie de la base de donnée + copy: + src: sdis29.sql + dest: /tmp + +- name: Importation de la base de données + mysql_db: + name: sdis29 + state: import + target: /tmp/sdis29.sql + login_user: dev + login_password: Azerty1+ + login_unix_socket: /var/run/mysqld/mysqld.sock + diff --git a/Mission2/roles/tomcat/defaults/main.yml b/Mission2/ansible/roles/tomcat/defaults/main.yml similarity index 100% rename from Mission2/roles/tomcat/defaults/main.yml rename to Mission2/ansible/roles/tomcat/defaults/main.yml diff --git a/Mission2/roles/tomcat/handlers/main.yml b/Mission2/ansible/roles/tomcat/handlers/main.yml similarity index 100% rename from Mission2/roles/tomcat/handlers/main.yml rename to Mission2/ansible/roles/tomcat/handlers/main.yml diff --git a/Mission2/roles/tomcat/tasks/main.yaml b/Mission2/ansible/roles/tomcat/tasks/main.yaml similarity index 100% rename from Mission2/roles/tomcat/tasks/main.yaml rename to Mission2/ansible/roles/tomcat/tasks/main.yaml diff --git a/Mission2/roles/tomcat/tasks/tomcat-setup-Debian.yml b/Mission2/ansible/roles/tomcat/tasks/tomcat-setup-Debian.yml similarity index 100% rename from Mission2/roles/tomcat/tasks/tomcat-setup-Debian.yml rename to Mission2/ansible/roles/tomcat/tasks/tomcat-setup-Debian.yml diff --git a/Mission2/roles/tomcat/templates/context.xml.j2 b/Mission2/ansible/roles/tomcat/templates/context.xml.j2 similarity index 100% rename from Mission2/roles/tomcat/templates/context.xml.j2 rename to Mission2/ansible/roles/tomcat/templates/context.xml.j2 diff --git a/Mission2/roles/tomcat/templates/tomcat-users.xml.j2 b/Mission2/ansible/roles/tomcat/templates/tomcat-users.xml.j2 similarity index 100% rename from Mission2/roles/tomcat/templates/tomcat-users.xml.j2 rename to Mission2/ansible/roles/tomcat/templates/tomcat-users.xml.j2 diff --git a/Mission2/roles/tomcat/templates/tomcat.service.j2 b/Mission2/ansible/roles/tomcat/templates/tomcat.service.j2 similarity index 100% rename from Mission2/roles/tomcat/templates/tomcat.service.j2 rename to Mission2/ansible/roles/tomcat/templates/tomcat.service.j2 diff --git a/Mission2/roles/tomcat/vars/Debian.yml b/Mission2/ansible/roles/tomcat/vars/Debian.yml similarity index 100% rename from Mission2/roles/tomcat/vars/Debian.yml rename to Mission2/ansible/roles/tomcat/vars/Debian.yml diff --git a/Mission2/tomcat-setup.yml b/Mission2/ansible/tomcat-setup.yml similarity index 100% rename from Mission2/tomcat-setup.yml rename to Mission2/ansible/tomcat-setup.yml diff --git a/Mission2/roles/mariadb_create_dump/tasks/main.yml b/Mission2/roles/mariadb_create_dump/tasks/main.yml deleted file mode 100644 index 1d604a9..0000000 --- a/Mission2/roles/mariadb_create_dump/tasks/main.yml +++ /dev/null @@ -1,6 +0,0 @@ - - -- name: exportation du dump - copy: - src: db-sauv.sql.gz - dest: /tmp diff --git a/Mission2/roles/mariadb_inject_dump/tasks/main.yml b/Mission2/roles/mariadb_inject_dump/tasks/main.yml deleted file mode 100644 index c3ba86a..0000000 --- a/Mission2/roles/mariadb_inject_dump/tasks/main.yml +++ /dev/null @@ -1,5 +0,0 @@ -- name: Restoration la base de données - community.mysql.mysql_db: - name: my_db - state: import - target: /tmp/db-sauv.sql.gz diff --git a/Mission2/roles/mysql/handlers/main.yml b/Mission2/roles/mysql/handlers/main.yml deleted file mode 100644 index 2b94486..0000000 --- a/Mission2/roles/mysql/handlers/main.yml +++ /dev/null @@ -1,22 +0,0 @@ ---- -# handlers file for mariadb -- name: set mariadb log selinux - sefcontext: - target: '/var/log/mariadb(/.*)?' - setype: mysqld_log_t - state: present -- name: restart mariadb server - systemd: - name: "{{ mariadb_service }}" - state: restarted - enabled: yes - -- name: Remove test database priviledges - command: mysql -u root -p{{ mysql_root_password }} -e "DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%'" - -- name: Flush Priviliges - command: mysql -u root -p{{ mysql_root_password }} -e "FLUSH PRIVILEGES" - -- name: Update repo cache - apt: - update_cache: yes diff --git a/Mission2/roles/mysql/tasks/main.yml b/Mission2/roles/mysql/tasks/main.yml deleted file mode 100644 index 3e401c8..0000000 --- a/Mission2/roles/mysql/tasks/main.yml +++ /dev/null @@ -1,39 +0,0 @@ -- name: "[MYSQL] - update cache" - apt: - update_cache: yes - -- name: "[MYSQL] - install" - apt: - name: mariadb-server - state: latest - -- name: "[Python] - install" - apt: - name: python - state: latest - -- name: "[MYSQL] - start mysql" - service: - name: "mysqld" - state: started - enabled: yes - -- name: "[MYSQL] - create database" - community.mysql.mysql_db: - name: - - sdis29 - state: present - -- name: "[MYSQL] - create user" - mysql_user: - name: "dev" - password: "Azerty1+" - priv: "*.*:ALL" - host: "127.0.0.1" - become: yes - -- name: Restoration la base de données - community.mysql.mysql_db: - name: my_db - state: import - target: /tmp/db-sauv.sql.gz diff --git a/Mission2/roles/openjdk/tasks/main.yml b/Mission2/roles/openjdk/tasks/main.yml deleted file mode 100644 index 656b022..0000000 --- a/Mission2/roles/openjdk/tasks/main.yml +++ /dev/null @@ -1,8 +0,0 @@ ---- -- hosts: all - - tasks: - - name: install openjdk-17 - apt : - name: openjdk-17-jdk - state: present