Hi,
Is there an easy way to get the targeted hosts of a schedule/job template via the api.
Situation:
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.
Problems/questions
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:
Q1
Have a good naming convention so you can determine the group from the schedule name.
Q2:
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:
/api/v2/get_targeted_hosts?inventory_id=X&limit=groupA:groupB!group3
or other suggestions