DevOps / Ansible Interview questions
What are Ansible facts?
Facts are pieces of information Ansible automatically discovers about a managed host at the start of a play, such as its IP addresses, OS distribution, kernel version, mounted filesystems, and available memory. They're gathered by the built-in setup module, which runs implicitly unless gather_facts: false is set.
- name: Show the OS family ansible.builtin.debug: msg: "This host runs {{ ansible_facts['os_family'] }}"
Facts let playbooks make conditional decisions based on a host's actual state, for example installing a different package name depending on distribution, without the playbook author needing to hardcode assumptions about every target. Because gathering facts takes time on every host, it can be disabled for plays that don't need them, or supplemented/replaced with fact caching for large inventories.
More Related questions...