# Confused By EC2 Dynamic Inventory

**URL:** <https://forum.ansible.com/t/confused-by-ec2-dynamic-inventory/22407>\
**Category:** Ansible Project\
**Created:** [August 28, 2016, 4:33pm UTC](https://forum.ansible.com/t/confused-by-ec2-dynamic-inventory/22407 "2016-08-28T16:33:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jon\_Forrest](https://avatars.discourse-cdn.com/v4/letter/j/a698b9/32.png) [@Jon\_Forrest](https://forum.ansible.com/u/Jon_Forrest)\
**Post date:** [August 28, 2016, 4:33pm UTC](https://forum.ansible.com/t/confused-by-ec2-dynamic-inventory/22407/1 "2016-08-28T16:33:50Z")

</div>

I'm 90% done with a problem. The remaining 10% requires using  
EC2 dynamic inventory, but I'm missing something important.  
I'm creating two instances ('frontend' and 'backend') where  
backend only allows SSH access from frontend, and nowhere else.  
Backend runs MySQL so I want to limit MySQL logins  
to only from frontend. This is trivial to do manually  
but I want to do it from an Ansible playbook.

There are 2 things I still need to do:

1) Add a rule to the security group used by backend to  
allow access for SSH and MySQL only from frontend.

2) Without using dynamic inventory I've had to populate  
the hosts file with lines like:

frontend ansible\_ssh\_host=52.32.251.105  
backend ansible\_ssh\_host=52.27.199.119

I'd want to somehow do this dynamically.

I've looked at both the Ansible docs and an excellent page  
at [https://djaodjin.com/blog/deploying-on-ec2-with-ansible.blog.html](https://djaodjin.com/blog/deploying-on-ec2-with-ansible.blog.html)  
(see below) but I'm not seeing how to accomplish these 2 tasks.

I know about the ec2.py script, which I can successfully run manually,  
but I don't know how to incorporate what it produces into a playbook.

I'd appreciate any help.

Cordially,  
Jon Forrest

P.S. What I'm confused about in the djaodjin page is where he lists  
basic-delete.yml and shows this line:

hosts: security\_group\_\*my-security-group\* # \<-- MAGIC IS HERE!

I'm guessing that somehow this is invoking the ec2.py script but I  
don't see how.

---

<div class="post-metadata">

**Author:** ![ZillaYT](https://avatars.discourse-cdn.com/v4/letter/z/4da419/32.png) [@ZillaYT](https://forum.ansible.com/u/ZillaYT)\
**Post date:** [August 29, 2016, 5:59pm UTC](https://forum.ansible.com/t/confused-by-ec2-dynamic-inventory/22407/2 "2016-08-29T17:59:43Z")

</div>

Provide the whole “ansible-playbook” command line you’re invoking.
