Version v2.7.0 of the documentation is no longer actively maintained. The site that you are currently viewing is an archived snapshot. For up-to-date documentation, see the latest version.
Use PostgreSQL as Ansible Inventory CMDB
Pigsty v2.7 normally reads its Ansible inventory from pigsty.yml. The release
also ships three scripts that can load that inventory into the pigsty schema
of the meta database and switch Ansible to a generated dynamic inventory.
The implementation in this page is tied to the v2.7.0 objects
bin/inventory_load,
bin/inventory_cmdb,
and bin/inventory_conf.
Prerequisites
The CMDB schema is created from
files/cmdb.sql
when the default pg-meta cluster is provisioned. Complete infra.yml and the
pg-meta database initialization first, then verify that the meta service is
reachable.
By default, ansible.cfg
contains:
Load the YAML inventory
bin/inventory_load reads a YAML inventory and replaces the rows in
pigsty.group, pigsty.host, pigsty.group_var, pigsty.host_var, and
pigsty.global_var. Back up or review the target CMDB before loading a new
inventory.
The script accepts -p|--path for the YAML file and -d|--data for the
PostgreSQL connection string. Its defaults come from PIGSTY_HOME and
METADB_URL.
Switch inventory source
Switch Ansible to the CMDB-backed inventory.sh:
bin/inventory_cmdb writes inventory.sh, makes it executable, and changes
the inventory entry in ansible.cfg. The generated script queries
pigsty.inventory through the meta PostgreSQL service.
Switch back to the static pigsty.yml inventory with:
These scripts only change the inventory source. Continue to edit and validate the source configuration deliberately; loading a new YAML file is not an automatic two-way synchronization mechanism.