Ansible has a module called: gather_facts. This module runs by default at the start of each playbook to gather the facts about remote hosts.