From cc6f10b6ac7735ea9211c85df99c8a49a72a8460 Mon Sep 17 00:00:00 2001 From: Franck Cuny Date: Sun, 28 Sep 2014 20:18:39 -0700 Subject: [PATCH] Update the GCE guide with a working configuration. Also remove a few whitespaces, improve the bash script and fix a typo. --- docsite/rst/guide_gce.rst | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/docsite/rst/guide_gce.rst b/docsite/rst/guide_gce.rst index f9e498ac0a..c93db36771 100644 --- a/docsite/rst/guide_gce.rst +++ b/docsite/rst/guide_gce.rst @@ -136,15 +136,15 @@ For the following use case, let's use this small shell script as a wrapper. #!/bin/bash PLAYBOOK="$1" - if [ -z $PLAYBOOK ]; then - echo "You need to pass a playback as argument to this script." + if [[ -z $PLAYBOOK ]]; then + echo "You need to pass a playbook as argument to this script." exit 1 fi export SSL_CERT_FILE=$(pwd)/cacert.cer export ANSIBLE_HOST_KEY_CHECKING=False - if [ ! -f "$SSL_CERT_FILE" ]; then + if [[ ! -f "$SSL_CERT_FILE" ]]; then curl -O http://curl.haxx.se/ca/cacert.pem fi @@ -175,11 +175,11 @@ A playbook would looks like this: tasks: - name: Launch instances gce: - instance_names: dev - machine_type: "{{ machine_type }}" - image: "{{ image }}" - service_account_email: "{{ service_account_email }}" - pem_file: "{{ pem_file }}" + instance_names: dev + machine_type: "{{ machine_type }}" + image: "{{ image }}" + service_account_email: "{{ service_account_email }}" + pem_file: "{{ pem_file }}" project_id: "{{ project_id }}" tags: webserver register: gce @@ -188,15 +188,18 @@ A playbook would looks like this: wait_for: host={{ item.public_ip }} port=22 delay=10 timeout=60 with_items: gce.instance_data - - name: add_host hostname={{ item.public_ip }} groupname=new_instances + - name: Add host to groupname + add_host: hostname={{ item.public_ip }} groupname=new_instances + with_items: gce.instance_data - name: Manage new instances hosts: new_instances connection: ssh + sudo: True roles: - base_configuration - production_server - + Note that use of the "add_host" module above creates a temporary, in-memory group. This means that a play in the same playbook can then manage machines in the 'new_instances' group, if so desired. Any sort of arbitrary configuration is possible at this point.