Clone this repo and initialize submodules:
git clone https://github.com/mateothegreat/ansible-google-cloud && cd $_
git submodule update --init
pip install ansible
pip install pycrypto
pip install apache-libcloud
$ ansible-playbook gce-instances-create.yml -e instances=test-01,test-02
PLAY [Create instance(s)] ******************************************************************************************************TASK [Launch instances] ********************************************************************************************************changed: [127.0.0.1]
TASK [Wait for SSH to come up] *************************************************************************************************
ok: [127.0.0.1] => (item={u'status': u'RUNNING', u'network': u'default', u'zone': u'us-central1-a', u'tags': [u'test'], u'image': u'centos-7-v20180314', u'disks': [u'test-01'], u'name': u'test-01', u'public_ip': u'104.197.64.187', u'private_ip': u'10.128.0.7', u'machine_type': u'n1-standard-1', u'subnetwork': u'default', u'metadata': {}})
ok: [127.0.0.1] => (item={u'status': u'RUNNING', u'network': u'default', u'zone': u'us-central1-a', u'tags': [u'test'], u'image': u'centos-7-v20180314', u'disks': [u'test-02'], u'name': u'test-02', u'public_ip': u'35.188.121.115', u'private_ip': u'10.128.0.8', u'machine_type': u'n1-standard-1', u'subnetwork': u'default', u'metadata': {}})
TASK [Add host to groupname] ***************************************************************************************************
changed: [127.0.0.1] => (item={u'status': u'RUNNING', u'network': u'default', u'zone': u'us-central1-a', u'tags': [u'test'], u'image': u'centos-7-v20180314', u'disks': [u'test-01'], u'name': u'test-01', u'public_ip': u'104.197.64.187', u'private_ip': u'10.128.0.7', u'machine_type': u'n1-standard-1', u'subnetwork': u'default', u'metadata': {}})
changed: [127.0.0.1] => (item={u'status': u'RUNNING', u'network': u'default', u'zone': u'us-central1-a', u'tags': [u'test'], u'image': u'centos-7-v20180314', u'disks': [u'test-02'], u'name': u'test-02', u'public_ip': u'35.188.121.115', u'private_ip': u'10.128.0.8', u'machine_type': u'n1-standard-1', u'subnetwork': u'default', u'metadata': {}})
PLAY RECAP *********************************************************************************************************************
127.0.0.1 : ok=3 changed=2 unreachable=0 failed=0
$ ansible-playbook gce-instances-delete.yml -e instances=test-01,test-02
PLAY [Delete instance(s)] *******************************************************************************************************
TASK [Destroy instances] ********************************************************************************************************changed: [127.0.0.1]
PLAY RECAP **********************************************************************************************************************127.0.0.1 : ok=1 changed=1 unreachable=0 failed=0