Ansible is a powerful tool to automate the provisioning and maintenance of servers. There are a variety of other provisioner tools like Puppet, Chef, and Salt available. Ansible is awesome because it works over SSH so is simple to setup; you ONLY need to install stuff on your local machine.

Working on a server without a provisioner is similar to writing code without version control. It’s a huge pain. Using this playbook will provision and maintain server(s) with the latest stable versions of nginx, PHP-FPM, MariaDB, WordPress, Memcache, Webgrind, and Postfix.

I wrote a simple Ansible playbook that provisions a high speed WordPress environment.

3. Now we will create a file to tell Ansible where our servers we want to provision/maintain are. Create a file in the root of your playbook named hosts:
[code type=”bash”]
[examplesite]
YOUR_FULLY_QUALIFIED_DOMAIN_NAME

In this file we can create as many hosts as we want in the event that we want to provision/maintain multiple environments.

4. Now it’s time to do our first provision. In the terminal enter the following:
[code type=”bash”]
ansible-playbook -i hosts site.yml
[/code]

Remember, Ansible uses SSH so your SSH keys will need to be setup correctly. This playbook will default try the root user on each of your servers (as defined above) so adjust your keys appropriately.

That’s it! Your server(s) should be provisioned and ready to go. Continuing to run the playbook on an existing site will not overwrite or break anything but will upgrade things as needed. This is a great way to bulk manage/update a group of servers. Want to upgrade PHP on all your servers? Just run your playbook. Want to deploy a security patch to all your servers? Add it to your playbook and rerun.