- Using Vagrant
- Tesing roles with Molecule and Testinfra
- Set Packer to use Ansible roles
- Move db role to external repo
- TravisCI for repo with external role
- Ansible - from playbooks to roles
- Split Ansible configuration to prod and stage environments
- Use community role for setup nginx
- Ansible Valut for secrets storing
- Dynamic inventory for environments
- TraviCI tests for Ansible, Packer, Terraform
- Ansible playbooks, handlers, templates (jinja2) with one play in playbook
- Ansible playbook with several plays
- Several Ansible playbooks
- Packer images provisioning with ansible playbooks
ansible-playbook clone.yml
->ansible app -m command -a 'rm -rf ~/reddit'
->ansible-playbook clone.yml
- first playbook run shows server is not changed (reddit already exists from previous step in homework), second playbook run shows server is changed (reddit was not exists)- (*) task:
- create static JSON-inventory (
ansible/inventory.json
) - confirure terraform to generate dinamyc inventory in json format as output variable (
terraform output dynamic_inventory
now shows actual servers) - create bash srcipt (
dynamic-inventory.sh
) to get output var from terraform and return it to ansible as inventory
- create static JSON-inventory (
- Remove load balancer confiruration from previous homework
- Import firewall rule from GCP to terraform state
- Test resource dependencies
- Split config to have two instances - one for application and one for database
- Split main.tf to separate config files - app.tf, db.tf, vpc.tf
- Use terraform modules in single and multi environments
- Use storage-bucket plugin from terraform registry to store states in remote buckets
- Add optional provisioning to app instance
- Because app and db is now on different instances, it needs to modify mongodb config (
bindIP
) on base image, and set environment variable DATABASE_URL on app instance
- Remove project wide SSH keys from GCP
- Install terraform 0.11.11
> terraform -v
Terraform v0.11.11
- Plan IaC (instance, provisioning, fw rule) in
main.tf
,variables.tf
,terraform.tfvars
- Add files for provisioning in
files/
- Output variables described in
outputs.tf
- SSH keys for several users
resource "google_compute_project_metadata" "default" {
metadata = {
# путь до публичного ключа
ssh-keys = "appuser1:${file(var.project_public_key_path)}appuser2:${file(var.project_public_key_path)}"
}
}
- Added
lb.tf
with code for load balancing main.tf
,variables.tf
,outputs.tf
modified for several app instances (count = n
)
- Installed Packer
- Application Default Credentials (ADC) created
gcloud auth application-default login
- Added template for image (
ubuntu16.json
) - Template validated with
packer validate ./ubuntu16.json
- VM created from GCP web console
- Application reddit-app deployed by script:
#! /bin/bash
git clone -b monolith https://github.com/express42/reddit.git
$ cd reddit && bundle install
$ puma -d
- Some template parameters were moved to variables
Summary: we have a "fry" image with manual application deploy
- Created template
immutable.json
for "baked" image with reddit-app - Added script
create-redditvm.sh
for VM creation based on "baked" image
Summary: we have a "baked" image with already deploed application
- Installed and initialized Cloud SDK
- Created VM instance
gcloud compute instances create reddit-app\
--boot-disk-size=10GB \
--image-family ubuntu-1604-lts \
--image-project=ubuntu-os-cloud \
--machine-type=g1-small \
--tags puma-server \
--restart-on-failure \
- Installed Ruby
sudo apt update
sudo apt install -y ruby-full ruby-bundler build-essential
- Installed MongoDB
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
sudo bash -c 'echo "deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 multiverse" > /etc/apt/sources.list.d/mongodb-org-3.2.list'
sudo apt update && sudo apt install -y mongodb-org
sudo systemctl start mongod && sudo systemctl enable mongod && sudo systemctl status mongod
- Test application deployed
cd ~/
git clone -b monolith https://github.com/express42/reddit.git
cd reddit && bundle install
puma -d
ps aux | grep puma
- Firewall rule for port 9292 created in GCP console
- Bash scripts created for Ruby, MongoDB installation and application deployment
- Startup script created (
startup.sh
) - VM instance created with startup script
gcloud compute instances create reddit-app\
--boot-disk-size=10GB \
--image-family ubuntu-1604-lts \
--image-project=ubuntu-os-cloud \
--machine-type=g1-small \
--tags puma-server \
--restart-on-failure \
--metadata-from-file startup-script=startup.sh
- Firewall rule created with command
gcloud compute firewall-rules create default-puma-server \
--allow=tcp:9292 \
--target-tags=puma-server
testapp_IP = 34.68.146.214
testapp_port = 9292
-
Remote internal server SSH in one command:
ssh -A -t [email protected] ssh someinternalhost
-
Create alias for command
ssh someinternalhost
cat ~/.ssh/config
Host someinternalhost
ProxyCommand ssh -A [email protected] -W %h:%p
bastion_IP = 35.209.46.30
someinternalhost_IP = 10.128.0.5