# Selecting hosts with softlayer.py dynamic inventory

**URL:** <https://forum.ansible.com/t/selecting-hosts-with-softlayer-py-dynamic-inventory/19442>\
**Category:** Ansible Project\
**Created:** [October 6, 2015, 10:30am UTC](https://forum.ansible.com/t/selecting-hosts-with-softlayer-py-dynamic-inventory/19442 "2015-10-06T10:30:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bedwyr\_Humphreys](https://avatars.discourse-cdn.com/v4/letter/b/f07891/32.png) [@Bedwyr\_Humphreys](https://forum.ansible.com/u/Bedwyr_Humphreys)\
**Post date:** [October 6, 2015, 10:30am UTC](https://forum.ansible.com/t/selecting-hosts-with-softlayer-py-dynamic-inventory/19442/1 "2015-10-06T10:30:13Z")

</div>

Hi,

I’m trying to use a dynamic inventory to configure Softlayer hosts. My scripts are working with a static inventory file where I specify things like

[BACKUP\_SERVER]  
10.000.00.00  
[JIRA]  
10.111.11.11

Now i want to move to using a dynamic inventory using softlayer.py from ansible/contrib/inventory

This returns the following structure:

**{**  
**“\_meta”: {**  
**“hostvars”: {**  
**“159.xxx.xx.xx”: {**  
**“datacenter”: {**  
**“id”: 999,**  
**“longName”: “Xxxx 2”,**  
**“name”: “xxx02”,**  
**“statusId”: 2**  
**},**  
**“domain”: “[softlayer.com](http://softlayer.com)”,**  
**“fullyQualifiedDomainName”: “[xxxx.softlayer.com](http://xxxx.softlayer.com)”,**  
**“globalIdentifier”: “xxxx-xxx-xxxx-xxxx-xxxxxxxxxx”,**  
**“hostname”: “yyyyy”,**  
**“id”: 11327741,**  
**“maxCpu”: 1,**  
**“maxMemory”: 8192,**  
**“powerState”: {**  
**“keyName”: “RUNNING”,**  
**“name”: “Running”**  
**},**  
**“primaryBackendIpAddress”: “10.XXX.XX.XX”,**  
**“primaryIpAddress”: “159.XXX.XXX.XX”,**  
**“status”: {**  
**“keyName”: “ACTIVE”,**  
**“name”: “Active”**  
**},**  
**“tagReferences”: []**  
**}**

…

So my questions are … how do I filter hosts in a playbook with a dynamic inventory?

I would have previously done:

---

<div class="post-metadata">

**Author:** ![Kesten\_Broughton](https://avatars.discourse-cdn.com/v4/letter/k/41988e/32.png) [@Kesten\_Broughton](https://forum.ansible.com/u/Kesten_Broughton)\
**Post date:** [October 7, 2015, 1:28pm UTC](https://forum.ansible.com/t/selecting-hosts-with-softlayer-py-dynamic-inventory/19442/2 "2015-10-07T13:28:09Z")

</div>

We are needing the same thing.

My understanding is that the inventory modules are expected to be modified for your own needs.  
We modified ec2.py to strip off the ec2\_tag prefix so that we could group things without renaming all roles to ec2\_tag… or having to write a large and rapidly changing config hosts file.

Our difficulty is that limiting with ec2.py is done via ec2.ini and this forces a workflow of templating out ec2.ini in stage 1 and using it in stage 2.  
This frequently causes mis-targeting.

The problem seems to me that --limit is not passed through to the inventory modules.

Is there a design choice for this, or could ansible inventory module be modified to allow this (and perhaps other efficiency filters like region)?

Right now, limit is only applied after the inventory is gathered which makes the group ‘all’ your entire fleet rather than that specified by --limit.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [October 7, 2015, 7:07pm UTC](https://forum.ansible.com/t/selecting-hosts-with-softlayer-py-dynamic-inventory/19442/3 "2015-10-07T19:07:44Z")

</div>

play\_hosts has the list of 'current hosts in play', passing limit to  
the inventory will break several things. For example plays that rely  
on data from groups not targeted (i.e. db servers whitelisting  
app\_servers) in play and will require updates to all existing  
inventory scripts.

---

<div class="post-metadata">

**Author:** ![esco\_real](https://avatars.discourse-cdn.com/v4/letter/e/c89c15/32.png) [@esco\_real](https://forum.ansible.com/u/esco_real)\
**Post date:** [October 7, 2015, 8:03pm UTC](https://forum.ansible.com/t/selecting-hosts-with-softlayer-py-dynamic-inventory/19442/4 "2015-10-07T20:03:49Z")

</div>

Hello Kesten,

you should check out this links:  
[https://github.com/ansible/ansible/pull/12451https://groups.google.com/forum/#!topic/ansible-devel/ZGwvE7RgWTc](https://github.com/ansible/ansible/pull/12451https://groups.google.com/forum/#!topic/ansible-devel/ZGwvE7RgWTc)

esco
