Set up one click deploy and provisioning of an environment with all neccessary elements of a DevOps Toolchain.
Description
Use Puppet / Chef / Ansible for the following setup
With the setup in place:
NOTES:
Notes
Details
The flow is as follows:
./mvnw
command (as documented).Here is where some key Ansible-related files are located:
ansible-tower
├── ansible.cfg - ansible configuration
├── hosts - hosts file containing webservers group. Place EC2 hostname here.
├── playbook.yml - main playbook that configures dev environment.
├── roles - the main playbook executes different roles.
│ ├── apache
│ ├── geerlingguy.java
│ ├── geerlingguy.jenkins
│ ├── jenkinsjobs
│ │ └── templates
│ │ ├── config.xml - jenkins job configuration XML.
│ ├── mysql
│ ├── tomcat - this role takes care of tomcat configuration and startup.
│ └── tools
│ └── tasks
│ └── main.yml
└── Vagrantfile - In order to start an Ansible Tower Instance.
Day 1: Creating a local Ansible Tower VM with Vagrant: 4h
Day 1: Creating and Configuring Amazon EC2 Image with Vagrant: 4h
Day 1/2: Creating a Dev Environment with Ansible: 12h
Day 3: Creating a CI/CD pipeline, troubleshooting the full flow: 14h
Within the repo, run the following (assuming Vagrant installed):
cd ansible-tower
vagrant up
vagrant ssh
vagrant ssh
command gives you credentials to Ansible Tower GUI as well as SSHing into the Tower Instance.
vagrant up
throws the error described here. I did not find time to solve this.vagrant up
caused some issues that I solved (see troubleshooting).Details:
See image of successful launch.
Details on Connecting to Instance:
vagrant-aws
plugin is installed.devops.pem
at the top of the repository. cd ec2-i-f9eaa477
vagrant up --provider=aws
Prerequisites
devops.pem
should be placed at top level of repo.0400
otherwise SSH will throw errors.ansible-tower/hosts
should contain the public DNS of the EC2 instance(s) you want to configure.
ec2-12-34-56-78.ap-southeast-1.compute.amazonaws.com
cd ansible-tower
ansible-galaxy install geerlingguy.jenkins -p ./roles/
(this will download the roles)roles
subdirectory now has
roles/geerlingguy.java/
roles/geerlingguy.jenkins/
Now run:
ansible-playbook playbook.yml
Note: the first run will ask you if you want to continue connecting.
See image.
I have kept StrictHostKeyChecking
enabled even though I have the option to disable that and make it truly hands-free. This is for security.
Customization
The following defaults are stored in the roles/tomcat/defaults/main.yml
playbook.
# tomcat download URL. override this as well as tomcat_filename, to download a different tomcat version.
tomcat_url: http://archive.apache.org/dist/tomcat/tomcat-7/v7.0.61/bin/apache-tomcat-7.0.61.tar.gz
# the filename of the file downloaded from above URL.
tomcat_filename: apache-tomcat-7.0.61
# temporary download destination.
tomcat_download_dest: /tmp/
# install location of tomcat.
tomcat_install_dest: /usr/share/
# tomcat ports
tomcat_http_port: 8080
tomcat_https_port: 8443
# tomcat user credentials
tomcat_admin_username: admin
tomcat_admin_password: admin
One can override these variables as per the Playbook docs to override these default values.
E.g. ansible-tower/playbook.yml
overrides the Jenkins Port default (as decided by geerlingguy/jenkins
):
vars:
jenkins_http_port: 8095
While starting up an Ansible Tower VM with Vagrant vagrant up
, I received this error:
The installation process had installed VirtualBox on my machine automatically, and created a VM. So I opened VirtualBox and tried to start the just-created VM. This showed me a more helpful error:
Solution
Before Connecting to the EC2 instance using the downloaded PEM File, I would need to change the file's permissions to 0400
.
However, on my Windows + Cygwin laptop, changing the permissions did not appear to work at all.
After tearing my hair out some, I figured out how to successfully change the permissions and connect to the machine. :+1: See the problem screenshots and solution in this comment.
I encountered multiple issues while exploring deployment of a Vagrant box to the EC2 Image. See problems and solutions here and here.