Skip to content

Commit

Permalink
creating roles properly for:
Browse files Browse the repository at this point in the history
- init
- httpd (apache 2.4.6)
- php (5.6.*)
- mysql (5.5.41)
- phpmyadmin (cloned latest from git repo)

- removed shell scripts & some cleanup

This is now fully working example!
skecskes committed Feb 19, 2015
1 parent 748f18d commit e2c06db
Showing 28 changed files with 171 additions and 157 deletions.
22 changes: 17 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
Vagrant Centos 7 lamp using Ansible playbook
=========================================

This personal development VM with Ansible provisioning is rather knowledge base. I created this VM in order to have a proper php testbed for my php applications. After vagrant up, the main url will welcome you with phpinfo(). I hope you will enjoy this VM and I always accept recommendations and requests.
This personal development VM with Ansible provisioning is **fully working example**. I created this VM in order to have a proper php testbed for my php applications. After vagrant up, the main url will welcome you with phpinfo(). I hope you will enjoy this VM and I always accept recommendations and requests.

## Guest OS

I am using CentOS 7 image from [somewhere](https://f0fff3908f081cb6461b407be80daf97f07ac418.googledrive.com/host/0BwtuV7VyVTSkUG1PM3pCeDJ4dVE/centos7.box) (thanks)
I am using CentOS 7 x64 image from [somewhere](https://f0fff3908f081cb6461b407be80daf97f07ac418.googledrive.com/host/0BwtuV7VyVTSkUG1PM3pCeDJ4dVE/centos7.box) (thanks)

## Prerequisites / Requirements

- virtualbox
- vagrant with guest additions (vagrant plugin install vagrant-vbguest)

## How to run

1. open terminal
2. $ *cd /var/www*
3. $ *mkdir project*
4. $ *cd project*
5. $ *git clone [email protected]:skecskes/vagrant-centos7-ansible-lamp.git*
6. $ *vagrant up*
7. Enjoy

Your /var/www/project folder will be synced with with vagrants apache root directory.

## Includes

- Apache 2.4.6
- php 5.6.5
- mySql MariaDB 5.5.41
- php 5.6.*
- mySql MariaDB 5.5.41 on port 3306
- phpinfo() on http://10.0.0.10
- phpmyadmin on http://10.0.0.10:9000
- phpmyadmin on http://10.0.0.10:9000 (latest version is cloned into vagrantbox)
7 changes: 3 additions & 4 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -18,13 +18,12 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
vb.customize ["modifyvm", :id, "--nictype1", "virtio"]
end

config.vm.provision :shell, path: "vagrant.sh"

config.vm.provision "ansible" do |ansible|
ansible.playbook = "playbook.yml"
ansible.playbook = "ansible/playbook.yml"
ansible.sudo = true
#ansible.inventory_path = "playbooks"
end
config.vm.provision :shell, path: "phpmyadmin.sh"

config.vm.provision :shell, inline: "echo Good job, now enjoy your new vbox: http://10.0.0.10"

end
10 changes: 10 additions & 0 deletions ansible/playbook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# file: roles/playbook.yml
---
- hosts: all

roles:
- init
- httpd
- php56
- mysql
- phpmyadmin
6 changes: 6 additions & 0 deletions ansible/roles/httpd/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# file: roles/httpd/defaults/main.yml
---

# used in apache vhost configuration files
doc_root: /var/www/html
hostname: vagrantbox
15 changes: 15 additions & 0 deletions ansible/roles/httpd/tasks/configure.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# file: roles/httpd/tasks/configure.yml

- name: Change default apache vhost
template: src=default.tpl dest=/etc/httpd/conf.d/000-default.conf

- name: Set global ServerName for apache config
lineinfile: dest=/etc/httpd/conf/httpd.conf line="ServerName localhost"

- name: SELinux to enforcing
command: /sbin/setenforce 0
notify:
- restart httpd

- name: Ensure Apache running
service: name=httpd state=started enabled=yes
6 changes: 6 additions & 0 deletions ansible/roles/httpd/tasks/install.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# file: roles/httpd/tasks/install.yml

- name: Install Apache web server
yum: pkg={{ item }} state=installed
with_items:
- httpd
5 changes: 5 additions & 0 deletions ansible/roles/httpd/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# file: roles/httpd/tasks/main.yml

- include: install.yml
- include: configure.yml
- include: secure.yml
10 changes: 10 additions & 0 deletions ansible/roles/httpd/tasks/secure.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# file: roles/httpd/tasks/secure.yml

- name: Add ports 80, 443 to firewall
shell: firewall-cmd --permanent --zone=public --add-service=http
shell: firewall-cmd --zone=public --add-port=80/tcp --permanent
shell: firewall-cmd --zone=public --add-port=443/tcp --permanent
shell: firewall-cmd --reload

- name: Flush iptables
shell: iptables -F
File renamed without changes.
13 changes: 13 additions & 0 deletions ansible/roles/init/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# file: roles/init/tasks/main.yml
---

- name: Set up firewall
shell: systemctl enable firewalld
shell: systemctl start firewalld

- name: Install nano, git, etc
yum: pkg={{ item }} state=installed
with_items:
- git
- nano
- curl
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# file: roles/mysql/tasks/configure.yml

- name: MySQL | Add allow rule for 3306 to firewall
- name: Add allow rule for 3306 to firewall
firewalld: zone=public port=3306/tcp permanent=true state=enabled
notify:
- Restart the MySQL service
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# file: roles/mysql/tasks/secure.yml


- name: MySQL | Set the root password for all root accounts
- name: Set the root password for all root accounts
mysql_user: name=root host={{ item }} password={{ mysql_root_password }} priv=*.*:ALL,GRANT
with_items:
- "{{ ansible_hostname }}"
@@ -10,7 +9,7 @@
- localhost
when: ansible_hostname != 'localhost'

- name: MySQL | Configure MySql for easy access as root user
- name: Configure MySql for easy access as root user
template: src=.my.cnf.j2 dest=~/.my.cnf owner=root group=root mode=0644

- name: ensure anonymous users are not in the database
File renamed without changes.
4 changes: 4 additions & 0 deletions ansible/roles/php56/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# file: roles/php/defaults/main.yml
---

composer_path: /usr/local/bin/composer
8 changes: 8 additions & 0 deletions ansible/roles/php56/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# file: roles/php/handlers/main.yml
---

- name: restart iptables
service: name=iptables state=restarted

- name: restart httpd
service: name=httpd state=restarted
5 changes: 5 additions & 0 deletions ansible/roles/php56/tasks/configure.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# file: roles/php/tasks/configure.yml

- name: Install Composer globally
shell: curl -sS https://getcomposer.org/installer | /usr/bin/php && /bin/mv -f composer.phar {{ composer_path }} creates={{ composer_path }}

36 changes: 36 additions & 0 deletions ansible/roles/php56/tasks/install.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# file: roles/php/tasks/install.yml

- name: Install epel from remote repo
yum: name=http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm state=present

- name: Install remi from remote repo
yum: name=http://rpms.famillecollet.com/enterprise/remi-release-7.rpm state=present

- name: upgrade all packages
yum: name=* state=latest

- name: Instal php
yum: pkg={{ item }} enablerepo=remi,remi-php56 state=present
with_items:
- php
- php-common

- name: Instal php modules
yum: pkg={{ item }} enablerepo=remi,remi-php56 state=present
with_items:
- php-pecl-apcu
- php-cli
- php-pear
- php-pdo
- php-mysqlnd
- php-pgsql
- php-pecl-mongo
- php-sqlite
- php-pecl-memcache
- php-pecl-memcached
- php-gd
- php-mbstring
- php-mcrypt
- php-xml
notify:
- restart httpd
5 changes: 5 additions & 0 deletions ansible/roles/php56/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# file: roles/php/tasks/main.yml
---

- include: install.yml
- include: configure.yml
25 changes: 25 additions & 0 deletions ansible/roles/phpmyadmin/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# file: roles/phpmyadmin/tasks/main.yml
---

- name: Finding out if phpmyadmin is already cloned
shell: test -d /var/www/phpmyadmin && echo 'exist' || echo ''
register: p

- name: Downloading phpmyadmin stable if isn't downloaded yet
shell: cd /var/www && git clone --depth 1 -b STABLE --single-branch https://github.com/phpmyadmin/phpmyadmin.git
when: p.stdout!='exist'

# echo "Copy parameters.yml and create database"
# cp -f /vagrant/config/symfony/parameters.yml /var/www/symfony/app/config/parameters.yml

- name: Copy conf for apache
template: src=phpmyadmin.tpl dest=/etc/httpd/conf.d/phpmyadmin.conf owner=root group=root mode=0644

- name: Setting firewall rules for phpmyadmin
firewalld: zone=public port=9000/tcp permanent=true state=enabled

- name: Flush iptables
shell: iptables -F

- name: Restarting httpd
shell: systemctl restart httpd
File renamed without changes.
22 changes: 0 additions & 22 deletions mysql.sh

This file was deleted.

24 changes: 0 additions & 24 deletions phpmyadmin.sh

This file was deleted.

97 changes: 0 additions & 97 deletions playbook.yml

This file was deleted.

1 change: 0 additions & 1 deletion vagrant.sh

This file was deleted.

0 comments on commit e2c06db

Please sign in to comment.