Feat: maj du deploiement (testé)

This commit is contained in:
Bertrand Benjamin 2022-09-06 19:53:17 +02:00
parent 211b7d5725
commit b365759be6
11 changed files with 130 additions and 59 deletions

View File

@ -1 +1,14 @@
<h1> Serveur pédagogique pour {{ item.name }} </h1> <!DOCTYPE html>
<html lang=fr>
<head>
<meta charset="UTF-8">
<meta name="Author" content="B.Bertrand">
<title>{{ item }}</title>
</head>
<body>
<h1> Serveur pédagogique pour {{ item }} </h1>
<!-- corps: tout ce que l'on veut afficher doit être mis entre ces balises -->
</body>
</html>

22
files/root_index.html.j2 Normal file
View File

@ -0,0 +1,22 @@
<!DOCTYPE html>
<html lang=fr>
<head>
<meta charset="UTF-8">
<meta name="Author" content="B.Bertrand">
<title>{{ item }}</title>
</head>
<body>
<h1> Serveur pédagogique pour {{ matiere }} </h1>
<!-- corps: tout ce que l'on veut afficher doit être mis entre ces balises -->
<ul>
{% for user in peda %}
<li>
<a href="./~{{ user }}">{{ user }}</a>
</li>
{% endfor%}
</ul>
</body>
</html>

5
home Normal file
View File

@ -0,0 +1,5 @@
[nsi]
192.168.2.146 ansible_user=debian
[snt]
ansible ansible_user=debian

2
hosts
View File

@ -1,2 +0,0 @@
[all]
stex.ovh ansible_port=25022 ansible_user=root

View File

@ -7,7 +7,7 @@
- vars/accounts.yml - vars/accounts.yml
tasks: tasks:
- include: tasks/lamp.yml #- include: tasks/lamp.yml
- include: tasks/accounts.yml - include: tasks/accounts.yml
handlers: handlers:

5
lycee Normal file
View File

@ -0,0 +1,5 @@
[stex]
stex.ovh ansible_port=25022 ansible_user=root
[home]
192.168.2.146 ansible_user=debian

28
lycee.yml Normal file
View File

@ -0,0 +1,28 @@
---
- hosts: snt
#ask_pass: true
become: true
vars_files:
- vars/default.yml
- vars/snt_accounts.yml
pre_tasks:
- name: Update
apt:
update_cache: true
upgrade: true
tasks:
- include: tasks/lamp.yml
- include: tasks/accounts.yml
handlers:
- name: Reload Apache
service:
name: apache2
state: reloaded
- name: Restart Apache
service:
name: apache2
state: restarted

View File

@ -1,17 +1,17 @@
--- ---
- name: add users - name: add users
user: user:
name: "{{ item.name }}" name: "{{ item }}"
create_home: true create_home: true
password: "{{ lookup('password', './pass/' + item.name + '_pass length=10 chars=ascii_letters') | password_hash('sha512') }}" password: "{{ lookup('password', './pass/' + item + '_pass length=10 chars=ascii_letters') | password_hash('sha512') }}"
update_password: on_create update_password: on_create
with_items: "{{ users }}" with_items: "{{ users }}"
register: returned register: returned
- name: create public_html - name: create public_html
file: file:
path: "/home/{{ item.name}}/public_html/" path: "/home/{{ item}}/public_html/"
owner: "{{ item.name }}" owner: "{{ item }}"
group: www-data group: www-data
state: directory state: directory
with_items: "{{ users }}" with_items: "{{ users }}"
@ -19,13 +19,13 @@
- name: Sets Up Index page - name: Sets Up Index page
template: template:
src: "files/index.html.j2" src: "files/index.html.j2"
dest: "/home/{{ item.name }}/public_html/index.html" dest: "/home/{{ item }}/public_html/index.html"
mode: 774 mode: 774
with_items: "{{ users }}" with_items: "{{ users }}"
- name: create database - name: create database
mysql_db: mysql_db:
db: "{{ item.name }}" db: "{{ item }}"
state: present state: present
login_user: root login_user: root
login_password: "{{ mysql_root_password }}" login_password: "{{ mysql_root_password }}"
@ -33,9 +33,9 @@
- name: create db user - name: create db user
mysql_user: mysql_user:
user: "{{ item.name }}" user: "{{ item }}"
password: "{{ lookup('password', './pass/' + item.name + '_sql length=10 chars=ascii_letters') | password_hash('sha512') }}" password: "{{ lookup('password', './pass/' + item + '_sql length=10 chars=ascii_letters') | password_hash('sha512') }}"
priv: "{{ item.name + '.*:ALL,GRANT' }}" priv: "{{ item + '.*:ALL,GRANT' }}"
login_user: root login_user: root
login_password: "{{ mysql_root_password }}" login_password: "{{ mysql_root_password }}"
state: present state: present

