From 8fd34d019f1097896fec2f514144c5add1bc53c9 Mon Sep 17 00:00:00 2001 From: Will Bradley Date: Thu, 26 Sep 2013 03:46:10 -0700 Subject: [PATCH] Initial commit --- create-user.yml | 62 +++++++++++++++++++ run-local-all | 4 ++ settings.yml | 7 +++ .../etc-apache2-sites-available-username.j2 | 8 +++ 4 files changed, 81 insertions(+) create mode 100644 create-user.yml create mode 100755 run-local-all create mode 100644 settings.yml create mode 100644 templates/etc-apache2-sites-available-username.j2 diff --git a/create-user.yml b/create-user.yml new file mode 100644 index 0000000..be6008b --- /dev/null +++ b/create-user.yml @@ -0,0 +1,62 @@ +## +# Ansible playbook for creating a new user with their own mysql db and apache site +# + +--- +- hosts: all + user: root + + vars_files: + - settings.yml + + vars_prompt: + - name: "domain_name" + prompt: "Domain Name" + private: no + + - name: "username" + prompt: "Username" + private: no + + - name: "user_fullname" + prompt: "Full Name" + private: no + + - name: "user_password" + prompt: "Password" + private: yes + encrypt: "sha512_crypt" + salt_size: 8 + + - name: "mysql_password" + prompt: "MySQL Password" + private: yes + + tasks: + ## + # Apt package installation of required software. + # + - name: Linux | Create User + user: name=$username comment="$user_fullname" password=$user_password shell="/bin/bash" + tags: common + + - name: MySQL | Create Database + mysql_db: name="$username" + tags: mysql + + - name: MySQL | Create User with host localhost and privs on own DB + mysql_user: user="$username" password="$mysql_password" host="localhost" priv="$username.*:ALL" + tags: mysql + + - name: Apache | Create virtual host site + action: template src=templates/etc-apache2-sites-available-username.j2 dest=/etc/apache2/sites-available/{{ username }} + tags: apache + + - name: Apache | Create document root + file: path=/home/$username/public_html owner=$username group=$username mode=0644 state=directory + tags: apache + + - name: Apache | Enable site + action: command a2ensite {{ username }} + tags: apache + diff --git a/run-local-all b/run-local-all new file mode 100755 index 0000000..734238e --- /dev/null +++ b/run-local-all @@ -0,0 +1,4 @@ +#!/bin/sh + +# Script for running the play on the localhost, everything included. +ansible-playbook -c local --tags="common,mysql,apache" ./create-user.yml diff --git a/settings.yml b/settings.yml new file mode 100644 index 0000000..d63ca82 --- /dev/null +++ b/settings.yml @@ -0,0 +1,7 @@ +# Settings that are applied to the templates. This file should be copied to +# the base folder of the play and renamed settings.yml, then modified to suit +# your needs. + +# apache +apache_server_admin: 'webmaster@testa.hsl.dn42' + diff --git a/templates/etc-apache2-sites-available-username.j2 b/templates/etc-apache2-sites-available-username.j2 new file mode 100644 index 0000000..d5e7e42 --- /dev/null +++ b/templates/etc-apache2-sites-available-username.j2 @@ -0,0 +1,8 @@ +## +# Ansible provided setup. See https://github.com/fourkitchens/server-playbooks. +## + + ServerAdmin {{ apache_server_admin }} + ServerName {{ domain_name }} + DocumentRoot /home/{{ username }}/public_html +