Sobes.tech
Junior — Middle

Can you explain what is meant by factors in Ansible?

sobes.tech AI

Answer from AI

In Ansible, facts are automatically collected data about the target hosts where playbooks are executed. They include system information such as:

  • Operating system and its version
  • IP addresses and network interfaces
  • Hardware characteristics (CPU, memory)
  • Installed packages and much more

Facts are gathered using the setup module and are available in playbooks for decision-making, conditional operators, and configuration settings. For example, the ansible_os_family fact can be used to select the appropriate package depending on the OS family.

Example of using facts in a playbook:

- hosts: all
  tasks:
    - debug:
        msg: "Operating System: {{ ansible_os_family }}"
    - name: Install package for Debian
      apt:
        name: nginx
        state: present
      when: ansible_os_family == "Debian"