예제 #1
0
def setup_instance():
    reservation = conn.run_instances(
        options.get_ami_id(),
        instance_type=options.get_instance_type(),
        key_name=options.get_ssh_key(),
        security_groups=[options.get_security_group()])
    reservation.instances[0].add_tag('Name', value=options.get_instance_name())
    return wait_for_ip(reservation.id)
예제 #2
0
def wait_for_ssh(ip_address):
  print options.YELLOW, "waiting for SSH access", options.WHITE
  e_code = 1
  while e_code != 0:
    p = subprocess.Popen(["ssh", "-i", options.get_ssh_key() + ".pem", options.get_ssh_user() + "@" + ip_address, "hostname"])
    e_code = p.wait()
    time.sleep(1)
  print options.GREEN, "SSH access obtained", options.GREEN
예제 #3
0
def configure_instance(ip_address):
  setup_ansible_hosts(ip_address)
  print options.YELLOW, "configuring instance:", ip_address, options.WHITE
  proc = subprocess.Popen(['ansible-playbook', '--private-key', options.get_ssh_key() + ".pem", '-u', options.get_ssh_user(), '-i', 'sample.hosts', 'apache2.yml'], stdout=subprocess.PIPE)
  exit_code = proc.wait()
  if exit_code == 0:
    print options.GREEN, "successfully configured the instance at:", options.WHITE, ip_address
  else:
    print options.RED, "failed to configure the instance at:", options.WHITE, ip_address
예제 #4
0
def wait_for_ssh(ip_address):
    print options.YELLOW, "waiting for SSH access", options.WHITE
    e_code = 1
    while e_code != 0:
        p = subprocess.Popen([
            "ssh", "-i",
            options.get_ssh_key() + ".pem",
            options.get_ssh_user() + "@" + ip_address, "hostname"
        ])
        e_code = p.wait()
        time.sleep(1)
    print options.GREEN, "SSH access obtained", options.GREEN
예제 #5
0
def configure_instance(ip_address):
    setup_ansible_hosts(ip_address)
    print options.YELLOW, "configuring instance:", ip_address, options.WHITE
    proc = subprocess.Popen([
        'ansible-playbook', '--private-key',
        options.get_ssh_key() + ".pem", '-u',
        options.get_ssh_user(), '-i', 'sample.hosts', 'apache2.yml'
    ],
                            stdout=subprocess.PIPE)
    exit_code = proc.wait()
    if exit_code == 0:
        print options.GREEN, "successfully configured the instance at:", options.WHITE, ip_address
    else:
        print options.RED, "failed to configure the instance at:", options.WHITE, ip_address
예제 #6
0
def setup_instance():
  reservation = conn.run_instances(options.get_ami_id(), instance_type=options.get_instance_type(), key_name=options.get_ssh_key(), security_groups=[options.get_security_group()])
  reservation.instances[0].add_tag('Name', value=options.get_instance_name())
  return wait_for_ip(reservation.id)