LIMIT as extra_vars

In AWX, you can pop-up ‘LIMIT’ option to limit the host list for playbook run.

Is it possible to take the value of LIMIT like --extra-vars

I have a python script to take the value from --extra-vars on playbook running and want to use the value of ‘LIMIT’ as well.

Thanks,
Jerry

Hi,

You may want to take a look at https://docs.ansible.com/ansible/latest/reference_appendices/special_variables.html
I think what you want is to use the ansible_limit variable.

Cheers!

Hi Jerry,

We do precisely this by setting an arbitrary variable with the ‘—limit’ value and using that variable in the ‘hosts’ field. It works just fine.

Rod

Hi Rod,

The python script I mentioned is ansible callback plugin
https://docs.ansible.com/ansible/latest/plugins/callback.html

When I use --extra-vars “host_limit=linux1”
the callback plugin takes the value like this

vm = play.get_variable_manager()
self.hosts = vm.extra_vars[“host_limit”]

In AWX, we would like to use the ‘LIMIT’ option instead of --extra-vars.

Do you know how the callback plugin can take the value of ‘LIMIT’?

Thanks,
Jerry