Obtain --limit parameter in playbook

Hi, I have had twice now the use case of needing to access host vars of a specific host, without knowing the inventory hostname.

I would like to suggest to be able to read the value of the --limit parameter from inside a playbook.
Maybe something like an ansible_limit magic variable, which has as value an array of the “:” (colon) separated parts.

Then one could use jinja2 tests to figure out the target-host from that.

The use case for this is a playbook to configure a development environment for a specific developer, without having to edit any files at all, so the target host needs to be supplied as a parameter.
At the same time, I would like to avoid --extra_vars “target_host=”, because right now, I need both:

ansible-playbook setup-and-deploy-development -i inventory/vsphere --limit my-developer-vm.example.com:localhost --extra-vars “target_host=my-developer-vm.example.com

I know in this case I could get rid of the “–limit” and put “{{ target_host }}” everywhere, but like I said, would like to avoid that…

Can anybody help me with this?

I want to know from inside the playbook, what was passed to the --limit parameter (e.g. “my-vm.my-domain.com:localhost”)

The reason I cannot just connect to the “my-domain” machine, is that I want to read an inventory variable, (the MAC address) before the machine even gets created, so creative usage of set facts and delegation does not help me much I am afraid.

To my knowledge you can't.
But you have ansible_play_batch variable that contains all the host in the play, maybe that helps you.