I'm not very familiar with Ansible but consider it to be somewhat interchangeable with Puppet (which I use extensively at work). You can certainly use Puppet to manage thousands of hosts but it entirely depends on other practices and technologies (an external node classifier in Puppet's case) to keep things manageable. I assume the same is true for Ansible.
Ansible is agentless, so the management of endpoints is entirely based on your server doing the scripting. It can use a static inventory file (text) or a dynamic one which can be served from anywhere (eg, sql query). Whenever you write playbooks you target groups of hosts based on tagging that’s done through inventory.