Hi all,
I am using a playbook to create a GCE VM intance and deploy some code to it. I was hard coding the IP of the created instance until i realized the use of dynamic inventories.
I downloaded gce.py and made it executable. Commands like
./gce.py --list
GCE_INI_PATH=/home/pavanan/Documents/ansible_backp/messaging-deploy/gce.ini ansible all -m ping
are working as expected.
I have two playbooks. One creates an instance in localhost and adds it to a group using add host command, like the following playbook from google cloud platform guide
- name: Create instance(s)
hosts: localhost
gather_facts: no
connection: local
vars:
machine_type: n1-standard-1 # default
image: debian-7
service_account_email: unique-id@developer.gserviceaccount.com
pem_file: /path/to/project.pem
project_id: project-id
tasks:
- name: Launch instances
gce:
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
- name: Wait for SSH to come up
wait_for: host={{ item.public_ip }} port=22 delay=10 timeout=60
with_items: gce.instance_data
- name: Add host to groupname
add_host: hostname={{ item.public_ip }} groupname=gce-instances
with_items: gce.instance_data
And the other playbook has host as gce-instances and the other deployment steps.
I made an inventory directory and placed my hosts file, with just [local] and localhost in it, and also the file gce.py.
How can I connect to and do the operations on the instance created above?
I tried,
$ export GCE_INI_PATH=/home/pavanan/Documents/ansible_backp/messaging-deploy/gce.ini
$ ansible-playbook -i inventory/gce.py my_playbook.yml