inisital commit

This commit is contained in:
Olivier Barais
2021-12-02 11:43:36 +01:00
parent dd84b7dcab
commit 8545eb3d66
25 changed files with 515 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
<VirtualHost *:{{ http_port }}>
ServerAdmin webmaster@localhost
ServerName {{ http_host }}
ServerAlias www.{{ http_host }}
DocumentRoot /var/www/{{ http_host }}
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/{{ http_host }}>
Options -Indexes
</Directory>
<IfModule mod_dir.c>
DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
</IfModule>
</VirtualHost>

View File

@@ -0,0 +1,2 @@
<?php
phpinfo();

View File

@@ -0,0 +1,7 @@
[webservers]
192.168.56.141 ansible_ssh_user=vagrant ansible_become_pass=vagrant ansible_python_interpreter=/usr/bin/python3
[webservers:vars]
ansible_connection=ssh
ansible_ssh_user=vagrant
ansible_ssh_pass=vagrant

View File

@@ -0,0 +1,94 @@
##################################################
# DO Community Playbooks: LAMP on Ubuntu 18.04
##################################################
---
- hosts: all
become: true
vars_files:
- vars/default.yml
tasks:
- name: Install prerequisites
apt:
name: 'aptitude'
update_cache: true
#Apache Configuration
- name: Install LAMP Packages
apt:
name: [ 'apache2', 'python3-pip', 'mysql-server', 'php', 'php-mysql', 'libapache2-mod-php' ]
state: present
- name: Make sure pymysql is present
become: true # needed if the other tasks are not played as root
pip:
name: pymysql
state: present
- name: Create document root
file:
path: "/var/www/{{ http_host }}"
state: directory
owner: "{{ app_user }}"
mode: '0755'
- name: Set up Apache virtualhost
template:
src: "files/apache.conf.j2"
dest: "/etc/apache2/sites-available/{{ http_conf }}"
notify: Reload Apache
- name: Enable new site
shell: /usr/sbin/a2ensite {{ http_conf }}
notify: Reload Apache
- name: Disable default Apache site
shell: /usr/sbin/a2dissite 000-default.conf
when: disable_default
notify: Reload Apache
# MySQL Configuration
- name: Sets the root password
mysql_user:
name: root
password: "{{ mysql_root_password }}"
login_unix_socket: /var/run/mysqld/mysqld.sock
- name: Removes all anonymous user accounts
mysql_user:
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 }}"
# UFW Configuration
- name: "UFW - Allow HTTP on port {{ http_port }}"
ufw:
rule: allow
port: "{{ http_port }}"
proto: tcp
# PHP Info Page
- name: Sets Up PHP Info Page
template:
src: "files/info.php.j2"
dest: "/var/www/{{ http_host }}/info.php"
handlers:
- name: Reload Apache
service:
name: apache2
state: reloaded
- name: Restart Apache
service:
name: apache2
state: restarted

View File

@@ -0,0 +1,47 @@
# LAMP on Ubuntu 18.04
This playbook will install a LAMP environment (**L**inux, **A**pache, **M**ySQL and **P**HP) on an Ubuntu 18.04 machine, as explained in the guide on [How to Use Ansible to Install and Configure LAMP on Ubuntu 18.04](#). A virtualhost will be created with the options specified in the `vars/default.yml` variable file.
## Settings
- `mysql_root_password`: the password for the MySQL root account.
- `app_user`: a remote non-root user on the Ansible host that will own the application files.
- `http_host`: your domain name.
- `http_conf`: the name of the configuration file that will be created within Apache.
- `http_port`: HTTP port, default is 80.
- `disable_default`: whether or not to disable the default Apache website. When set to true, your new virtualhost should be used as default website. Default is true.
## Running this Playbook
Quickstart guide for those already familiar with Ansible:
### 1. Obtain the playbook
```shell
git clone https://github.com/do-community/ansible-playbooks.git
cd ansible-playbooks/lamp_ubuntu1804
```
### 2. Customize Options
```shell
nano vars/default.yml
```
```yml
---
mysql_root_password: "mysql_root_password"
app_user: "sammy"
http_host: "your_domain"
http_conf: "your_domain.conf"
http_port: "80"
disable_default: true
```
### 3. Run the Playbook
```command
ansible-playbook -l [target] -i [inventory file] -u [remote user] playbook.yml
```
For more information on how to run this Ansible setup, please check this guide: [soon]().

View File

@@ -0,0 +1,7 @@
---
mysql_root_password: "mysql_root_password"
app_user: "vagrant"
http_host: "demotlc"
http_conf: "demotlc.conf"
http_port: "80"
disable_default: true