How to use setup module?

To use the setup module in Ansible, follow these steps:

  1. Basic Command: You can run the setup module to gather facts about a specific host. Use the following command:

    ansible <target_host> -m setup

    Replace <target_host> with the name of your target host (e.g., localhost).

  2. Filtering Facts: If you want to retrieve specific facts, you can use the filter argument. For example, to get only the operating system distribution facts:

    ansible <target_host> -m setup -a "filter=ansible_distribution*"
  3. Running in a Playbook: You can also include the setup module in an Ansible playbook. Here’s a simple example:

    - hosts: all
      tasks:
        - name: Gather facts
          setup:
  4. 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!

0 Comments

no data
Be the first to share your comment!