#!/bin/sh # This script is Ansible Jinja/j2 pre-processed! # # Configured by Ansible with IPs and Hostnames, this is ran on # both Web and DB server to make the other host known. # # Run: # ssh ec2-54-242-248-253.compute-1.amazonaws.com sudo sh /tmp/do-connect-vms.sh # # Copyright (c) 2013 Hubert Feyrer # {% for host in groups['security_group_ec2-webservers'] %} webserver_name_public="{{ host }}" webserver_name_internal="{{ hostvars[host]['ec2_private_dns_name'] }}" webserver_ip="{{ hostvars[host]['ec2_ip_address'] }}" {% endfor %} {% for host in groups['security_group_ec2-dbservers'] %} dbserver_name_public="{{ host }}" dbserver_name_internal="{{ hostvars[host]['ec2_private_dns_name'] }}" dbserver_ip="{{ hostvars[host]['ec2_ip_address'] }}" {% endfor %} hostname=`hostname` # AWS/EC2: internal! htdocs=/usr/pkg/share/httpd/htdocs echo Start: `date` if [ $hostname = $dbserver_name_internal ]; then echo DBserver: grant remote access to webserver ( cat <webapp.php