From 50574192c4425c011aa40759160c53670487ccdc Mon Sep 17 00:00:00 2001 From: IDEZ Ugo Date: Tue, 14 Dec 2021 15:11:34 +0100 Subject: [PATCH] Tomcat Playbook --- tomcat/config => config | 0 {tomcat/ppebase => ppebase}/exans.yml | 0 {tomcat/ppebase => ppebase}/hosts | 0 {tomcat/ppebase => ppebase}/invent.txt | 0 .../roles/bdd/tasks/mariadb.yml | 0 .../roles/bdddump/tasks/createdump.yml | 0 .../roles/tomcat/defaults/main.yml | 2 +- ppebase/roles/tomcat/defaults/main.yml.sv1 | 2 + ppebase/roles/tomcat/handlers/main.yml | 0 ppebase/roles/tomcat/tasks/main.yml | 74 +++++++++++++++++++ .../roles/tomcat/tasks/main.yml.sv1 | 0 .../roles/tomcat/tasks/main.yml.sv2 | 0 .../roles/tomcat/tasks/main.yml.sv3 | 13 +++- .../roles/tomcat/templates/context.xml.j2 | 0 .../tomcat/templates/tomcat-users.xml.j2 | 0 .../roles/tomcat/templates/tomcat.service.j2 | 22 ++++++ .../roles/tomcat/vars/main.yml | 0 {tomcat/ppebase => ppebase}/tomcat-setup.yml | 0 tomcat/ppebase/context.xml | 19 ----- tomcat/ppebase/roles/tomcat/handlers/main.yml | 4 - .../roles/tomcat/templates/tomcat.service.j2 | 22 ------ tomcat/ppebase/tomcat-users.xml | 44 ----------- 22 files changed, 109 insertions(+), 93 deletions(-) rename tomcat/config => config (100%) rename {tomcat/ppebase => ppebase}/exans.yml (100%) rename {tomcat/ppebase => ppebase}/hosts (100%) rename {tomcat/ppebase => ppebase}/invent.txt (100%) rename {tomcat/ppebase => ppebase}/roles/bdd/tasks/mariadb.yml (100%) rename {tomcat/ppebase => ppebase}/roles/bdddump/tasks/createdump.yml (100%) rename {tomcat/ppebase => ppebase}/roles/tomcat/defaults/main.yml (51%) create mode 100644 ppebase/roles/tomcat/defaults/main.yml.sv1 create mode 100644 ppebase/roles/tomcat/handlers/main.yml create mode 100644 ppebase/roles/tomcat/tasks/main.yml rename {tomcat/ppebase => ppebase}/roles/tomcat/tasks/main.yml.sv1 (100%) rename {tomcat/ppebase => ppebase}/roles/tomcat/tasks/main.yml.sv2 (100%) rename tomcat/ppebase/roles/tomcat/tasks/main.yml => ppebase/roles/tomcat/tasks/main.yml.sv3 (81%) rename {tomcat/ppebase => ppebase}/roles/tomcat/templates/context.xml.j2 (100%) rename {tomcat/ppebase => ppebase}/roles/tomcat/templates/tomcat-users.xml.j2 (100%) create mode 100644 ppebase/roles/tomcat/templates/tomcat.service.j2 rename {tomcat/ppebase => ppebase}/roles/tomcat/vars/main.yml (100%) rename {tomcat/ppebase => ppebase}/tomcat-setup.yml (100%) delete mode 100644 tomcat/ppebase/context.xml delete mode 100644 tomcat/ppebase/roles/tomcat/handlers/main.yml delete mode 100644 tomcat/ppebase/roles/tomcat/templates/tomcat.service.j2 delete mode 100644 tomcat/ppebase/tomcat-users.xml diff --git a/tomcat/config b/config similarity index 100% rename from tomcat/config rename to config diff --git a/tomcat/ppebase/exans.yml b/ppebase/exans.yml similarity index 100% rename from tomcat/ppebase/exans.yml rename to ppebase/exans.yml diff --git a/tomcat/ppebase/hosts b/ppebase/hosts similarity index 100% rename from tomcat/ppebase/hosts rename to ppebase/hosts diff --git a/tomcat/ppebase/invent.txt b/ppebase/invent.txt similarity index 100% rename from tomcat/ppebase/invent.txt rename to ppebase/invent.txt diff --git a/tomcat/ppebase/roles/bdd/tasks/mariadb.yml b/ppebase/roles/bdd/tasks/mariadb.yml similarity index 100% rename from tomcat/ppebase/roles/bdd/tasks/mariadb.yml rename to ppebase/roles/bdd/tasks/mariadb.yml diff --git a/tomcat/ppebase/roles/bdddump/tasks/createdump.yml b/ppebase/roles/bdddump/tasks/createdump.yml similarity index 100% rename from tomcat/ppebase/roles/bdddump/tasks/createdump.yml rename to ppebase/roles/bdddump/tasks/createdump.yml diff --git a/tomcat/ppebase/roles/tomcat/defaults/main.yml b/ppebase/roles/tomcat/defaults/main.yml similarity index 51% rename from tomcat/ppebase/roles/tomcat/defaults/main.yml rename to ppebase/roles/tomcat/defaults/main.yml index 4b7a55b..3ab700f 100644 --- a/tomcat/ppebase/roles/tomcat/defaults/main.yml +++ b/ppebase/roles/tomcat/defaults/main.yml @@ -1,2 +1,2 @@ tomcat_archive_url: http://depl/store/apache-tomcat-10.0.13.tar.gz -tomcat_archive_dest: /opt/tomcat/apache-tomcat-10.0.13.tar.gz +tomcat_archive_dest: /usr/share/tomcat/ diff --git a/ppebase/roles/tomcat/defaults/main.yml.sv1 b/ppebase/roles/tomcat/defaults/main.yml.sv1 new file mode 100644 index 0000000..ecea063 --- /dev/null +++ b/ppebase/roles/tomcat/defaults/main.yml.sv1 @@ -0,0 +1,2 @@ +tomcat_archive_url: http://depl/store/apache-tomcat-10.0.13.tar.gz +tomcat_archive_dest: /usr/share/tomcat/apache-tomcat-10.0.13.tar.gz diff --git a/ppebase/roles/tomcat/handlers/main.yml b/ppebase/roles/tomcat/handlers/main.yml new file mode 100644 index 0000000..e69de29 diff --git a/ppebase/roles/tomcat/tasks/main.yml b/ppebase/roles/tomcat/tasks/main.yml new file mode 100644 index 0000000..aa09550 --- /dev/null +++ b/ppebase/roles/tomcat/tasks/main.yml @@ -0,0 +1,74 @@ + - name: Install basic packages + package: + name: ['vim','aptitude','bash-completion','tmux','tree','htop','wget','unzip','curl','git','python'] + state: present + update_cache: yes + + - name: installer JDK + apt: + name: openjdk-11-jdk + state: present + + - name: creer le repertoire /opt/tomcat + file: + path: /usr/share/tomcat + state: directory + mode: 0755 + + - name: creer le groupe tomcat + group: + name: tomcat + + - name: creer l'utilisateur tomcat + user: + name: tomcat + group: tomcat + home: /usr/share/tomcat + createhome: no + + - name: installer TomCat + unarchive: + src: http://depl/store/apache-tomcat-10.0.13.tar.gz + dest: /usr/share/tomcat + remote_src: yes + + - name: Change ownership + file: + path: /usr/share/tomcat + owner: tomcat + group: tomcat + mode: "u+rwx,g+rx,o=rx" + recurse: yes + state: directory + + - name: Templating Tomcat service from local to remote + template: + src: tomcat.service.j2 + dest: /etc/systemd/system/tomcat.service + when: ansible_service_mgr == "systemd" + + - name: Demarrer tomcat + local_action: command sh /usr/share/tomcat/apache-tomcat-10.0.13/bin/startup.sh + + - name: Definition des utilisateurs + template: + src: tomcat-users.xml.j2 + dest: /usr/share/tomcat/apache-tomcat-10.0.13/conf/tomcat-users.xml + + - name: Autorisation des différentes ips de connexions + template: + src: context.xml.j2 + dest: "{{ item }}" + with_items: + - /usr/share/tomcat/apache-tomcat-10.0.13/webapps/host-manager/META-INF/context.xml + - /usr/share/tomcat/apache-tomcat-10.0.13/webapps/manager/META-INF/context.xml + + - name: Redemarrer le service tomcat (1) + local_action: command sh /usr/share/tomcat/apache-tomcat-10.0.13/bin/shutdown.sh + + - name: Redemarrer le service tomcat (2) + local_action: command sh /usr/share/tomcat/apache-tomcat-10.0.13/bin/startup.sh + + - name: Redemarrer le service tomcat (3) + local_action: command sh /usr/share/tomcat/apache-tomcat-10.0.13/bin/catalina.sh start + diff --git a/tomcat/ppebase/roles/tomcat/tasks/main.yml.sv1 b/ppebase/roles/tomcat/tasks/main.yml.sv1 similarity index 100% rename from tomcat/ppebase/roles/tomcat/tasks/main.yml.sv1 rename to ppebase/roles/tomcat/tasks/main.yml.sv1 diff --git a/tomcat/ppebase/roles/tomcat/tasks/main.yml.sv2 b/ppebase/roles/tomcat/tasks/main.yml.sv2 similarity index 100% rename from tomcat/ppebase/roles/tomcat/tasks/main.yml.sv2 rename to ppebase/roles/tomcat/tasks/main.yml.sv2 diff --git a/tomcat/ppebase/roles/tomcat/tasks/main.yml b/ppebase/roles/tomcat/tasks/main.yml.sv3 similarity index 81% rename from tomcat/ppebase/roles/tomcat/tasks/main.yml rename to ppebase/roles/tomcat/tasks/main.yml.sv3 index 5dba831..1fc6574 100644 --- a/tomcat/ppebase/roles/tomcat/tasks/main.yml +++ b/ppebase/roles/tomcat/tasks/main.yml.sv3 @@ -43,9 +43,10 @@ - name: Templating Tomcat service from local to remote template: - src: tomcat.service.j2 - dest: /etc/systemd/system/ - mode: 0755 + src: templates/tomcat.service.j2 + dest: /etc/systemd/system/tomcat.service + when: ansible_service_mgr == "systemd" + - name: Demarrer le service tomcat local_action: command sh /opt/tomcat/apache-tomcat-10.0.13/bin/startup.sh @@ -62,6 +63,12 @@ src: context.xml.j2 dest: context.xml + - name: changement de la ligne dans context.xml + replace: + path: tomcat-users.xml + regexp: + replace: + - name: Redemarrer le service tomcat (1) local_action: command sh /opt/tomcat/apache-tomcat-10.0.13/bin/shutdown.sh diff --git a/tomcat/ppebase/roles/tomcat/templates/context.xml.j2 b/ppebase/roles/tomcat/templates/context.xml.j2 similarity index 100% rename from tomcat/ppebase/roles/tomcat/templates/context.xml.j2 rename to ppebase/roles/tomcat/templates/context.xml.j2 diff --git a/tomcat/ppebase/roles/tomcat/templates/tomcat-users.xml.j2 b/ppebase/roles/tomcat/templates/tomcat-users.xml.j2 similarity index 100% rename from tomcat/ppebase/roles/tomcat/templates/tomcat-users.xml.j2 rename to ppebase/roles/tomcat/templates/tomcat-users.xml.j2 diff --git a/ppebase/roles/tomcat/templates/tomcat.service.j2 b/ppebase/roles/tomcat/templates/tomcat.service.j2 new file mode 100644 index 0000000..1c902f5 --- /dev/null +++ b/ppebase/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/apache-tomcat-10.0.13 +Environment=CATALINA_BASE=/usr/share/tomcat/apache-tomcat-10.0.13 +Environment=CATALINA_PID=/usr/share/tomcat/apache-tomcat-10.0.13/temp/tomcat.pid + +ExecStart=catalina.sh start +ExecStop=catalina.sh stop + +[Install] +WantedBy=multi-user.target diff --git a/tomcat/ppebase/roles/tomcat/vars/main.yml b/ppebase/roles/tomcat/vars/main.yml similarity index 100% rename from tomcat/ppebase/roles/tomcat/vars/main.yml rename to ppebase/roles/tomcat/vars/main.yml diff --git a/tomcat/ppebase/tomcat-setup.yml b/ppebase/tomcat-setup.yml similarity index 100% rename from tomcat/ppebase/tomcat-setup.yml rename to ppebase/tomcat-setup.yml diff --git a/tomcat/ppebase/context.xml b/tomcat/ppebase/context.xml deleted file mode 100644 index 9265673..0000000 --- a/tomcat/ppebase/context.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - diff --git a/tomcat/ppebase/roles/tomcat/handlers/main.yml b/tomcat/ppebase/roles/tomcat/handlers/main.yml deleted file mode 100644 index 02c4fcb..0000000 --- a/tomcat/ppebase/roles/tomcat/handlers/main.yml +++ /dev/null @@ -1,4 +0,0 @@ -- name: restart tomcat - service: - name: tomcat - state: restarted diff --git a/tomcat/ppebase/roles/tomcat/templates/tomcat.service.j2 b/tomcat/ppebase/roles/tomcat/templates/tomcat.service.j2 deleted file mode 100644 index 0ce7236..0000000 --- a/tomcat/ppebase/roles/tomcat/templates/tomcat.service.j2 +++ /dev/null @@ -1,22 +0,0 @@ -[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=/opt/tomcat/bin/catalina.sh start -ExecStop=/opt/tomcat/bin/catalina.sh stop - -[Install] -WantedBy=multi-user.target diff --git a/tomcat/ppebase/tomcat-users.xml b/tomcat/ppebase/tomcat-users.xml deleted file mode 100644 index 37c05aa..0000000 --- a/tomcat/ppebase/tomcat-users.xml +++ /dev/null @@ -1,44 +0,0 @@ - - - - - - - - - - - - -