commit 7245b12f86876d65b7c9546f1f62406920b2de7f Author: Bertrand Benjamin Date: Fri Sep 18 15:01:27 2020 +0200 First commit diff --git a/files/apache.conf.j2 b/files/apache.conf.j2 new file mode 100644 index 0000000..47c9cbe --- /dev/null +++ b/files/apache.conf.j2 @@ -0,0 +1,17 @@ + + 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 + + + Options -Indexes + + + + DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm + + + diff --git a/files/info.php.j2 b/files/info.php.j2 new file mode 100644 index 0000000..fc5863b --- /dev/null +++ b/files/info.php.j2 @@ -0,0 +1 @@ + diff --git a/localhost.yml b/localhost.yml new file mode 100644 index 0000000..e69de29 diff --git a/tasks/lamp.yml b/tasks/lamp.yml new file mode 100644 index 0000000..6fdf9f1 --- /dev/null +++ b/tasks/lamp.yml @@ -0,0 +1,77 @@ +--- +- name: Install prerequisites + apt: name={{ item }} update_cache=yes state=latest force_apt_get=yes + loop: [ 'aptitude' ] + + #Apache Configuration +- name: Install LAMP Packages + apt: name={{ item }} update_cache=yes state=latest + loop: [ 'apache2', 'mysql-server', 'python3-pymysql', 'php', 'php-mysql', 'libapache2-mod-php' ] + +- 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