All Projects → ptibbetts → anstead

ptibbetts / anstead

Licence: other
Ansible playbook for Laravel

Programming Languages

python
139335 projects - #7 most used programming language
ruby
36898 projects - #4 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to anstead

Centos7 Cis
Ansible CentOS 7 - CIS Benchmark Hardening Script
Stars: ✭ 64 (+357.14%)
Mutual labels:  ansible-playbook
Dellemc Openmanage Ansible Modules
Dell EMC OpenManage Ansible Modules
Stars: ✭ 169 (+1107.14%)
Mutual labels:  ansible-playbook
dotfiles
Minimalistic dotfiles setup for MacOS and Linux
Stars: ✭ 22 (+57.14%)
Mutual labels:  ansible-playbook
Ansible Interactive Tutorial
Interactive Ansible tutorials with dead simple setup via Docker
Stars: ✭ 1,309 (+9250%)
Mutual labels:  ansible-playbook
Ansibleplaybooks
A collection of Ansible Playbooks that configure Kali to use Fish & install a number of tools
Stars: ✭ 143 (+921.43%)
Mutual labels:  ansible-playbook
Zbx Smartctl
Templates and scripts for monitoring disks health with Zabbix and smartmontools
Stars: ✭ 206 (+1371.43%)
Mutual labels:  ansible-playbook
Automated Pihole
Automated Self-Updating (Public) Pi-hole Stack using unbound as recursive DNS server with Ansible
Stars: ✭ 52 (+271.43%)
Mutual labels:  ansible-playbook
manjaro-playbook
Manjaro/Arch Linux Ansible provision playbook
Stars: ✭ 25 (+78.57%)
Mutual labels:  ansible-playbook
Matrix Docker Ansible Deploy
Matrix (An open network for secure, decentralized communication) server setup using Ansible and Docker
Stars: ✭ 2,541 (+18050%)
Mutual labels:  ansible-playbook
Ansible Playbook Grapher
A command line tool to create a graph representing your Ansible playbook tasks and roles
Stars: ✭ 234 (+1571.43%)
Mutual labels:  ansible-playbook
Terraform Null Ansible
Terraform Module to run ansible playbooks
Stars: ✭ 114 (+714.29%)
Mutual labels:  ansible-playbook
Barn
Ansible playbooks for Laravel applications
Stars: ✭ 129 (+821.43%)
Mutual labels:  ansible-playbook
Shiva
An Ansible playbook to provision a host for penetration testing and CTF challenges
Stars: ✭ 220 (+1471.43%)
Mutual labels:  ansible-playbook
Ansible Nas
Build a full-featured home server or NAS replacement with an Ubuntu box and this playbook.
Stars: ✭ 1,198 (+8457.14%)
Mutual labels:  ansible-playbook
UBUNTU20-CIS
Ansible role for Ubuntu 2004 CIS Baseline
Stars: ✭ 136 (+871.43%)
Mutual labels:  ansible-playbook
Ansible In Action
Ansible playbook to deploy your Laravel code base to VPS
Stars: ✭ 61 (+335.71%)
Mutual labels:  ansible-playbook
Graylog Ansible Role
Ansible role which installs and configures Graylog
Stars: ✭ 173 (+1135.71%)
Mutual labels:  ansible-playbook
LEMPer
LEMPer Stack is terminal-based LEMP / LNMP installer and manager for Debian & Ubuntu cloud or virtual server (vps) and on-premise (bare metal).
Stars: ✭ 171 (+1121.43%)
Mutual labels:  lemp
chatroom
💬chat
Stars: ✭ 56 (+300%)
Mutual labels:  ansible-playbook
Spamscope
Fast Advanced Spam Analysis Tool
Stars: ✭ 223 (+1492.86%)
Mutual labels:  ansible-playbook

Why pay for server management when you can use this…

Anstead

Ansible playbooks for setting up a LEMP stack with Redis for Laravel.

  • Local development environment with Vagrant
  • High-performance production servers
  • One-command provisioning
  • One-command deployments

It's still in development

Anstead is a fork of Trellis but for Laravel instead of WordPress.

I've used it in production for over a year however it's only ever had one person use it.

I'm uploading it to show how I changed Trellis to work with Laravel.

I would love to have it merged back into Trellis 💚

Major changes from Trellis:

  • Laravel apps instead of WordPress sites
  • separate server for the database
  • adds Redis
  • splits out the web user to a new role as it's only used on the app server
  • splits out the MariaDB and app setup roles into client/code and server/database roles
  • adds bash aliases to the Vagrant box
  • re-adds the provision.sh script
  • handlers are now in their own role that other roles have as a dependency - this is because handlers are shared between roles but not shared between plays and this gets around that
  • other than the MariaDB PPA it hasn't been synced with Trellis for a while

