From d8b0c86d3d41c3886434f03487e15c05fb0a9746 Mon Sep 17 00:00:00 2001 From: Bertrand Benjamin Date: Wed, 23 Sep 2020 22:38:15 +0200 Subject: [PATCH 1/3] Fix: good dest for root_index --- tasks/lamp.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/lamp.yml b/tasks/lamp.yml index fca35bc..469b0a2 100644 --- a/tasks/lamp.yml +++ b/tasks/lamp.yml @@ -66,7 +66,7 @@ - name: Sets Up Index page template: src: "files/index.html.j2" - dest: "/var/www/{{ http_host }}/info.php" + dest: "/var/www/{{ http_host }}/index.html" vars: name: "la SNT" From 67626a455bce6dc2b78433ee593280558ab2caba Mon Sep 17 00:00:00 2001 From: Bertrand Benjamin Date: Wed, 23 Sep 2020 23:04:15 +0200 Subject: [PATCH 2/3] Feat: account creation! --- files/index.html.j2 | 2 +- hosts | 2 ++ localhost.yml | 4 ++-- tasks/accounts.yml | 23 +++++++++++++++++++++++ tasks/lamp.yml | 3 ++- vars/accounts.yml | 3 +++ 6 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 hosts diff --git a/files/index.html.j2 b/files/index.html.j2 index 2d8bda9..52b3878 100644 --- a/files/index.html.j2 +++ b/files/index.html.j2 @@ -1 +1 @@ -

Serveur pédagogique pour {{ name }}

+

Serveur pédagogique pour {{ item.name }}

diff --git a/hosts b/hosts new file mode 100644 index 0000000..209f792 --- /dev/null +++ b/hosts @@ -0,0 +1,2 @@ +[all] +stex.ovh ansible_port=25022 ansible_user=root diff --git a/localhost.yml b/localhost.yml index 6fbaba4..7b07134 100644 --- a/localhost.yml +++ b/localhost.yml @@ -1,6 +1,6 @@ --- -- hosts: 127.0.0.1 - connection: local +- hosts: all + #ask_pass: true become: true vars_files: - vars/default.yml diff --git a/tasks/accounts.yml b/tasks/accounts.yml index ed97d53..39ff574 100644 --- a/tasks/accounts.yml +++ b/tasks/accounts.yml @@ -1 +1,24 @@ --- +- name: add users + user: + name: "{{ item.name }}" + create_home: true + password: "{{ lookup('password', './pass/' + item.name + '_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 }}" + group: www-data + state: directory + with_items: "{{ users }}" + +- name: Sets Up Index page + template: + src: "files/index.html.j2" + dest: "/home/{{ item.name }}/public_html/index.html" + mode: 774 + with_items: "{{ users }}" diff --git a/tasks/lamp.yml b/tasks/lamp.yml index 469b0a2..8594bff 100644 --- a/tasks/lamp.yml +++ b/tasks/lamp.yml @@ -68,7 +68,8 @@ src: "files/index.html.j2" dest: "/var/www/{{ http_host }}/index.html" vars: - name: "la SNT" + item: + name: "la SNT" - name: Enable userdir shell: /usr/sbin/a2enmod userdir diff --git a/vars/accounts.yml b/vars/accounts.yml index ed97d53..178ad57 100644 --- a/vars/accounts.yml +++ b/vars/accounts.yml @@ -1 +1,4 @@ --- +users: + - name: test1 + - name: test2 From d91a5e97fd7c1d50dc5a2972f09967bba6f9b520 Mon Sep 17 00:00:00 2001 From: Bertrand Benjamin Date: Fri, 25 Sep 2020 07:02:45 +0200 Subject: [PATCH 3/3] Feat: mysql user creation done --- tasks/accounts.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tasks/accounts.yml b/tasks/accounts.yml index 39ff574..db5b7b5 100644 --- a/tasks/accounts.yml +++ b/tasks/accounts.yml @@ -22,3 +22,21 @@ dest: "/home/{{ item.name }}/public_html/index.html" mode: 774 with_items: "{{ users }}" + +- name: create database + mysql_db: + db: "{{ item.name }}" + state: present + login_user: root + login_password: "{{ mysql_root_password }}" + with_items: "{{ users }}" + +- 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' }}" + login_user: root + login_password: "{{ mysql_root_password }}" + state: present + with_items: "{{ users }}"