My previous efforts in creating a #devops environment have been entirely manual. When you start scaling and needing to setup things quickly and consistently or outside of production, there is need to automate the process. For infrastructure automation, I have turned to Ansible, which I will henceforth use to configure the entire environment and automate deployments with.
(1) To begin, designate a system that will be used as the host — from where Ansible will be launched. In this case, my development laptop (a MacBook Pro) fits the bill, given that Ansible is mostly a Linux tool. Then in addition to the tools you normally use for development work, you must also install Ansible, VirtualBox, and Vagrant. The idea is to use a VM for development before pushing the changes out to the actual #devops server.
# ansible --version ansible 188.8.131.52 # vagrant --version Vagrant 1.8.5 # vboxmanage --version 5.1.10r112026
(2) The second step is to create the Ansible project consisting of a minimal file layout and configuration options, as shown in the image below.
As can be observed in the image, the Ansible config and inventory files are both setup within the project, and I have elected to configure my servers in the “devops” role. The VM server I’ll use for development is called “devops_vm”, and all servers will be in the “devops_servers” group, to begin with.
(3) To ensure consistency and expediency of major dependencies, such as Java, I will have the archive available locally. In this case, it is under .roles/devops/files/java. I am also following the philosophy of gathering facts always and using Jinja2 (as Ansible is based on Python 2.x) to mint all configuration files. To manage secrets, I’ll maintain a password file locally at /etc/ansible/vault_password.
(4) The current playbook (./provision.yml) will ensure some basic settings, utilities, and services on the provisioned server, as well as install Java if it is not already installed. The source code for this project can be reviewed at GitHub. Ansible will do what I had manually done in #305: Install Java 8 on CentOS 7, only a lot simpler.