From 78e30b62263887b879f33d948f948cc647fb2b32 Mon Sep 17 00:00:00 2001 From: uap32-r Date: Mon, 13 Dec 2021 16:43:56 +0100 Subject: [PATCH] Ansible Tomcat --- SDIS29ansible/ansible/.ppebase.yml.swp | Bin 0 -> 1024 bytes SDIS29ansible/ansible/.test.yml.swp | 0 SDIS29ansible/ansible/hosts | 3 + SDIS29ansible/ansible/invent | 1 + SDIS29ansible/ansible/roles/base/main.yml | 17 +++++ .../ansible/roles/db/handlers/main.yml | 15 ++++ SDIS29ansible/ansible/roles/db/tasks/main.yml | 41 +++++++++++ .../ansible/roles/tomcat/defaults/main.yml | 3 + .../ansible/roles/tomcat/handlers/main.yml | 4 ++ .../ansible/roles/tomcat/tasks/.main.yml.swp | 0 .../ansible/roles/tomcat/tasks/main.yml | 67 ++++++++++++++++++ .../roles/tomcat/templates/context.xml.j2 | 19 +++++ .../tomcat/templates/tomcat-users.xml.j2 | 44 ++++++++++++ .../roles/tomcat/templates/tomcat.service.j2 | 22 ++++++ .../ansible/roles/tomcat/vars/main.yml | 2 + SDIS29ansible/ansible/tomcat-setup.yml | 14 ++++ 16 files changed, 252 insertions(+) create mode 100644 SDIS29ansible/ansible/.ppebase.yml.swp create mode 100644 SDIS29ansible/ansible/.test.yml.swp create mode 100644 SDIS29ansible/ansible/hosts create mode 100644 SDIS29ansible/ansible/invent create mode 100644 SDIS29ansible/ansible/roles/base/main.yml create mode 100644 SDIS29ansible/ansible/roles/db/handlers/main.yml create mode 100644 SDIS29ansible/ansible/roles/db/tasks/main.yml create mode 100644 SDIS29ansible/ansible/roles/tomcat/defaults/main.yml create mode 100644 SDIS29ansible/ansible/roles/tomcat/handlers/main.yml create mode 100644 SDIS29ansible/ansible/roles/tomcat/tasks/.main.yml.swp create mode 100644 SDIS29ansible/ansible/roles/tomcat/tasks/main.yml create mode 100644 SDIS29ansible/ansible/roles/tomcat/templates/context.xml.j2 create mode 100644 SDIS29ansible/ansible/roles/tomcat/templates/tomcat-users.xml.j2 create mode 100644 SDIS29ansible/ansible/roles/tomcat/templates/tomcat.service.j2 create mode 100644 SDIS29ansible/ansible/roles/tomcat/vars/main.yml create mode 100644 SDIS29ansible/ansible/tomcat-setup.yml diff --git a/SDIS29ansible/ansible/.ppebase.yml.swp b/SDIS29ansible/ansible/.ppebase.yml.swp new file mode 100644 index 0000000000000000000000000000000000000000..a263f087f2fba71aa55b7f98820f0fb34d8fbbef GIT binary patch literal 1024 zcmYc?$V<%2S1{ExVL$ + state: present + update_cache: yes diff --git a/SDIS29ansible/ansible/roles/db/handlers/main.yml b/SDIS29ansible/ansible/roles/db/handlers/main.yml new file mode 100644 index 0000000..598434d --- /dev/null +++ b/SDIS29ansible/ansible/roles/db/handlers/main.yml @@ -0,0 +1,15 @@ +handlers: +- name: Reload Apache + service: + name: apache2 + state: reloaded + +- name: Restart Apache + service: + name: apache2 + state: restarted + +- name: Restart mysql + service: + name: mysql + state: restarted diff --git a/SDIS29ansible/ansible/roles/db/tasks/main.yml b/SDIS29ansible/ansible/roles/db/tasks/main.yml new file mode 100644 index 0000000..edd16dd --- /dev/null +++ b/SDIS29ansible/ansible/roles/db/tasks/main.yml @@ -0,0 +1,41 @@ +--- +- hosts: all + tasks: + - name: installation de apache + package: + name: apache2 + state: latest + enabled: yes + + - name: installation de mysql + package: + name: mysql + state: latest + enabled: yes + + - name: installation de mariadb + package: + name: mariadb-server + state: latest + enabled: yes + + - name: initialisation du mot de passe root + mysql_user: + name: root + password: "{{ Azerty1+ }}" + login_unix_socket: /var/run/mysqld/mysqld.sock + + - name: suppression de tous les utilisateurs inconnus + mysql_user: + name: '' + host_all: yes + state: absent + login_user: root + login_password: "{{ Azerty1+ }}" + + - name: suppression de la database test de mysql + mysql_db: + name: test + state: absent + login_user: root + login_password: "{{ mysql_root_password }}" diff --git a/SDIS29ansible/ansible/roles/tomcat/defaults/main.yml b/SDIS29ansible/ansible/roles/tomcat/defaults/main.yml new file mode 100644 index 0000000..0fd6883 --- /dev/null +++ b/SDIS29ansible/ansible/roles/tomcat/defaults/main.yml @@ -0,0 +1,3 @@ +--- +tomcat_archive_url: http://depl/store/apache-tomcat-10.0.13.tar.gz +tomcat_archive_dest: /tmp/apache-tomcat-{{ tomcat_ver }}.tar.gz diff --git a/SDIS29ansible/ansible/roles/tomcat/handlers/main.yml b/SDIS29ansible/ansible/roles/tomcat/handlers/main.yml new file mode 100644 index 0000000..02c4fcb --- /dev/null +++ b/SDIS29ansible/ansible/roles/tomcat/handlers/main.yml @@ -0,0 +1,4 @@ +- name: restart tomcat + service: + name: tomcat + state: restarted diff --git a/SDIS29ansible/ansible/roles/tomcat/tasks/.main.yml.swp b/SDIS29ansible/ansible/roles/tomcat/tasks/.main.yml.swp new file mode 100644 index 0000000..e69de29 diff --git a/SDIS29ansible/ansible/roles/tomcat/tasks/main.yml b/SDIS29ansible/ansible/roles/tomcat/tasks/main.yml new file mode 100644 index 0000000..79c5395 --- /dev/null +++ b/SDIS29ansible/ansible/roles/tomcat/tasks/main.yml @@ -0,0 +1,67 @@ +- name: Install Default Java (Debian/Ubuntu) + apt: + name: default-jdk + state: present + +- name: ajout du groupe tomcat + group: + name: tomcat + +- name: ajout du tomcat user + user: + name: tomcat + group: tomcat + home: /usr/share/tomcat + createhome: no + system: yes + +- name: téléchargement de Tomcat + get_url: + url: "http://depl/store/apache-tomcat-10.0.13.tar.gz" + dest: "{{ tomcat_archive_dest }}" + +- name: Crée une direction pour tomcat + file: + path: /usr/share/tomcat + state: directory + owner: tomcat + group: tomcat + +- name: Extraction de l'archive 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 du tomcat service file + template: + src: tomcat.service.j2 + dest: /etc/systemd/system/tomcat.service + when: ansible_service_mgr == "systemd" + +- name: démarrage et activation de tomcat + service: + daemon_reload: yes + name: tomcat + state: started + enabled: yes + when: ansible_service_mgr == "systemd" + +- name: Set UI access credentials + template: + src: tomcat-users.xml.j2 + dest: /usr/share/tomcat/conf/tomcat-users.xml + notify: restart tomcat + +- name: Allow access to Manager and Host Manager apps from any 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/SDIS29ansible/ansible/roles/tomcat/templates/context.xml.j2 b/SDIS29ansible/ansible/roles/tomcat/templates/context.xml.j2 new file mode 100644 index 0000000..9265673 --- /dev/null +++ b/SDIS29ansible/ansible/roles/tomcat/templates/context.xml.j2 @@ -0,0 +1,19 @@ + + + + diff --git a/SDIS29ansible/ansible/roles/tomcat/templates/tomcat-users.xml.j2 b/SDIS29ansible/ansible/roles/tomcat/templates/tomcat-users.xml.j2 new file mode 100644 index 0000000..dd9bff3 --- /dev/null +++ b/SDIS29ansible/ansible/roles/tomcat/templates/tomcat-users.xml.j2 @@ -0,0 +1,44 @@ + + + + + + + + + + + + + diff --git a/SDIS29ansible/ansible/roles/tomcat/templates/tomcat.service.j2 b/SDIS29ansible/ansible/roles/tomcat/templates/tomcat.service.j2 new file mode 100644 index 0000000..e0d34bd --- /dev/null +++ b/SDIS29ansible/ansible/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/SDIS29ansible/ansible/roles/tomcat/vars/main.yml b/SDIS29ansible/ansible/roles/tomcat/vars/main.yml new file mode 100644 index 0000000..aae9205 --- /dev/null +++ b/SDIS29ansible/ansible/roles/tomcat/vars/main.yml @@ -0,0 +1,2 @@ +--- +JAVA_HOME: /usr/lib/jvm/default-java diff --git a/SDIS29ansible/ansible/tomcat-setup.yml b/SDIS29ansible/ansible/tomcat-setup.yml new file mode 100644 index 0000000..867b571 --- /dev/null +++ b/SDIS29ansible/ansible/tomcat-setup.yml @@ -0,0 +1,14 @@ +--- +- name: Tomcat deployment playbook + hosts: all # Inventory hosts group / server to act on + become: yes # If to escalate privilege + become_method: sudo # Set become method + remote_user: root # Update username for remote server + vars: + tomcat_ver: 10.0.14 # Tomcat version to install + ui_manager_user: manager # User who can access the UI manager section only + ui_manager_pass: azerty1+ # UI manager user password + ui_admin_username: admin # User who can access bpth manager and admin UI sections + ui_admin_pass: Azerty1+ # UI admin password + roles: + - tomcat