Forrest logo
back to the ansible tool

ansible:tldr:df825

ansible: List the groups in an inventory.
$ ansible localhost -m debug -a '${var=groups-keys()}'
try on your machine

This command is using the Ansible command-line tool (ansible) to perform a specific task on the local machine (localhost).

The -m parameter specifies the Ansible module to use, in this case, it's the debug module. The debug module is useful for displaying debug information or variables during playbook execution.

The -a parameter specifies the arguments to pass to the module. In this case, the argument is ${var=groups-keys()}.

groups-keys() is an Ansible function used to retrieve a list of all the group names defined in the inventory file. It returns a comma-separated string of group names.

${var=groups-keys()} assigns the result of groups-keys() to the var variable. The assignment (=) is in the Ansible variable format, which allows you to define variables inline in playbooks or command-line operations.

So, the command will execute the debug module on localhost and print out the value of the var variable, which will be the list of all group names defined in the inventory file.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the ansible tool