# Dynamic inventory not working in playbook

**URL:** <https://forum.ansible.com/t/dynamic-inventory-not-working-in-playbook/21192>\
**Category:** Ansible Project\
**Created:** [April 18, 2016, 2:06pm UTC](https://forum.ansible.com/t/dynamic-inventory-not-working-in-playbook/21192 "2016-04-18T14:06:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pavanan\_M\_S](https://avatars.discourse-cdn.com/v4/letter/p/ed655f/32.png) [@Pavanan\_M\_S](https://forum.ansible.com/u/Pavanan_M_S)\
**Post date:** [April 18, 2016, 2:06pm UTC](https://forum.ansible.com/t/dynamic-inventory-not-working-in-playbook/21192/1 "2016-04-18T14:06:50Z")

</div>

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**

```auto
- 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
