From 67626a455bce6dc2b78433ee593280558ab2caba Mon Sep 17 00:00:00 2001 From: Bertrand Benjamin Date: Wed, 23 Sep 2020 23:04:15 +0200 Subject: [PATCH] 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