# Not able to configure server using Ansible Dynamic Inventory

**URL:** <https://forum.ansible.com/t/not-able-to-configure-server-using-ansible-dynamic-inventory/17643>\
**Category:** Ansible Project\
**Created:** [February 27, 2015, 11:38pm UTC](https://forum.ansible.com/t/not-able-to-configure-server-using-ansible-dynamic-inventory/17643 "2015-02-27T23:38:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rahul\_Mehrotra](https://avatars.discourse-cdn.com/v4/letter/r/5e9695/32.png) [@Rahul\_Mehrotra](https://forum.ansible.com/u/Rahul_Mehrotra)\
**Post date:** [February 27, 2015, 11:38pm UTC](https://forum.ansible.com/t/not-able-to-configure-server-using-ansible-dynamic-inventory/17643/1 "2015-02-27T23:38:23Z")

</div>

I am using ec2.py dynamic inventory for provisioning with ansible. I have placed the ec2.py in /etc/ansible/hosts file and marked it executable. I also have the ec2.ini file in /etc/ansible/hosts.

> [ec2]
> 
> regions = us-west-2 regions\_exclude = us-gov-west-1,cn-north-1
> 
> destination\_variable = public\_dns\_name
> 
> vpc\_destination\_variable = ip\_address route53 = False
> 
> all\_instances = True all\_rds\_instances = False
> 
> cache\_path = ~/.ansible/tmp
> 
> cache\_max\_age = 0
> 
> nested\_groups = False group\_by\_instance\_id = True group\_by\_region = True group\_by\_availability\_zone = True group\_by\_ami\_id = True group\_by\_instance\_type = True group\_by\_key\_pair = True group\_by\_vpc\_id = True group\_by\_security\_group = True group\_by\_tag\_keys = True group\_by\_tag\_none = True group\_by\_route53\_names = True group\_by\_rds\_engine = True group\_by\_rds\_parameter\_group = True

Above is my ec2.ini file

```auto
---
- hosts: localhost
  connection: local
  gather_facts: yes
  vars_files:
   - ../group_vars/dev_vpc
   - ../group_vars/dev_sg
   - ../hosts_vars/ec2_info
  vars:
    instance_type: t2.micro
  tasks:
   - name: Provisioning EC2 instance
     local_action:
     module: ec2
     region: "{{ region }}"
     key_name: "{{ key }}"
     instance_type: "{{ instance_type }}"
     image: "{{ ami_id }}"
     wait: yes
     group_id: ["{{ sg_npm }}", "{{sg_ssh}}"]
     vpc_subnet_id: "{{ PublicSubnet }}"
     source_dest_check: false
     instance_tags: '{"Name": "EC2", "Environment": "Development"}'
 register: ec2
  - name: associate new EIP for the instance
    local_action:
      module: ec2_eip
      region: "{{ region }}"
      instance_id: "{{ item.id }}"
      with_items: ec2.instances
  - name: Waiting for NPM Server to come-up
    local_action:
      module: wait_for
      host: "{{ ec2 }}"
      state: started
      delay: 5
      timeout: 200
 - include: ec2-configure.yml

```

Now the configuring script is as follows

```auto
- name: Configure EC2 server
  hosts: tag_Name_EC2
  user: ec2-user
  sudo: True
  gather_facts: True
  tasks:
   - name: Install nodejs related packages
     yum: name={{ item }} enablerepo=epel state=present
     with_items:
      - nodejs
      - npm

```

However when the configure script is called, the second script results into no hosts found. If I execute the ec2-configure.yml just alone and if the EC2 server is up & running then it is able to find it and configure it.

I added the wait\_for to make sure that the instance is in running state before the ec2-configure.yml is called.

Would appreciate if anyone can point my error. Thanks

---

<div class="post-metadata">

**Author:** ![Chris\_Church1](https://avatars.discourse-cdn.com/v4/letter/c/ac8455/32.png) [@Chris\_Church1](https://forum.ansible.com/u/Chris_Church1)\
**Post date:** [March 3, 2015, 7:46pm UTC](https://forum.ansible.com/t/not-able-to-configure-server-using-ansible-dynamic-inventory/17643/2 "2015-03-03T19:46:08Z")

</div>

The inventory script is only invoked at the beginning of the playbook run.

You'll have to call your provisioning and configure playbooks separately,  
or use add\_host ([http://docs.ansible.com/add\_host\_module.html](http://docs.ansible.com/add_host_module.html)) to update  
the inventory in memory after you have provisioned a host.

---

<div class="post-metadata">

**Author:** ![Rahul\_Mehrotra](https://avatars.discourse-cdn.com/v4/letter/r/5e9695/32.png) [@Rahul\_Mehrotra](https://forum.ansible.com/u/Rahul_Mehrotra)\
**Post date:** [March 3, 2015, 11:00pm UTC](https://forum.ansible.com/t/not-able-to-configure-server-using-ansible-dynamic-inventory/17643/3 "2015-03-03T23:00:24Z")

</div>

Thank you for the reply Chris,  
I would appreciate if you can provide an example of how we can do the in-memory inventory update. Thank you
