To use the setup module in Ansible, follow these steps:
-
Basic Command: You can run the
setupmodule to gather facts about a specific host. Use the following command:ansible <target_host> -m setupReplace
<target_host>with the name of your target host (e.g.,localhost). -
Filtering Facts: If you want to retrieve specific facts, you can use the
filterargument. For example, to get only the operating system distribution facts:ansible <target_host> -m setup -a "filter=ansible_distribution*" -
Running in a Playbook: You can also include the
setupmodule in an Ansible playbook. Here’s a simple example:- hosts: all tasks: - name: Gather facts setup: -
Viewing Output: The output will include various facts about the target host, such as its OS, network interfaces, and hardware details.
Using the setup module is a great way to gather information about your managed hosts, which can help in making decisions in your playbooks. For more practice, consider checking out related labs on LabEx!