TODO:

  • rollbacks
  • xdebug
  • laravel.log file still stored in storage and not managed by logrotate

Demo

An example project is available at https://github.com/ptibbetts/anstead-example-project

What's included

This playbook configures the following and more:

  • Ubuntu 16.04 Xenial LTS
  • Nginx
  • PHP 7.1
  • MariaDB
  • Redis
  • Supervisor
  • SSL support (scores an A+ on the Qualys SSL Labs Test)
  • Let's Encrypt integration for free SSL certificates
  • HTTP/2 support (requires SSL)
  • Composer
  • sSMTP (mail delivery)
  • MailHog
  • Fail2ban
  • ferm

Requirements

Ensure all dependencies have been installed before moving on:

Installation

# → Root folder
├── anstead/      # → Ansible / Vagrant folder
└── laravel/      # → Laravel app

All Ansible commands should be ran from the /anstead directory

cd anstead

Servers

This playbook has been designed to have three servers in production:

  • a web server consisting of application code, PHP & Nginx
  • a database server with MariaDB installed
  • a separate server for Redis

however it is possible to use only the one server, which is how the staging and development environments are setup.

Development environment

Vagrant calls the Ansible script to provision a virtual machine for local development.

vagrant up # start Vagrant
cd /srv/www/example.com/current # all Artisan & Composer commands to be ran here

Aliases

The Vagrant box comes with the following bash aliases:

  • art is an alias of php artisan
  • tinker is an alias of php artisan tinker
  • phpspec is an alias of /vendor/bin/phpspec
  • phpunit is an alias of /vendor/bin/phpunit
  • jsonprettify is an alias of python -mjson.tool

You can customise these aliases and add your own by editing the /aliases file.

Remote server setup (staging/production)

At least one base Ubuntu 16.04 server is required for setting up remote servers.

I want all services on the same server

This is how the staging environment is setup by default.

To change the production environment you'll need to add the IP address of the server to the /hosts/production file under [production] and each of the services.

I want a separate server for each service

This is the how the production environment is setup by default but you will still need to configure it to get it to work.

You must make sure each server has private networking (internal IP addresses) enabled so that communication between the servers is both faster and cheaper - you don't usually have to pay for bandwidth on the internal network.

You need to add the domain of the web server and the external IP addresses of the database and Redis servers to the /hosts/production file. Then you need to add the private/internal IP address of each server under the env section in the /group_vars/production/laravel_apps.yml file.

This is so that you can connect to the servers with Ansible using the external IP but each server can communicate with each other using the internal network.

The database and Redis servers, by default, will only open the SSH port. If you separate the services to their own server then they will also open the port for their respective service.

You also need to SSH into each server once as Ansible seems to struggle accepting multiple new servers at the same time - this would be a good time to run apt update && apt upgrade -y before provisioning them.

Provisioning

Ensure hosts/{staging,production} contains the IP address(es) of the server(s) you wish to provision and that group_vars/{staging,production}/{laravel_apps, vault}.yml have been configured, then you can use the provision command to call Ansible:

bin/provision.sh <environment>

Deployments

Could not be easier:

bin/deploy.sh <environment> <app name>

Extras

Installing extra PHP packages

Add the package to the php_extensions_custom array in roles/php/defaults/main.yml and re-provision the app server by running ansible-playbook server.yml -e env=production --tags=php.

Installing extra software packages

Add the package to the apt_packages_custom array in roles/common/defaults/main.yml and run the provisioning script again - htop is a an example of something I'd add here.

Laravel Horizon

If you'd like to use Laravel Horizon to manage the queue workers then you need to make the following changes to Anstead:

anstead/roles/deploy/hooks/finalize-after.yml

- - name: Restart all queue workers
-  shell: /usr/bin/php artisan queue:restart chdir={{ deploy_helper.new_release_path }}
+ - name: Restart Horizon
+  shell: /usr/bin/php artisan horizon:terminate chdir={{ deploy_helper.new_release_path }}

anstead/roles/supervisor/templates/laravel-workers.j2

- [program:{{ item.key }}-worker]
+ [program:{{ item.key }}-horizon-worker]
- process_name=%(process_num)02d
+ process_name=%(program_name)s
- command=php {{ www_root }}/{{ item.key }}/{{ item.value.current_path | default('current') }}/artisan queue:work --queue=default --tries=2
+ command=php {{ www_root }}/{{ item.key }}/{{ item.value.current_path | default('current') }}/artisan horizon
autostart=true
autorestart=true
user={{ web_user }}
- numprocs=2
+ numprocs=1
redirect_stderr=true
- stdout_logfile={{ www_root }}/{{ item.key }}/logs/worker.log
+ stdout_logfile={{ www_root }}/{{ item.key }}/logs/horizon.log

config/horizon.php

Change the local environment to development.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].