Is it possible to export inventory to a file?

Hi.
I need to import and export inventories. I can import inventory from a file but I couldn’t figure out if there is a way to export inventory to a file?
I wonder if there is a easy way to do that? Any suggestion?

I wrote below script that run sql queries on awx database and print hosts as inventory format. Putting here in case someone needs it.

`

#!/bin/bash

PSQL=/usr/bin/psql

DB_USER=awx
DB_NAME=awx

function run_sql(){
docker exec awx_postgres_1 $PSQL
-X
-U $DB_USER
-c “$1”
–single-transaction
–set AUTOCOMMIT=off
–set ON_ERROR_STOP=on
–no-align
-t
–field-separator ’ ’
–quiet
-d $DB_NAME

}

function get_host_name(){
echo grep "^$1 " /tmp/awx_hosts | cut -d" " -f2
}

run_sql “select id, name from main_host” > /tmp/awx_hosts

run_sql “select id, name from main_group” | while read group_id group_name ; do
echo “[$group_name]”
run_sql “select host_id from main_group_hosts where group_id=‘$group_id’” | while read host_id; do

get_host_name $host_id
done
echo
done

rm -f /tmp/awx_hosts

`

İbrahim,

AWX provides an API endpoint that will generate an inventory for you in JSON format:

curl -ks “https://user:pass@awx.example.org/api/v2/inventories/1/script/” | python -m json.tool

{
“all”: {
“hosts”: [
“localhost”
]
}
}