Search code examples
ansibleansible-inventoryansible-tower

How to do inventory sync as soon as the inventory is created in ansible tower through script (in an automated fashion)


I wanted to understand how to do inventory sync as soon as the inventory is created using schedules (something like below) :

tower-cli schedule create --name sync_schedule --inventory-source 182 --rrule "DTSTART:20190507T183000Z RRULE:FREQ=DAILY;INTERVAL=1;COUNT=1"

Wanted to figure out rrule to sync once as soon as it is created.


Solution

  • Solution is to set "update_on_launch" value to true in API call:

    curl  --silent -lk  -u $user:$password -H 'Content-Type:application/json' -XPOST -d '{"name": '\"$project_name\"',"inventory": '\"$inventory_id\"',"source_script": 4,"credential": null,"overwrite_vars": true,"overwrite": true,"update_on_launch": true,"verbosity": 1,"update_cache_timeout": 0,"source_regions":"","source_vars":"---\nTERRAFORM_ENV: stl/'$project_name'","source":"custom"}' https://awx.com/api/v2/inventory_sources/