ansible-playbooks/create-user.yml

77 lines
2.0 KiB
YAML
Raw Normal View History

2013-09-26 10:46:10 +00:00
##
# 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"
2013-09-26 11:52:16 +00:00
private: no
2013-09-26 10:46:10 +00:00
encrypt: "sha512_crypt"
salt_size: 8
- name: "mysql_password"
prompt: "MySQL Password"
2013-09-26 11:52:16 +00:00
private: no
2013-09-26 10:46:10 +00:00
tasks:
- name: Linux | Create User
2014-02-06 22:28:39 +00:00
user: name=$username comment="$user_fullname" password=$user_password shell="/bin/bash" groups="www-data"
2013-09-26 10:46:10 +00:00
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
2013-09-26 11:52:16 +00:00
template: src=templates/etc-apache2-sites-available-username.j2 dest=/etc/apache2/sites-available/{{ username }}
2013-09-26 10:46:10 +00:00
tags: apache
- name: Apache | Create document root
2013-09-26 11:52:16 +00:00
file: path=/home/$username/public_html owner=$username group=$username mode=0755 state=directory
2013-09-26 10:46:10 +00:00
tags: apache
2013-09-26 12:04:21 +00:00
- name: Apache | Create index.html
template: src=templates/home-username-public_html-index.j2 dest=/home/$username/public_html/index.html
tags: file
2014-02-06 22:28:39 +00:00
# notes for creating wordpress site:
#cd /home/{username}/public_html
#sudo tar -xvf /home/wordpress-install.tgz
#sudo chown -R {username}:www-data .
#chmod -R 775 public_html
#echo "define('FS_CHMOD_DIR', (0775 & ~ umask()));
#define('FS_CHMOD_FILE', (0664 & ~ umask()));" >> wp-config.php
2013-09-26 10:46:10 +00:00
- name: Apache | Enable site
2013-09-26 11:52:16 +00:00
command: a2ensite {{ username }}
2013-09-26 10:46:10 +00:00
tags: apache
2013-09-26 11:52:16 +00:00
- name: Apache | Reload service
command: service apache2 reload
tags: apache