From d0ed7df8872737e3f2015890402d30c50217672d Mon Sep 17 00:00:00 2001 From: IDEZ Ugo Date: Wed, 15 Dec 2021 11:51:25 +0100 Subject: [PATCH] Playbook pour tomcat et mariadb --- ap34prod/hosts | 3 + .../tomcat-setup.yml => ap34prod/ppebase.yml | 2 +- ap34prod/ppedb.yml | 9 ++ .../roles/ppebase}/defaults/main.yml | 0 .../roles/ppebase}/handlers/main.yml | 0 .../roles/ppebase}/tasks/main.yml | 22 ++++ .../roles/ppebase}/templates/context.xml.j2 | 0 .../ppebase}/templates/tomcat-users.xml.j2 | 0 .../ppebase}/templates/tomcat.service.j2 | 0 .../roles/ppebase}/vars/main.yml | 0 ap34prod/roles/ppedb/tasks/main.yml | 20 ++++ .../roles/svbdd}/tasks/createdump.yml | 0 ppebase/exans.yml | 4 - ppebase/hosts | 1 - ppebase/invent.txt | 1 - ppebase/roles/bdd/tasks/mariadb.yml | 39 ------- ppebase/roles/tomcat/defaults/main.yml.sv1 | 2 - ppebase/roles/tomcat/tasks/main.yml.sv1 | 100 ------------------ ppebase/roles/tomcat/tasks/main.yml.sv2 | 68 ------------ ppebase/roles/tomcat/tasks/main.yml.sv3 | 76 ------------- 20 files changed, 55 insertions(+), 292 deletions(-) create mode 100644 ap34prod/hosts rename ppebase/tomcat-setup.yml => ap34prod/ppebase.yml (97%) create mode 100644 ap34prod/ppedb.yml rename {ppebase/roles/tomcat => ap34prod/roles/ppebase}/defaults/main.yml (100%) rename {ppebase/roles/tomcat => ap34prod/roles/ppebase}/handlers/main.yml (100%) rename {ppebase/roles/tomcat => ap34prod/roles/ppebase}/tasks/main.yml (84%) rename {ppebase/roles/tomcat => ap34prod/roles/ppebase}/templates/context.xml.j2 (100%) rename {ppebase/roles/tomcat => ap34prod/roles/ppebase}/templates/tomcat-users.xml.j2 (100%) rename {ppebase/roles/tomcat => ap34prod/roles/ppebase}/templates/tomcat.service.j2 (100%) rename {ppebase/roles/tomcat => ap34prod/roles/ppebase}/vars/main.yml (100%) create mode 100755 ap34prod/roles/ppedb/tasks/main.yml rename {ppebase/roles/bdddump => ap34prod/roles/svbdd}/tasks/createdump.yml (100%) delete mode 100644 ppebase/exans.yml delete mode 100644 ppebase/hosts delete mode 100644 ppebase/invent.txt delete mode 100755 ppebase/roles/bdd/tasks/mariadb.yml delete mode 100644 ppebase/roles/tomcat/defaults/main.yml.sv1 delete mode 100644 ppebase/roles/tomcat/tasks/main.yml.sv1 delete mode 100644 ppebase/roles/tomcat/tasks/main.yml.sv2 delete mode 100644 ppebase/roles/tomcat/tasks/main.yml.sv3 diff --git a/ap34prod/hosts b/ap34prod/hosts new file mode 100644 index 0000000..8aff93e --- /dev/null +++ b/ap34prod/hosts @@ -0,0 +1,3 @@ +[local] +localhost +127.0.0.1 diff --git a/ppebase/tomcat-setup.yml b/ap34prod/ppebase.yml similarity index 97% rename from ppebase/tomcat-setup.yml rename to ap34prod/ppebase.yml index 52aaa99..a869d18 100644 --- a/ppebase/tomcat-setup.yml +++ b/ap34prod/ppebase.yml @@ -10,4 +10,4 @@ ui_admin_username: admin # User who can access bpth manager and admin UI sections ui_admin_pass: root # UI admin password roles: - - tomcat + - ppebase diff --git a/ap34prod/ppedb.yml b/ap34prod/ppedb.yml new file mode 100644 index 0000000..0d051f6 --- /dev/null +++ b/ap34prod/ppedb.yml @@ -0,0 +1,9 @@ +--- +- name: MariaDB deployment playbook + hosts: all + become: yes + become_method: sudo + remote_user: root + + roles: + - ppedb diff --git a/ppebase/roles/tomcat/defaults/main.yml b/ap34prod/roles/ppebase/defaults/main.yml similarity index 100% rename from ppebase/roles/tomcat/defaults/main.yml rename to ap34prod/roles/ppebase/defaults/main.yml diff --git a/ppebase/roles/tomcat/handlers/main.yml b/ap34prod/roles/ppebase/handlers/main.yml similarity index 100% rename from ppebase/roles/tomcat/handlers/main.yml rename to ap34prod/roles/ppebase/handlers/main.yml diff --git a/ppebase/roles/tomcat/tasks/main.yml b/ap34prod/roles/ppebase/tasks/main.yml similarity index 84% rename from ppebase/roles/tomcat/tasks/main.yml rename to ap34prod/roles/ppebase/tasks/main.yml index aa09550..24cd880 100644 --- a/ppebase/roles/tomcat/tasks/main.yml +++ b/ap34prod/roles/ppebase/tasks/main.yml @@ -72,3 +72,25 @@ - name: Redemarrer le service tomcat (3) local_action: command sh /usr/share/tomcat/apache-tomcat-10.0.13/bin/catalina.sh start + + - name: on installe java + apt: + name: default-jdk + state: present + + - name: on installe les paquets de MariaDB + apt: + name: mariadb-server + state: latest + update_cache: yes + + - name: on installe Python3 + apt: + name: python3-pymysql + state: latest + + - name: on lance MariaDB + service: + name: mysql + state: started + diff --git a/ppebase/roles/tomcat/templates/context.xml.j2 b/ap34prod/roles/ppebase/templates/context.xml.j2 similarity index 100% rename from ppebase/roles/tomcat/templates/context.xml.j2 rename to ap34prod/roles/ppebase/templates/context.xml.j2 diff --git a/ppebase/roles/tomcat/templates/tomcat-users.xml.j2 b/ap34prod/roles/ppebase/templates/tomcat-users.xml.j2 similarity index 100% rename from ppebase/roles/tomcat/templates/tomcat-users.xml.j2 rename to ap34prod/roles/ppebase/templates/tomcat-users.xml.j2 diff --git a/ppebase/roles/tomcat/templates/tomcat.service.j2 b/ap34prod/roles/ppebase/templates/tomcat.service.j2 similarity index 100% rename from ppebase/roles/tomcat/templates/tomcat.service.j2 rename to ap34prod/roles/ppebase/templates/tomcat.service.j2 diff --git a/ppebase/roles/tomcat/vars/main.yml b/ap34prod/roles/ppebase/vars/main.yml similarity index 100% rename from ppebase/roles/tomcat/vars/main.yml rename to ap34prod/roles/ppebase/vars/main.yml diff --git a/ap34prod/roles/ppedb/tasks/main.yml b/ap34prod/roles/ppedb/tasks/main.yml new file mode 100755 index 0000000..ec62b5d --- /dev/null +++ b/ap34prod/roles/ppedb/tasks/main.yml @@ -0,0 +1,20 @@ +- name: on lance MariaDB + service: + name: mysql + state: started + +- name: creation de la BDD sdis29 + mysql_db: + login_unix_socket: /var/run/mysqld/mysqld.sock + name: sdis29 + #login_user: adminBDsdis + #login_password: mdpBDsdis + #login_host: localhost + +- name: creation de l'utilisateur slam + mysql_user: + name: slam + password: Azerty1+ + priv: '*.*:ALL,GRANT' + state: present + login_unix_socket: /var/run/mysqld/mysqld.sock diff --git a/ppebase/roles/bdddump/tasks/createdump.yml b/ap34prod/roles/svbdd/tasks/createdump.yml similarity index 100% rename from ppebase/roles/bdddump/tasks/createdump.yml rename to ap34prod/roles/svbdd/tasks/createdump.yml diff --git a/ppebase/exans.yml b/ppebase/exans.yml deleted file mode 100644 index 9f2fb25..0000000 --- a/ppebase/exans.yml +++ /dev/null @@ -1,4 +0,0 @@ ---- -- hosts: all - roles: - - bdd diff --git a/ppebase/hosts b/ppebase/hosts deleted file mode 100644 index 9672f3b..0000000 --- a/ppebase/hosts +++ /dev/null @@ -1 +0,0 @@ -[localhost] diff --git a/ppebase/invent.txt b/ppebase/invent.txt deleted file mode 100644 index 2fbb50c..0000000 --- a/ppebase/invent.txt +++ /dev/null @@ -1 +0,0 @@ -localhost diff --git a/ppebase/roles/bdd/tasks/mariadb.yml b/ppebase/roles/bdd/tasks/mariadb.yml deleted file mode 100755 index 277df1d..0000000 --- a/ppebase/roles/bdd/tasks/mariadb.yml +++ /dev/null @@ -1,39 +0,0 @@ - - name: update - apt: - update_cache: yes - ignore_errors: yes - - - name: installer MariaDB Serveur - apt: - name: mariadb-server - state: latest - - - name: installer mariadbclient - apt: - name: mariadb-client - state: latest - - - name: installer python - apt: - name: python - state: latest - - - name: demarrer mysql - service: - name: mysqld - state: started - enabled: yes - - - name: creer la bdd - community.mysql.mysql_db: - name: - - sdis29 - state: present - - - name: creer l'utilisateur - mysql_user: - name: slam - password: Azerty1+ - priv: *.*:ALL - host: 127.0.0.1 - become: yes diff --git a/ppebase/roles/tomcat/defaults/main.yml.sv1 b/ppebase/roles/tomcat/defaults/main.yml.sv1 deleted file mode 100644 index ecea063..0000000 --- a/ppebase/roles/tomcat/defaults/main.yml.sv1 +++ /dev/null @@ -1,2 +0,0 @@ -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/tasks/main.yml.sv1 b/ppebase/roles/tomcat/tasks/main.yml.sv1 deleted file mode 100644 index 9522ca8..0000000 --- a/ppebase/roles/tomcat/tasks/main.yml.sv1 +++ /dev/null @@ -1,100 +0,0 @@ - - name: on s'assure que le systeme supporte l'https - stat: - path: /usr/lib/apt/methods/https - register: apt_https_transport - - - name: installer apt https transport - apt: - name: "apt-transport-https" - state: present - update_cache: yes - when: not apt_https_transport.stat.exists - - - 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: /opt/tomcat - state: directory - mode: 0755 - - - name: creer le groupe tomcat - group: - name: tomcat - - - name: creer l'utilisateur tomcat - user: - name: tomcat - group: tomcat - home: /user/share/tomcat - createhome: no - - - name: installer TomCat - unarchive: - src: http://depl/store/apache-tomcat-10.0.13.tar.gz - dest: /opt/tomcat - remote_src: yes - - - name: Change ownership - file: - path: /opt/tomcat - owner: tomcat - group: tomcat - mode: "u+rwx,g+rx,o=rx" - recurse: yes - state: directory - - - name: Create a tomcat directory - file: - path: /usr/share/tomcat - state: directory - owner: tomcat - group: tomcat - - - name: Extract tomcat archive - unarchive: - src: /opt/tomcat/apache-tomcat-10.0.13.tar.gz - dest: /usr/share/tomcat - owner: tomcat - group: tomcat - remote_src: yes - extra_opts: "--strip-components=1" - creates: /usr/share/tomcat/bin - - - name: Copy Tomcat service from local to remote - copy: - src: tomcat.service.j2 - dest: /etc/systemd/system/ - mode: 0755 - - - name: demarrer le service TomCat - systemd: - name: tomcat - state: started - enabled: true - daemon_reload: yes - - - 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/ppebase/roles/tomcat/tasks/main.yml.sv2 b/ppebase/roles/tomcat/tasks/main.yml.sv2 deleted file mode 100644 index aa7853b..0000000 --- a/ppebase/roles/tomcat/tasks/main.yml.sv2 +++ /dev/null @@ -1,68 +0,0 @@ - - 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: /opt/tomcat - state: directory - mode: 0755 - - - name: creer le groupe tomcat - group: - name: tomcat - - - name: creer l'utilisateur tomcat - user: - name: tomcat - group: tomcat - home: /user/share/tomcat - createhome: no - - - name: installer TomCat - unarchive: - src: http://depl/store/apache-tomcat-10.0.13.tar.gz - dest: /opt/tomcat - remote_src: yes - - - name: Change ownership - file: - path: /opt/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/ - mode: 0755 - - - name: VRRR demarrer le service tomcat - local_action: command sh /opt/tomcat/apache-tomcat-10.0.13/bin/startup.sh - - - - name: Set UI access credentials - template: - src: tomcat-users.xml.j2 - dest: 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: - - /opt/tomcat/webapps/host-manager/META-INF/context.xml - - /opt/tomcat/webapps/manager/META-INF/context.xml - notify: restart tomcat - diff --git a/ppebase/roles/tomcat/tasks/main.yml.sv3 b/ppebase/roles/tomcat/tasks/main.yml.sv3 deleted file mode 100644 index 1fc6574..0000000 --- a/ppebase/roles/tomcat/tasks/main.yml.sv3 +++ /dev/null @@ -1,76 +0,0 @@ - - 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: /opt/tomcat - state: directory - mode: 0755 - - - name: creer le groupe tomcat - group: - name: tomcat - - - name: creer l'utilisateur tomcat - user: - name: tomcat - group: tomcat - home: /user/share/tomcat - createhome: no - - - name: installer TomCat - unarchive: - src: http://depl/store/apache-tomcat-10.0.13.tar.gz - dest: /opt/tomcat - remote_src: yes - - - name: Change ownership - file: - path: /opt/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: 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 - - - - name: Set UI access credentials - template: - src: tomcat-users.xml.j2 - dest: tomcat-users.xml - notify: restart tomcat - - - name: Allow access to Manager and Host Manager apps from any IP - template: - 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 - - - name: Redemarrer le service tomcat (2) - local_action: command sh /opt/tomcat/apache-tomcat-10.0.13/bin/startup.sh