Phansible is an open source project that provides an easy web interface to create Ansible provisionings for PHP based projects. Although the project is more focused on development environments with Vagrant, it's quite easy to configure the downloaded bundle for provisioning any remote server with SSH access. All it takes, besides making sure you have a proper SSH connection to those servers, is that you create a new inventory file to include the servers you want to control.
To configure your local machine and remote servers for a seamless SSH connection using SSH keypair, check this post: Configuring SSH server access for Ansible.
Download your Phansible bundle
Go to phansible.com and create your provisioning. Some things you should consider:
- The Vagrant options are irrelevant, unless you want to have a multistage environment containing also a Vagrant VM
- Server Name: fill the "Server Name" option, in the "web server" section, with the host and/or IP address of your remote server.
Download and unpack the zip file. If you don't plan to use Vagrant for a local environment, you can delete the included Vagrantfile.
Create a new inventory
Check the "ansible/inventories" folder - you will find a dev inventory that contains the IP address configured for the Vagrant environment. You can create a new inventory file for the remote servers, called "production" or "testing" for instance. For this example, let's use "testing". The inventory should contain a group with the server host or IP address, like this:
You will provide the path to this inventory when running ansible-playbook.
Naturally, you should use the hostname or IP address you configured for the SSH access.
Check the variables on ansible/vars/common.yml
Another thing you might want to change is the document root, which is set to "/vagrant" by default. Edit the file ansible/vars/common.yml and change it to the desired location.
Run the Playbook
Now you can just run the ansible-playbook command specifying the inventory and playbook:
$ ansible-playbook -i ansible/inventories/testing ansible/playbook.yml
It should run smoothly if you have a proper SSH keypair connection that doesn't require password for sudo.
It's important to remember that there is no code checkout task by default, since the application data synchronization is handled by Vagrant and the shared folders, in the standard Phansible usage. You'll have to add a task to checkout the application code and make it available in the server in some way. Have a look at the Git Ansible module to see how you can automate the process of checking out code from a Git repository.
It's important to remember that Phansible is aimed at testing and development environments, not intended to be used for production. However, it's a good starting point for any PHP provisioning, a boootstrap that you can customize to fit your needs. Have a look at Ansible Galaxy and the Ansible Documentation for a deeper Ansible experience :)