Provision with AWS (Amazon Web Service)
Step 1 - Change the vm box to be used
To provision with AWS, the AWS box built with packer or a referenced AWS vagrant box from some archive must be used. If the box was built update the base box in the Vagrantfile
for eg.
config.vm.box = "dummy.box"
Step 2 - Change Ansible Override Variables
from:
ansible.extra_vars = "provisioners/ansible/extra_vars/jenkins-master-playbook-vars.yml"
to:
ansible.extra_vars = "provisioners/ansible/extra_vars/jenkins-master-aws-playbook-vars.yml"
Step 3 - Fill in required AWS info
Inorder to provision environments within AWS, it is a requirement to provide sensitive AWS information such as the access_key_id
and secret_access_key
. Since this code is being committed to a github repository where other persons can view the code base, environment variables are being used to set this information in a local terminal, for e.g. export AWS_SECRET_ACCESS_KEY=SOMEKEYHASH
.
def aws_provider_configs(config)
config.vm.provider :aws do |aws, override|
override.ssh.username = ENV["AWS_SSH_USER"]
override.ssh.private_key_path = ENV["AWS_KEY_LOCATION"]
aws.keypair_name = ENV["AWS_KEYPAIR_NAME"]
aws.access_key_id = ENV["AWS_ACCESS_KEY_ID"]
aws.secret_access_key = ENV["AWS_SECRET_ACCESS_KEY"]
aws.ami = ENV["AMI"]
aws.security_groups = [ENV['AWS_SECURITY_GROUP']]
aws.region = "us-east-1"
aws.tags = {
'Name' => 'jenkins-docker-master',
'Provisioner' => 'Medullan',
'OS_Version' => 'Ubuntu',
'Release' => 'Latest'
}
end
end
Step 4 - Uncomment Rsync Folder sharing
This step is important. The rsync line lists files that should be ignore when syncing files on the local machine with the AWS machine. If these are not ignore then the process will attempt to transfer very huge files and you may wait a very long time before seeing any progress.
config.vm.synced_folder ".", "/vagrant", type: "rsync", :rsync_excludes => ['packer_cache/', 'http/', ... ]
then run:
$ vagrant up --provider=aws
This will create and run an AWS instance in your account.
For more information on provisioning with AWS please view the following repository:
https://github.com/mitchellh/vagrant-aws
Extras
There are some Ansible roles that are shared when provisioning the base image and the Jenkins environments. One such role would be setup. If you wat to ignore this role when provisioning the Jenkins environments, Then uncomment the following line in the Vagrantfile:
ansible.skip_tags = ['setup']
Caveats
When provisioning the Jenkins environment with AWS for the first time, the provisioning will fail for SSH reasons. To see how to resolve, please see the Known Issues section for this topic