Ansible Facts
Ansible Facts: What They Are and How to Use Them
Ansible facts are variables that are automatically discovered by Ansible from a managed host. They can be used to gather information about the host and to customize the behavior of Ansible playbooks and roles. In this article, we’ll discuss what Ansible facts are, how to use them, and provide some examples. What Are Ansible Facts? Ansible facts are variables that are automatically discovered by Ansible from a managed host. They are collected during the execution of a playbook or role and can be used to customize the behavior of the playbook or role. Ansible facts are stored in a special variable called “ansible_facts” and can be accessed from any task or play. Ansible facts are collected by the setup module, which is automatically executed by Ansible when a playbook or role is executed. The setup module collects a variety of information about the managed host, such as operating system, IP address, memory, CPU, and disk information. This information is stored in the ansible_facts variable and can be used to customize the behavior of the playbook or role. How to Use Ansible Facts Ansible facts can be used to customize the behavior of a playbook or role. For example, you can use facts to determine the operating system of the managed host and then execute tasks that are specific to that operating system. You can also use facts to customize the behavior of a role. For example, you can use facts to determine the IP address of the managed host and then use that IP address to configure a web server. Examples of Ansible Facts Here are some examples of Ansible facts that can be collected from a managed host: • ansible_all_ipv4_addresses: A list of all IPv4 addresses assigned to the managed host. • ansible_architecture: The architecture of the managed host (e.g. x86_64). • ansible_distribution: The distribution of Linux running on the managed host (e.g. Ubuntu). • ansible_hostname: The hostname of the managed host. • ansible_interfaces: A list of all network interfaces on the managed host. • ansible_memtotal_mb: The total amount of memory (in MB) on the managed host. Conclusion Ansible facts are variables that are automatically discovered by Ansible from a managed host. They can be used to gather information about the host and to customize the behavior of Ansible playbooks and roles. In this article, we discussed what Ansible facts are, how to use them, and provided some examples.
Comments
Post a Comment