This has come up once or twice.
When limiting, you can't get facts from other hosts.
The solution is to not use --limit and instead do:
hosts: "mygroup:{{ limit_spec }}"
and pass "-e limit_spec=what_I_would_have_passed_to_limit"
This allows patterns like:
- hosts: all
tasks: [] # gather facts
- hosts: mygroup:{{ limit_spec }}"
tasks:
-
And you can still rely on the previous gathered steps without limiting execution to just those hosts.
For bonus points, take the colon off...
- hosts: mygroup{{ limit_spec | default('') }}
And then on the CLI:
-e "limit_spec=:&webservers"
And if no limit is specified, it works like you would want.