Together they make small work out of a complex task
*All software runs on Windows, Mac and popular *nix systems.
Vagrant is a lightweight, easy to use wrapper that will create a virtual machine, install an OS and pass control to a provisioner script for configuration.
File: ./Vagrantfile
config.vm.box = "wheezy" config.vm.box_url = "http://puppet-vagrant-boxes.puppetlabs.com/debian-70rc1-x64-vbox4210-nocm.box" config.vm.hostname = 'debian-web'; config.vm.network :private_network, ip: "192.168.33.10" config.vm.synced_folder "./www", "/var/www", id: "vagrant-root", :group=>'www-data', :mount_options=>['dmode=775,fmode=775'] config.vm.provision "ansible" do |ansible| ansible.playbook = "provisioners/playbook.yml" ansible.inventory_path = "provisioners/ansible_hosts"
Ansible is an automation tool for configuration and deployment.
File: provisioners/playbook.yml
--- - hosts: webservers user: vagrant sudo: yes vars_files: - roles/common/vars/vars.yml vars: templates_dir: "roles/common/templates" tasks: - include: roles/common/tasks/base.yml - include: roles/common/tasks/environment.yml - include: roles/common/tasks/add_ppas.yml - include: roles/common/tasks/php.yml - include: roles/common/tasks/nginx.yml - include: roles/common/tasks/mariadb.yml ...
File: provisioners/roles/common/tasks/add_ppas.yml
--- - name: Add dotdeb main apt_repository: repo='deb http://packages.dotdeb.org wheezy all' state=present - name: Add dotdeb main src apt_repository: repo='deb-src http://packages.dotdeb.org wheezy all' state=present - name: Add dotdeb php55 apt_repository: repo='deb http://packages.dotdeb.org wheezy-php55 all' state=present - name: Add dotdeb php55 src apt_repository: repo='deb-src http://packages.dotdeb.org wheezy-php55 all' state=present - name: APT | Install DotDeb key apt_key: url='http://www.dotdeb.org/dotdeb.gpg' state=present tags: dotdeb
File: provisioners/roles/common/tasks/nginx.yml
--- - name: Nginx | Install Nginx apt: pkg=nginx state=latest - name: Nginx | Check vhosts path exists file: dest=/etc/nginx/sites-available state=directory - name: Nginx | Copy vhost files copy: src="{{ templates_dir }}/nginx/sites-available/webserver1" dest=/etc/nginx/sites-available owner=root group=root mode=600 notify: - nginx-restart - name: Nginx | Create vhost symlinks file: path=/etc/nginx/sites-enabled/webserver state=link src=/etc/nginx/sites-available/webserver1 notify: - nginx-restart - name: Nginx | Remove default vhost file: dest=/etc/nginx/sites-available/default state=absent - name: Nginx | Remove default vhost enabled symlink file: dest=/etc/nginx/sites-enabled/default state=absent - name: Nginx | Ensure directory exists file: dest=/var/www state=directory - name: Nginx | Ensure Nginx is running service: name=nginx state=started
File: provisioners/roles/common/tasks/php.yml
--- - name: Install PHP5 apt: pkg={{ item }} state=latest force=yes with_items: - php5-fpm - php5-mysql - php5-cli - php5-curl - name: PHP | Copy PHP config file copy: src="{{ templates_dir }}/php/php.ini" dest=/etc/php5/fpm/php.ini owner=root group=root force=yes notify: - php5-fpm-restart
File: provisioners/roles/common/handlers/php.yml
--- - name: php5-fpm-start service: name=php5-fpm state=started - name: php5-fpm-restart service: name=php5-fpm state=restarted - name: php5-fpm-stop service: name=php5-fpm state=stopped