ansible/ansible-modules-core — pull request #114 by erjohnso (2014-10-01 22:02:31+00:00)
Title: Adding new metadata_from_file option to GCE module

Introducing a new option to allow users to set metadata values from the contents of files. This is useful for taking advantage of passing in 'startup-scripts' [https://cloud.google.com/compute/docs/howtos/startupscript] to new instances. An example playbook might look like,

```
- name: Create an instance with a startup-script
hosts: local
gather_facts: False
vars:
pid: MY_PROJECT
email: hidden@developer.gserviceaccount.com
pem: /home/erjohnso/pkey.pem
machine_type: n1-standard-1
image: debian-7
itags: apache
izone: us-central1-b
tasks:
- name: Bring up new instance with startup script
gce:
name: "metadata-test"
metadata: '{"k1":"v1"}'
metadata_from_file: '{"startup-script":"/home/erjohnso/bootup.sh"}'
machine_type: "{{ machine_type }}"
image: "{{ image }}"
tags: "{{ itags }}"
zone: "{{ izone }}"
project_id: "{{ pid }}"
pem_file: "{{ pem }}"
service_account_email: "{{ email }}"
```

When the instance is created, it looks by default for a special metadata tag called 'startup-script'. If that exists, the value is written to the instance's disk and executed automatically at instance creation. Typical uses are initial configuration such as 'apt-get update'.