View File

@ -1,12 +1,14 @@
--- ---
- name: Install prerequisites
apt: name={{ item }} update_cache=yes state=latest force_apt_get=yes
loop: [ 'aptitude' ]
#Apache Configuration #Apache Configuration
- name: Install LAMP Packages - name: Install LAMP Packages
apt: name={{ item }} update_cache=yes state=latest apt: name={{ item }} update_cache=yes state=latest
loop: [ 'apache2', 'mysql-server', 'python3-pymysql', 'php', 'php-mysql', 'libapache2-mod-php' ] loop:
- 'apache2'
- 'mariadb-server'
- 'python3-pymysql'
- 'php'
- 'php-mysql'
- 'libapache2-mod-php'
- name: Create document root - name: Create document root
file: file:
@ -30,12 +32,18 @@
when: disable_default when: disable_default
notify: Reload Apache notify: Reload Apache
# MySQL Configuration # MySQL Configuration
- name: Start MariaDB service
service:
name: mariadb
state: started
- name: Sets the root password - name: Sets the root password
mysql_user: mysql_user:
name: root name: root
password: "{{ mysql_root_password }}" password: "{{ mysql_root_password }}"
login_unix_socket: /var/run/mysqld/mysqld.sock login_unix_socket: /var/run/mysqld/mysqld.sock
ignore_errors: yes
- name: Removes all anonymous user accounts - name: Removes all anonymous user accounts
mysql_user: mysql_user:
@ -52,12 +60,6 @@
login_user: root login_user: root
login_password: "{{ mysql_root_password }}" login_password: "{{ mysql_root_password }}"
- name: "UFW - Allow HTTP on port {{ http_port }}"
ufw:
rule: allow
port: "{{ http_port }}"
proto: tcp
- name: Sets Up PHP Info Page - name: Sets Up PHP Info Page
template: template:
src: "files/info.php.j2" src: "files/info.php.j2"
@ -65,11 +67,11 @@
- name: Sets Up Index page - name: Sets Up Index page
template: template:
src: "files/index.html.j2" src: "files/root_index.html.j2"
dest: "/var/www/{{ http_host }}/index.html" dest: "/var/www/{{ http_host }}/index.html"
vars: vars:
item: item:
name: "la SNT" - "{{ matiere }}"
- name: Enable userdir - name: Enable userdir
shell: /usr/sbin/a2enmod userdir shell: /usr/sbin/a2enmod userdir

View File

@ -1,20 +1,4 @@
--- ---
#tribes:
# - "2GT1G1"
# - "2GT1G2"
# - "2GT2G1"
# - "2GT2G2"
# - "2GT3G1"
# - "2GT3G2"
# - "2GT4G1"
# - "2GT4G2"
# - "2GT5G1"
# - "2GT5G2"
# - "2GT6G1"
# - "2GT6G2"
#profs:
# - "proftest"
#users: tribes + profs
users: users:
- name: test1 - name: test1
- name: test2 - name: test2

14
vars/snt_accounts.yml Normal file
View File

@ -0,0 +1,14 @@
---
matiere: "SNT"
peda:
- "2GTG1"
- "2GTG2"
- "2GTG3"
- "2GTG4"
- "2GTG5"
- "2GTG6"
- "2GTG8"
- "2GTG9"
profs:
- "proftest"
users: "{{ peda + profs }}"