diff --git a/files/index.html.j2 b/files/index.html.j2
index 52b3878..066cecf 100644
--- a/files/index.html.j2
+++ b/files/index.html.j2
@@ -1 +1,14 @@
-
Serveur pédagogique pour {{ item.name }}
+
+
+
+
+
+ {{ item }}
+
+
+
+ Serveur pédagogique pour {{ item }}
+
+
+
+
diff --git a/files/root_index.html.j2 b/files/root_index.html.j2
new file mode 100644
index 0000000..f11b1b3
--- /dev/null
+++ b/files/root_index.html.j2
@@ -0,0 +1,22 @@
+
+
+
+
+
+ {{ item }}
+
+
+
+ Serveur pédagogique pour {{ matiere }}
+
+
+
+ {% for user in peda %}
+ -
+ {{ user }}
+
+ {% endfor%}
+
+
+
+
diff --git a/home b/home
new file mode 100644
index 0000000..234101e
--- /dev/null
+++ b/home
@@ -0,0 +1,5 @@
+[nsi]
+192.168.2.146 ansible_user=debian
+
+[snt]
+ansible ansible_user=debian
diff --git a/hosts b/hosts
deleted file mode 100644
index 209f792..0000000
--- a/hosts
+++ /dev/null
@@ -1,2 +0,0 @@
-[all]
-stex.ovh ansible_port=25022 ansible_user=root
diff --git a/localhost.yml b/localhost.yml
index 7b07134..5cfa796 100644
--- a/localhost.yml
+++ b/localhost.yml
@@ -7,7 +7,7 @@
- vars/accounts.yml
tasks:
- - include: tasks/lamp.yml
+ #- include: tasks/lamp.yml
- include: tasks/accounts.yml
handlers:
diff --git a/lycee b/lycee
new file mode 100644
index 0000000..1a5b937
--- /dev/null
+++ b/lycee
@@ -0,0 +1,5 @@
+[stex]
+stex.ovh ansible_port=25022 ansible_user=root
+
+[home]
+192.168.2.146 ansible_user=debian
diff --git a/lycee.yml b/lycee.yml
new file mode 100644
index 0000000..ee6141b
--- /dev/null
+++ b/lycee.yml
@@ -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
diff --git a/tasks/accounts.yml b/tasks/accounts.yml
index db5b7b5..cb412db 100644
--- a/tasks/accounts.yml
+++ b/tasks/accounts.yml
@@ -1,17 +1,17 @@
---
- name: add users
user:
- name: "{{ item.name }}"
+ name: "{{ item }}"
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
with_items: "{{ users }}"
register: returned
- name: create public_html
file:
- path: "/home/{{ item.name}}/public_html/"
- owner: "{{ item.name }}"
+ path: "/home/{{ item}}/public_html/"
+ owner: "{{ item }}"
group: www-data
state: directory
with_items: "{{ users }}"
@@ -19,13 +19,13 @@
- name: Sets Up Index page
template:
src: "files/index.html.j2"
- dest: "/home/{{ item.name }}/public_html/index.html"
+ dest: "/home/{{ item }}/public_html/index.html"
mode: 774
with_items: "{{ users }}"
- name: create database
mysql_db:
- db: "{{ item.name }}"
+ db: "{{ item }}"
state: present
login_user: root
login_password: "{{ mysql_root_password }}"
@@ -33,9 +33,9 @@
- name: create db user
mysql_user:
- user: "{{ item.name }}"
- password: "{{ lookup('password', './pass/' + item.name + '_sql length=10 chars=ascii_letters') | password_hash('sha512') }}"
- priv: "{{ item.name + '.*:ALL,GRANT' }}"
+ user: "{{ item }}"
+ password: "{{ lookup('password', './pass/' + item + '_sql length=10 chars=ascii_letters') | password_hash('sha512') }}"
+ priv: "{{ item + '.*:ALL,GRANT' }}"
login_user: root
login_password: "{{ mysql_root_password }}"
state: present
diff --git a/tasks/lamp.yml b/tasks/lamp.yml
index 8594bff..b0deef7 100644
--- a/tasks/lamp.yml
+++ b/tasks/lamp.yml
@@ -1,12 +1,14 @@
---
-- name: Install prerequisites
- apt: name={{ item }} update_cache=yes state=latest force_apt_get=yes
- loop: [ 'aptitude' ]
-
#Apache Configuration
- name: Install LAMP Packages
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
file:
@@ -30,46 +32,46 @@
when: disable_default
notify: Reload Apache
- # MySQL Configuration
+# MySQL Configuration
+- name: Start MariaDB service
+ service:
+ name: mariadb
+ state: started
+
- name: Sets the root password
mysql_user:
- name: root
- password: "{{ mysql_root_password }}"
- login_unix_socket: /var/run/mysqld/mysqld.sock
+ name: root
+ password: "{{ mysql_root_password }}"
+ login_unix_socket: /var/run/mysqld/mysqld.sock
+ ignore_errors: yes
- name: Removes all anonymous user accounts
mysql_user:
- name: ''
- host_all: yes
- state: absent
- login_user: root
- login_password: "{{ mysql_root_password }}"
+ name: ''
+ host_all: yes
+ state: absent
+ login_user: root
+ login_password: "{{ mysql_root_password }}"
- name: Removes the MySQL test database
mysql_db:
- name: test
- state: absent
- login_user: root
- login_password: "{{ mysql_root_password }}"
-
-- name: "UFW - Allow HTTP on port {{ http_port }}"
- ufw:
- rule: allow
- port: "{{ http_port }}"
- proto: tcp
+ name: test
+ state: absent
+ login_user: root
+ login_password: "{{ mysql_root_password }}"
- name: Sets Up PHP Info Page
template:
- src: "files/info.php.j2"
- dest: "/var/www/{{ http_host }}/info.php"
+ src: "files/info.php.j2"
+ dest: "/var/www/{{ http_host }}/info.php"
- name: Sets Up Index page
template:
- src: "files/index.html.j2"
- dest: "/var/www/{{ http_host }}/index.html"
+ src: "files/root_index.html.j2"
+ dest: "/var/www/{{ http_host }}/index.html"
vars:
- item:
- name: "la SNT"
+ item:
+ - "{{ matiere }}"
- name: Enable userdir
shell: /usr/sbin/a2enmod userdir
diff --git a/vars/accounts.yml b/vars/accounts.yml
index 39354ea..178ad57 100644
--- a/vars/accounts.yml
+++ b/vars/accounts.yml
@@ -1,20 +1,4 @@
---
-#tribes:
-# - "2GT1G1"
-# - "2GT1G2"
-# - "2GT2G1"
-# - "2GT2G2"
-# - "2GT3G1"
-# - "2GT3G2"
-# - "2GT4G1"
-# - "2GT4G2"
-# - "2GT5G1"
-# - "2GT5G2"
-# - "2GT6G1"
-# - "2GT6G2"
-#profs:
-# - "proftest"
-#users: tribes + profs
users:
- name: test1
- name: test2
diff --git a/vars/snt_accounts.yml b/vars/snt_accounts.yml
new file mode 100644
index 0000000..70388da
--- /dev/null
+++ b/vars/snt_accounts.yml
@@ -0,0 +1,14 @@
+---
+matiere: "SNT"
+peda:
+ - "2GTG1"
+ - "2GTG2"
+ - "2GTG3"
+ - "2GTG4"
+ - "2GTG5"
+ - "2GTG6"
+ - "2GTG8"
+ - "2GTG9"
+profs:
+ - "proftest"
+users: "{{ peda + profs }}"