--limit and groups variable inconsistency

Hi,

I use dynamic ec2 inventory.

i tag hosts with tag ENV and call ansible with --limit tag_ENV_staging to get only hosts of staging
At the same time, i have another ENV called production

in my template i use loop on groups[‘mgmt’] to get list of all ‘mgmt’ hosts to put them to some config file

{% for host in groups[‘mgmt’] %}{{ hostvars[host][ec2_private_ip_address] }}{% if not loop.last %},{% endif %}{% endfor %}

but i got both staging and production hosts, but template is updated only on staging

it is possible that --limit has bug or groups is not respect --limit??

ansible version 1.9.2

limit affects the hosts: in a play, not the information about hosts in
each group, what you want to do is loop over an intersection:

groups['mgmg']|intersect(groups['tag_ENV_staging')])

or if you want it dynamically, you can use play_hosts (list of current
hosts in play)

groups['mgmg']|intersect(play_hosts)

Ok, i understand,
Your solution is good for me… Thanks.

But, maybe, you need to add some explanation to docs or add additional var current_groups/limited_groups ??

Anatoly, please also be aware that you might be bitten by https://github.com/ansible/ansible/issues/12174 .

no, this is not my case