Giter VIP home page Giter VIP logo

ansible-lamp-stack's Introduction

Ansible LAMP Stack

This is a demo Ansible project showing the basics of setting up a multi-server LAMP stack + HA-Proxy loadbalancer.

Requirements

The Stack

  • Ubuntu 14.04
  • HA-Proxy v1.4.24
  • Apache v2.4
  • PHP v5.5
  • Composer
  • NodeJS + NPM
    • Grunt
    • Gulp
    • Bower
    • Node Sass
  • MySQL v5.5

Boxes

  • 1x HA-Proxy Loadbalancer
  • 2x Apache + PHP
  • 1x MySQL

The LAMP stack operates as follows: the LB forwards port 80 to port 8000 on the host and balances traffic via round-robin. Each web server is also directly available on host ports 8001 and 8002. The MySQL box forwards port 3306 to port 33060 on the host for easy access via client apps like Sequel Pro. Each box has an admin and deploy user. Their passwords are protected via ansible-vault. The vault file can be found in roles/users/vars/main.yml and the password is admin.

Setup

This project contains 2 Vagrant files in separate folders. ansible-ctrl has the "control" machine. It does the provisioning of the boxes in ansible-workers. I suppose it goes without saying, but you will need to have both sets of machines running. There are 5 in all @ 512 MB each, so make sure you have enough memory on your host machine.

To get it all running, open 2 tabs in terminal, one for ansible-ctrl/ and one for ansible-workers/:

ansible-workers/

Note: Make sure this finishes before moving on.

$ vagrant up

ansible-ctrl/

$ vagrant up
$ vagrant ssh
$ cd ~/.ssh
$ ssh-keygen -t rsa -b 4096 -C "[email protected]"

Repeat the next step for 16 - 19. When prompted the password is vagrant. This will allow ansible to ssh into each box it's provisioning via public key.

$ ssh-copy-id [email protected]

And now to provision the stack. The vault password is admin:

$ cd /etc/ansible/playbooks
$ ansible-playbook main.yml --ask-vault-pass

Assuming all went well, you should be able to visit http://localhost:8000 in your browser and see a welcome message from ansible-site.dev. You can also visit /info.php to see info about the PHP installation.

Where to go from here

Ansible is fairly simple to understand. Everything is configured in YAML. Start with ansible-ctrl/main.yml and move on from there. main.yml includes the bits and pieces that we want to provision. The roles in each of the included files represent the sub-folders in the roles dir. For each role, tasks/main.yml is loaded up first. It can perform tasks, or include other files for better organization. vars/main.yml contains, you guessed it, variables to be used in your tasks and templates. handlers/main.yml contains commands to be run when they're "notified" by a task, ie. restarting Apache.

Try provisioning your own site. Take a look at ansible-ctrl/webservers.yml. You can add more sites there. Also be sure to look at ansible-ctrl/roles/webserver/templates/ to see how the site's vhost, index.html, and index.php are being created. You can also add databases in ansible-ctrl/dbservers.yml.

ansible-lamp-stack's People

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.