nshvyryaev Infra repository
There are two instances: bastion_IP = 35.189.220.151 someinternalhost_IP = 10.132.0.3
Only bastion has external IP.
Use bastion host to connect to an instance with internal IP only.
Connect in one command:
ssh -i {identity_file} -A -t {user}@{bastion_external_IP} ssh {some_internal_host_IP}
Connection command example:
ssh -i ~/.ssh/otus/appuser -A -t [email protected] ssh 10.132.0.3
To use ssh alias someinternalhost
add following config to your ~/.ssh/config
:
Host someinternalhost
ForwardAgent yes
HostName 10.132.0.3
User appuser
IdentityFile ~/.ssh/otus/appuser
ProxyCommand ssh -W %h:%p [email protected]
VPN is based on Pritunl server. Configuration could be found at cloud-bastion.ovpn
.
Pritunl web admin panel has valid TLS certificate
signed for 35-189-220-151.sslip.io
domain
testapp_IP = 35.240.45.64 testapp_port = 9292
Execute from project root.
gcloud compute instances create reddit-app-auto\
--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_script.sh
gcloud compute firewall-rules create default-puma-server \
--direction=INGRESS \
--priority=1000 \
--network=default \
--action=ALLOW \
--rules=tcp:9292 \
--source-ranges=0.0.0.0/0 \
--target-tags=puma-server
Run commands from directory packer
. Use variables.json.example
to create files with variables.
Create variables.json
file with required parameters.
Run packer build -var-file=variables.json ubuntu16.json
Create immutable_variables.json
file with required parameters.
Run packer build -var-file=immutable_variables.json immutable.json
Run create-reddit-vm.sh
to create an instance from full image.
No more actions needed - server will operate as soon as an instance will be ready.
Terraform configuration is added to the project. See terraform
directory for configuration details.
Use terraform.tfvars.example
as an example of what can be configured via variables.
SSH keys are stored in single variable 'ssh-keys', that means that Terraform:
- Removes manually added keys
- You need to concatenate username into value separating key and user with colon
- You need to concatenate multiple keys into single value and separate them with new line
Added using Google module https://github.com/terraform-google-modules/terraform-google-lb
.
Code was copied to add instances to targets pool without auto scaling.
Use instance_count
variable to set desired count of instances in load balancer targets pool.
Terraform configuration is split into separate modules. Stage and prod environments created. SSH IP limitation added to the project. External static IP added.
SweetOps/storage-bucket/google
doesn't work with defaults. Specifying parameter "location" has fixed the issue.
Terraform can use remote backend to store its state. This allows work together on the same project. Running multiple apply command simultaneously is restricted, state is locked.
You should use absolute path in module in order to refer files located in module.
${path.module}
will help.
Mongodb listens only on localhost by default. To allow external connections you need to add
DB host internal IP in bindIp
config variable.
For some reason Travis build has failed... Let's check if it is caused by the code
Git module doesn't change anything if repo exists. Module makes change if we remove existing folder.
Static JSON inventory file has the same structure as YAML does. Dynamic has hosts configured as names only.
Each host variables are extracted into separate section _meta: hostvars
. Dynamic JSON can't be used without a script.
- Playbook
reddit_app_one_play.yml
added for DB and APP configuration - Playbook
reddit_app_multiple_plays.yml
added. Multiple plays simplify running a bit. - Previous playbook is split into
app.yml, db.yml, deploy.yml
. Playbooksite.yml
launches them all. - Dynamic inventory created using gcp_compute plugin
- Packer provisioning is reconfigured with Ansible.
To run Ansible deploy execute ansible-playbook site.yml
from directory ansible
.
Note: There was an issue with APT repo key provided in gist for packer_db.yml.
- Ansible roles added for app and db
- Both roles are used in playbook
site.yml
- Two environments created: stage and prod
- Community role
jdauphant.nginx
used to configure http port proxy. 9292 firewall rule has been disabled, 80 port is enabled. - Playbook users.yml added to create users on app host. Variables are encrypted with Ansible Vault. For SSH config see https://serverpilot.io/docs/how-to-enable-ssh-password-authentication/