Get targeted host from schedule/job template via api


Is there an easy way to get the targeted hosts of a schedule/job template via the api.

I’ve got a lot of inventories subdivided in groups. I’ve got job templates that target hosts by filling in the “limit” (sometimes by prompt). These templates have a schedule to run during specific times in a month. The limit could be set in the schedule. some limits are easy (just one group) others use union and exclusions.

The number of schedules is steadily increasing.

Due to the increasing nature of templates/schedules it is getting hard to:

Q1:Determine what schedule is targeting what host
Q2 :Determine if a host has been targeted by a job_template/schedule

Manual solution:
Have a good naming convention so you can determine the group from the schedule name.
Open the job template → see the limit → go to inventory → group …

My automated solution:
Via api:
Read all schedules that have a next run in the next 30 days
Get the targeted inventory
get the template/workflow/schedule limit
run ansible-playbook with --list-hosts (on a script server)
parse output (on a script server)
get hosts (on a script server)

create an excel (shows schedule per host or host per schedule

Question: Can this be done faster/easier
This solution works but since part of this needs to be executed with “shell ansible-playbook with --list-hosts” makes it slow

It would be nice if there was an awx api endpoint that just returns the hosts given a limit and an inventory. Does something like this exists:


or other suggestions

1 Like

I don’t think this is possible with normal inventory

@AlanCoding would constructed inventory fit this usecase?

I think a constructed inventory could do this but then you change the “limit” functionality to all and a constructed inventory.
Also this would kind of make the host menu/list a mess since it list host multiple times (the original inventory and every constructed inventory).

I have a working solution as described in the original post. But yet I feel this is a QOL feature that could be most welcome in AWX.

Use cases:

  • If a scheduled tasks would have it’s host known you could add a “future job” on the host level next to the previous jobs.

  • When you launch a template you could list the targeted hosts in the preview section. I should not have to open a second tab and go to inventory → group → hosts to check if this is what I want to target.

PS: OMG its the real TheRealHaoLiu from AWX Office Hours