Lauching template job via api on custom host (ie. not on an inventory)

Hi all, i don’t know if this is really possibile or i can use tower/awx for this.
Anyway, i’d like to setup a trigger on my monitoring system that, if the trigger is fired on a particular host, launches a template/job/playbook on that host.

For example, a trigger for “low disk space” is fired for host myhost.local on my monitoring software.
The trigger generates an action that will call via REST API a template on my tower server, ie. a POST to http://tower.local/job_templates/13/launch/ .

Now, the job will be lauched for the inventory associated to htat template but i’d like the job to be run only on myhost.local.

I know i can pass an inventory id via REST API but really id’ like to pass only a host .

How can i do that? Does it make sense?
Do i have to: create an inventory containing myhost.local → get that inventory id → pass the inventory id via POST when launching template → delete the inventory ?

Thanks!

Hi,

You may be able to pass host.local as parameters within content to enable an API using “limit”

`

{
“name”: “”,
“description”: “”,
“job_type”: “run”,
“inventory”: null,
“project”: null,
“playbook”: “”,
“scm_branch”: “”,
“forks”: 0,
“limit”: “”,
“verbosity”: 0,
“extra_vars”: “”,
“job_tags”: “”,
“force_handlers”: false,
“skip_tags”: “”,
“start_at_task”: “”,
“timeout”: 0,
“use_fact_cache”: false,
“host_config_key”: “”,
“ask_scm_branch_on_launch”: false,
“ask_diff_mode_on_launch”: false,
“ask_variables_on_launch”: false,
“ask_limit_on_launch”: false,
“ask_tags_on_launch”: false,
“ask_skip_tags_on_launch”: false,
“ask_job_type_on_launch”: false,
“ask_verbosity_on_launch”: false,
“ask_inventory_on_launch”: false,
“ask_credential_on_launch”: false,
“survey_enabled”: false,
“become_enabled”: false,
“diff_mode”: false,
“allow_simultaneous”: false,
“custom_virtualenv”: null,
“job_slice_count”: 1
}

`

Hi Fabio, thanks for you answer, I’ll give it a try.
However, I managed to get the desired behaviour just setting hosts value as a var, like

hosts: {{ host_to_check }}

and passing the desired host in extra_vars like

{ “extra_vars”: { “host_to_check”: “my host.local” } }

This wasn’t working before until I flagged the prompt checkbox for extra_vars in template.

Thanks!

Hello aquilinux. Was wondering if you knew what I might be doing wrong or what might have changed. When using your example I get the below errors. Thanks for your time.

`

[WARNING]: provided hosts list is empty, only localhost is available. Note

3
that the implicit localhost does not match ‘all’

4

5
[WARNING]: Could not match supplied host pattern, ignoring:

`