Selecting hosts with softlayer.py dynamic inventory

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”,
“fullyQualifiedDomainName”: “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:

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.

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.

Hello Kesten,

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

esco