Saving Ansible Inventory File Path

From bib. source

[…] we specified the path to the inventory file on the command line using -i hosts.ini. But we can avoid having to specify this path every time we run ansible commands by specifying the path to the inventory file in an ansible.cfg file that is also stored in the root directory of your project.

Essentially, as long as ansible is run with the i option taking an argument that is the filepath, or path, of the inventory file, Ansible will know what our inventory file is or what inventory file to use (Geerling 2023, 22). An example of running such a command is as follows (and as seen here):

ansible -i ${INVENTORY_FILE_PATH}

So as not to need to add -i ${INVENTORY_FILE_PATH to the ansible command, the inventory file path can be declared in an ansible.cfg file at the root of the Ansible project, exemplified as so (Ibid):

[defaults]
inventory = path/example_inventory_file.ini

bash_script bash_scripting command_line bash configuration_management configuration_file inventory_file graph_theory Bourne_Again_Shell Bourne_Again_Shell_script Bourne_Again_Shell_scripting


bibliography

  • “Ad-Hoc Commands.” In Ansible for DevOps: Server and Configuration Management for Humans, 2nd ed., 18–46. Leanpub, 2023.