Ansible in a Minute · Ansible Core ·
Use delegate_facts to assign facts to the delegated host
Short answer
Use delegate_facts true so facts gathered with delegate_to are stored on the delegated host, not the play host.
Subscribe for updates
Get an email whenever we publish new guides and blog posts. Unsubscribe anytime.
By subscribing you agree we may email you about Ansible in a Minute and related Level Up Labs updates. We store your address in the same lead sheet as our contact form.
Request
gather facts on localhost and assign them to localhost with delegate_facts
Example
A quick heads-up: Every environment is different. Review and test this example before you run it on systems you care about.
---
- name: Assign setup facts to the delegated host
hosts: all
gather_facts: false
tasks:
- name: Gather facts on localhost and store them on localhost
ansible.builtin.setup:
delegate_to: localhost
delegate_facts: true
run_once: trueHow it works
By default, facts from a delegated task are assigned to inventory_hostname. Set delegate_facts to true to assign those facts to the delegated host instead.
When to use it
- Gathering facts from database hosts while targeting app servers
- Looking up hostvars for machines that are not the current play host
Requirements
- Ansible: >=2.14
Validation
- Syntax validated
- Not execution-tested
- Last verified 2026-09-16
Notes
A common pattern is delegate_to: "{{ item }}" with loop: "{{ groups['dbservers'] }}" and delegate_facts: true so each database host keeps its own facts while the play targets another group.
Reference
- Delegating facts (Ansible docs)
Built for every Ansible use case in every organization
BacklogZero can generate this kind of automation in your environment, just like it did here.