Ansible is the most powerful automation tool that can automate cloud provisioning, configuration management, application deployment, and many other IT needs.
Ansible represents what machines it manages using a very simple INI file that puts all of your managed machines in groups of your own choosing.
It looks like this -
[digitalocean]
example.com ansible_user=root
[aws]
example.me ansible_user=ubuntu
Once inventory hosts are listed under ansible/inventories
, variables can be assigned to them in yml files (in a subdirectory called group_vars
)
It looks like this -
remote_user: ubuntu
docker_group: docker
github_repo: 'https://github.com/ankitjain28may/drupal-best-practices.git'
staging_branch: 'develop'
env_file: 'ansible'
backup_dir: '/var/www'
project_dir: '/var/www'
project_folder_name: 'html'
backup_folder_name: 'backup'
Note : Configure default path to your inventory in ansible.cfg
in root directory
Anisble Playbooks can be used to manage configurations of and deployments to remote machines.
Ansible playbooks looks like -
---
- name: Name of the playbook
hosts: <hostname>
roles:
- role1
- role2
Add your hosts name in existing playbooks defined in drupal.*.yml
under ansible
dir or create your own custom playbooks.
In this project, Total 8 playbooks are defined to help you, Detailed description of these playbooks-
- drupal.development.yml is configured for your development environment -
ansible-playbook ansible/drupal.development.yml -i <inventory_path>
have following roles -
{git-pull, env, restart, composer, drupal}
- drupal.docker-install.yml is configured to install docker and docker-compose -
ansible-playbook ansible/drupal.docker-install.yml -i <inventory_path>
have following roles -
{docker-install}
- drupal.production.yml is configured to setup site on production server -
ansible-playbook ansible/drupal.production.yml -i <inventory_path>
have following roles -
{backup, docker-install, git-clone, git-hooks, env, docker-build, composer-prod, drupal}
- drupal.restore-backup.yml is configured to restore backup on your server -
ansible-playbook ansible/drupal.restore-backup.yml -i <inventory_path>
have following roles -
{restore, docker-build, composer-prod, drupal}
- drupal.staging.yml is configured to setup site on staging server -
ansible-playbook ansible/drupal.staging.yml -i <inventory_path>
have following roles -
{backup, docker-install, git-stage, git-hooks, env, restart, composer, drupal}
- drupal.backup.yml is configured to backup your site on server -
ansible-playbook ansible/drupal.backup.yml -i <inventory_path>
have following roles -
{backup}
- drupal.local.yml is configured to configure development environment on your local system -
ansible-playbook ansible/drupal.local.yml -i <inventory_path>
have following roles -
{docker-install, git-hooks, docker-build, composer, drupal}
- drupal.travis.prod.yml is configured to integrate Continuous Integration and Continuous Deployment -
ansible-playbook ansible/drupal.travis.prod.yml -i <inventory_path>
have following roles -
{docker-build, composer, drupal}
-
backup - It will rename
html
folder tobackup
folder and create emptyhtml
folder. -
composer - Install Composer Dependencies with dev dependencies.
-
composer-prod - Install Composer Dependencies without dev dependencies.
-
docker-build - Delete previous container and rebuild image if there is any change and re-create
drupal
anddrupaldb
containers. -
docker-install - Install Docker and docker-compose on the server.
-
drupal - Import Configuration and Rebuild Cache.
-
env - Move
.env.example
to.env
. -
git-clone - Clone the git repo.
-
git-pull - Pull the changes from the git repo after stashing any local changes.
-
git-stage - Clone the selective branch from git repo.
-
git-hooks - Configure git hooks on pre-commit
-
restart - Restart Docker containers.
-
restore - Restore previously generated
backup
folder tohtml
andhtml
tobackup
.