diff --git a/Mission2/hosts b/Mission2/hosts new file mode 100644 index 0000000..ef9c739 --- /dev/null +++ b/Mission2/hosts @@ -0,0 +1,9 @@ +[localhost] +localhost + +[test] +tomcattest + +[proxsrv] +10.121.38.65 + diff --git a/Mission2/mariadb-setup.yml b/Mission2/mariadb-setup.yml new file mode 100644 index 0000000..aa644a5 --- /dev/null +++ b/Mission2/mariadb-setup.yml @@ -0,0 +1,9 @@ +--- +- name: Tomcat playbook + hosts: test + become: yes + become_method: sudo + remote_user: root + + roles: + - mysql diff --git a/Mission2/playbook.yml b/Mission2/playbook.yml new file mode 100644 index 0000000..fa32652 --- /dev/null +++ b/Mission2/playbook.yml @@ -0,0 +1,13 @@ +--- +- hosts: test + remote_user: root + become: yes + become_method: sudo + + roles: + - tomcat + - mariadb + - mariadb_create_dump + - mariadb_create_usr + - mariadb_inject_dump + - openjdk diff --git a/Mission2/roles/mariadb_create_dump/tasks/main.yml b/Mission2/roles/mariadb_create_dump/tasks/main.yml new file mode 100644 index 0000000..1d604a9 --- /dev/null +++ b/Mission2/roles/mariadb_create_dump/tasks/main.yml @@ -0,0 +1,6 @@ + + +- 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 new file mode 100644 index 0000000..c3ba86a --- /dev/null +++ b/Mission2/roles/mariadb_inject_dump/tasks/main.yml @@ -0,0 +1,5 @@ +- 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 new file mode 100644 index 0000000..2b94486 --- /dev/null +++ b/Mission2/roles/mysql/handlers/main.yml @@ -0,0 +1,22 @@ +--- +# 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 new file mode 100644 index 0000000..3e401c8 --- /dev/null +++ b/Mission2/roles/mysql/tasks/main.yml @@ -0,0 +1,39 @@ +- 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/mysql/vars/debian.yml b/Mission2/roles/mysql/vars/debian.yml new file mode 100644 index 0000000..0d5305e --- /dev/null +++ b/Mission2/roles/mysql/vars/debian.yml @@ -0,0 +1,12 @@ +mariadb_packages: + - mariadb-server + - mariadb-common + - python-mysqldb + - python-openssl +repo_software_package: + - software-properties-common + - dirmngr + - apt-transport-https +key_url: "https://mariadb.org/mariadb_release_signing_key.asc" +repo_deb: deb [arch=amd64] https://mirror.klaus-uwe.me/mariadb/repo/10.4/debian +mariadb_socket: /run/mysqld/mysqld.sock diff --git a/Mission2/roles/openjdk/tasks/main.yml b/Mission2/roles/openjdk/tasks/main.yml new file mode 100644 index 0000000..656b022 --- /dev/null +++ b/Mission2/roles/openjdk/tasks/main.yml @@ -0,0 +1,8 @@ +--- +- hosts: all + + tasks: + - name: install openjdk-17 + apt : + name: openjdk-17-jdk + state: present diff --git a/Mission2/roles/tomcat/defaults/main.yml b/Mission2/roles/tomcat/defaults/main.yml new file mode 100644 index 0000000..c4ee4c4 --- /dev/null +++ b/Mission2/roles/tomcat/defaults/main.yml @@ -0,0 +1,3 @@ +--- +tomcat_archive_url: https://dlcdn.apache.org/tomcat/tomcat-10/v10.0.13/bin/apache-tomcat-10.0.13.tar.gz +tomcat_archive_dest: /tmp/apache-tomcat-{{ tomcat_ver }}.tar.gz diff --git a/Mission2/roles/tomcat/handlers/main.yml b/Mission2/roles/tomcat/handlers/main.yml new file mode 100644 index 0000000..02c4fcb --- /dev/null +++ b/Mission2/roles/tomcat/handlers/main.yml @@ -0,0 +1,4 @@ +- name: restart tomcat + service: + name: tomcat + state: restarted diff --git a/Mission2/roles/tomcat/tasks/main.yaml b/Mission2/roles/tomcat/tasks/main.yaml new file mode 100644 index 0000000..9ba17ed --- /dev/null +++ b/Mission2/roles/tomcat/tasks/main.yaml @@ -0,0 +1,8 @@ +--- +- name: Add the OS specific variables + include_vars: "{{ item }}" + with_first_found: + - "{{ ansible_distribution }}{{ ansible_distribution_major_version }}.yml" + - "{{ ansible_os_family }}.yml" + +- include_tasks: "tomcat-setup-{{ ansible_os_family }}.yml" diff --git a/Mission2/roles/tomcat/tasks/tomcat-setup-Debian.yml b/Mission2/roles/tomcat/tasks/tomcat-setup-Debian.yml new file mode 100644 index 0000000..1bf92f2 --- /dev/null +++ b/Mission2/roles/tomcat/tasks/tomcat-setup-Debian.yml @@ -0,0 +1,85 @@ +- name: S'assurer que le système utilise le port HTTPS pour APT. + stat: + path: /usr/lib/apt/methods/https + register: apt_https_transport + +- name: Installation APT HTTPS transport. + apt: + name: "apt-transport-https" + state: present + update_cache: yes + when: not apt_https_transport.stat.exists + +- name: Installation packages basique + package: + name: ['vim','aptitude','bash-completion','tmux','tree','htop','wget','unzip','curl','git','python'] + state: present + update_cache: yes + +- name: Installation Java (Debian/Ubuntu) + apt: + name: default-jdk + state: present + +- name: Ajout tomcat dans un groupe + group: + name: tomcat + +- name: Ajout "tomcat" au user + user: + name: tomcat + group: tomcat + home: /usr/share/tomcat + createhome: no + system: yes + +- name: Installation Tomcat + get_url: + url: "https://dlcdn.apache.org/tomcat/tomcat-10/v10.0.14/bin/apache-tomcat-10.0.14.tar.gz" + dest: "{{ tomcat_archive_dest }}" + +- name: Création du répertoire tomcat + file: + path: /usr/share/tomcat + state: directory + owner: tomcat + group: tomcat + +- name: Extraction archive de tomcat + unarchive: + src: "{{ tomcat_archive_dest }}" + dest: /usr/share/tomcat + owner: tomcat + group: tomcat + remote_src: yes + extra_opts: "--strip-components=1" + creates: /usr/share/tomcat/bin + +- name: Copie tomcat fichier service* + template: + src: templates/tomcat.service.j2 + dest: /etc/systemd/system/tomcat.service + when: ansible_service_mgr == "systemd" + +- name: Démarrer et activé tomcat + service: + daemon_reload: yes + name: tomcat + state: started + enabled: yes + when: ansible_service_mgr == "systemd" +- name: Définir l'accès a l'interface utilisateur authentifié + template: + src: tomcat-users.xml.j2 + dest: /usr/share/tomcat/conf/tomcat-users.xml + notify: restart tomcat + +- name: Autoriser l'accès aux applications du gestionnaire et gestionnaire d'hote sur n'importe qu'elle IP + template: + src: context.xml.j2 + dest: "{{ item }}" + with_items: + - /usr/share/tomcat/webapps/host-manager/META-INF/context.xml + - /usr/share/tomcat/webapps/manager/META-INF/context.xml + notify: restart tomcat + diff --git a/Mission2/roles/tomcat/templates/context.xml.j2 b/Mission2/roles/tomcat/templates/context.xml.j2 new file mode 100644 index 0000000..9265673 --- /dev/null +++ b/Mission2/roles/tomcat/templates/context.xml.j2 @@ -0,0 +1,19 @@ + + + + diff --git a/Mission2/roles/tomcat/templates/tomcat-users.xml.j2 b/Mission2/roles/tomcat/templates/tomcat-users.xml.j2 new file mode 100644 index 0000000..976627e --- /dev/null +++ b/Mission2/roles/tomcat/templates/tomcat-users.xml.j2 @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + diff --git a/Mission2/roles/tomcat/templates/tomcat.service.j2 b/Mission2/roles/tomcat/templates/tomcat.service.j2 new file mode 100644 index 0000000..e0d34bd --- /dev/null +++ b/Mission2/roles/tomcat/templates/tomcat.service.j2 @@ -0,0 +1,22 @@ +[Unit] +Description=Tomcat +After=syslog.target network.target + +[Service] +Type=forking + +User=tomcat +Group=tomcat + +Environment=JAVA_HOME={{ JAVA_HOME }} +Environment='JAVA_OPTS=-Djava.awt.headless=true' + +Environment=CATALINA_HOME=/usr/share/tomcat +Environment=CATALINA_BASE=/usr/share/tomcat +Environment=CATALINA_PID=/usr/share/tomcat/temp/tomcat.pid + +ExecStart=/usr/share/tomcat/bin/catalina.sh start +ExecStop=/usr/share/tomcat/bin/catalina.sh stop + +[Install] +WantedBy=multi-user.target diff --git a/Mission2/roles/tomcat/vars/Debian.yml b/Mission2/roles/tomcat/vars/Debian.yml new file mode 100644 index 0000000..aae9205 --- /dev/null +++ b/Mission2/roles/tomcat/vars/Debian.yml @@ -0,0 +1,2 @@ +--- +JAVA_HOME: /usr/lib/jvm/default-java diff --git a/Mission2/tomcat-setup.yml b/Mission2/tomcat-setup.yml new file mode 100644 index 0000000..cccb4da --- /dev/null +++ b/Mission2/tomcat-setup.yml @@ -0,0 +1,15 @@ +--- +- name: Tomcat playbook + hosts: test + become: yes + become_method: sudo + remote_user: root + vars: + tomcat_ver: 10.0.13 + ui_manager_user: manager + ui_manager_pass: root + ui_admin_username: admin + ui_admin_pass: root + roles: + - tomcat +