iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more
Need a server to try this on? Antihost offers Linux VPS plans with NVMe storage, full root access and a 14-day free trial.
Read system information through the ansible_facts dictionary. For example, use ansible_facts['distribution'] for the operating-system distribution and ansible_facts['os_family'] for its family. Playbooks normally gather these values automatically before running tasks, unless the play sets gather_facts: false.
Prefer dictionary lookups over older bare names such as ansible_distribution. The injected-name behavior is deprecated, and the default is planned to change in ansible-core 2.24, so using ansible_facts now avoids a migration failure later.
Free tools Windows power users keep installed
One-click scans. No signup required.
What Ansible facts are and when they exist
Ansible facts are variables describing a managed host. They can include operating-system identity, kernel and hardware details, network information, and other values returned by the fact-gathering module. In a playbook, the values are available after fact gathering has completed and can then be used in task arguments, conditions, templates, and assertions.
The automatic gathering step
When a play does not override the setting, Ansible inserts a fact-gathering step before the play’s ordinary tasks. The ansible.builtin.gather_facts module is part of ansible-core and normally uses the ansible.builtin.setup fact module. Use the fully qualified module name when calling it explicitly so the task is unambiguous.
#1 Best Overall
- Powerful Turbo Fan:CAGIWIRU Electric Air Duster have reached speed up to 130000RPM,Can efficient remove dust and debris.With LED light and Three Adjustable Speed to meet with different cleaning tasks.
- With Attached USB C Fasting Charging cable.Charing 3 hours,Enjoy up to 240 minutes of use on the lowest setting, For third speed can use for 25mins.with four charging options to meet with your needs.
- Wide Application:Upgraded attached 5 different nozzles,making it suitable for a variety of scenes, such as car,pet, pc, keyboards, and other electronic devices. It also serves for office and home clean duster.
- Handy Design & Portable:Cordless air duster electric nozzle is Light weight and small size, design and comfortable to hold and space saving, convenient to carry around. You can put it in your room or inside the car without taking up space.
- Warranty & Support: Our Electric air duster comes with 5 years warranty and 24/7 customer service. During this period, if you have any questions,pls kindly feel free to contact us.
- name: Gather host facts explicitly
ansible.builtin.gather_facts:
Automatic gathering applies per play. If a play disables it, facts are not magically available from that play unless an earlier task gathers them or another mechanism supplies equivalent variables.
Skipping the step
Set gather_facts: false at play level when the play does not need host information or when you intend to collect only a controlled subset later.
- name: Run a task without automatic fact gathering
hosts: all
gather_facts: false
tasks:
- name: Perform an operation that needs no host facts
ansible.builtin.debug:
msg: 'Fact gathering was skipped for this play'
If a later task references ansible_facts in this play, expect an undefined-variable error unless you add a gathering task first.
Use the ansible_facts dictionary correctly
Keys do not include the ansible_ prefix
The dictionary stores the fact name without the ansible_ prefix. Therefore, the correct forms are:
| Information | Correct expression | Do not use inside the dictionary |
|---|---|---|
| Operating-system distribution | ansible_facts['distribution'] |
ansible_facts['ansible_distribution'] |
| Operating-system family | ansible_facts['os_family'] |
ansible_facts['ansible_os_family'] |
| System type | ansible_facts['system'] |
ansible_facts['ansible_system'] |
The second column is the form to put in Jinja expressions. Adding ansible_ to the key asks for a different dictionary member and normally produces an undefined value.
Display one fact while developing
The debug module can print a single value or the complete dictionary. Printing one value is easier to read and avoids flooding the terminal with host data.
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Clear out junk files and repair common Windows errors3Fix the driver behind crashes, sound loss and screen glitches- name: Show the distribution
ansible.builtin.debug:
msg: "Distribution: {{ ansible_facts['distribution'] }}"
- name: Show the operating-system family
ansible.builtin.debug:
msg: "Family: {{ ansible_facts['os_family'] }}"
- name: Inspect every gathered fact
ansible.builtin.debug:
var: ansible_facts
Use single quotes around the dictionary key in Jinja when the surrounding YAML string uses double quotes. That quoting style keeps the expression readable and avoids accidental YAML parsing changes.
Rank #2
- Screen Cleaner is Your Screen’s New Bestfriend! - EVEO is proud to present a screen cleaner that’s perfectly suited for your TV. Meet your new screen cleaner, computer screen cleaner, laptop cleaner, iPad cleaner, Macbook,tv cleaner or any other electronic device. Our screen cleaner spray and wipe along with the included plush microfiber cloth, easily removes dust, fingerprints & other smudges on the screen’s surface. Clean effectively for a streak-free screen
- Gentle on your Screens - Our screen cleaner spray and wipes is compatible to be used even for the most sensitive LCD, LED, CRT, and OLED screens in proper use. Be at ease knowing that this product is compatible with all the major brands: LG, SONY, Samsung, Sharp, iPad, iPhone, Android screens, Kindle, PC monitors - we’ve got you covered! Can be used as LCD screen cleaner, tv cleaner, smart tv screen cleaner, and more
- Premium Super Soft Plush Microfiber Cloth - Included in this efficient screen cleaning kit. This screen cleaner spray and wipe has our signature plush microfiber cloth specially designed to comply with screens and monitors and leave them streak-free. Has been shown to effectively absorbs stubborn stains, zero streaks, and no fiber shedding. Always use this together with our screen cleaner for the best results
- Easy-to-Use Screen Cleaner Kit + microfiber cleaning cloth - The EVEO Screen Cleaning Kit will easily be your new favorite tool when it comes to taking care of the things you love most, quick and easy solution for a streak-free screen. Simply screw on the sprayer gun on the screen cleaner bottle. Spray the cleaning liquid onto the microfiber cloth, then wipe the screen until desired cleanliness & shine is achieved.
- Quality Screen Care Kit Worth Purchasing - Enjoy a convenient Screen Cleaner anytime, anywhere you need it. Your satisfaction is our top priority. We stand behind the quality of our products and that’s why, you shouldn’t be worrying at all. We manufacture the Best Screen Cleaner. and can be used for laptop cleaning kit, laptop screen cleaner, tv screen cleaner for smart tv. MacBook screen cleaner, monitor cleaner or screen cleaner spray for electronic devices with microfiber cleaning cloth
Use facts in conditions
Facts are ordinary variables once gathered, so a task can branch on them with when. The expression should contain the dictionary lookup, not the older injected variable name.
- name: Run a family-specific task
ansible.builtin.debug:
msg: 'This host belongs to the RedHat family'
when: ansible_facts['os_family'] == 'RedHat'
- name: Run a distribution-specific task
ansible.builtin.debug:
msg: 'This host reports Debian'
when: ansible_facts['distribution'] == 'Debian'
Put the condition on the task that needs it. This makes the dependency on the gathered value visible and prevents a fact-based branch from being mistaken for a static inventory variable.
Use facts in templates and task arguments
The same syntax works in a template, a command argument, or a module parameter.
PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware match- name: Create a file whose content identifies the host system
ansible.builtin.copy:
dest: /tmp/system-information.txt
content: "distribution={{ ansible_facts['distribution'] }}
system={{ ansible_facts['system'] }}
"
Keep the lookup in the expression wherever it is used. Do not convert it to a bare ansible_distribution variable simply because an older example uses that spelling.
A complete playbook pattern
The following play gathers facts, reports selected values, and takes a family-specific branch. It uses only the dictionary form, so it remains understandable when injected variables are disabled.
---
- name: Inspect system information
hosts: all
gather_facts: true
tasks:
- name: Report the host's basic platform facts
ansible.builtin.debug:
msg:
- "Distribution: {{ ansible_facts['distribution'] }}"
- "OS family: {{ ansible_facts['os_family'] }}"
- "System: {{ ansible_facts['system'] }}"
- name: Handle RedHat-family hosts
ansible.builtin.debug:
msg: 'Apply the RedHat-family procedure here'
when: ansible_facts['os_family'] == 'RedHat'
- name: Handle Debian-family hosts
ansible.builtin.debug:
msg: 'Apply the Debian-family procedure here'
when: ansible_facts['os_family'] == 'Debian'
gather_facts: true is shown explicitly in this example even though it is the normal default. Being explicit helps readers see why the values are available and makes a later change to the play easier to review.
Control what gets collected
Limit collection when full setup is unnecessary
For a play that needs no host metadata, disable automatic collection as shown earlier. A tutorial-based approach also describes using gather_subset to request categories such as network or hardware information instead of the full setup result. Treat the exact subset names and behavior as version-sensitive and verify them against the documentation for the ansible-core version installed in your environment.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Rank #3
- 【Large size】:Measuring 800 x 300 mm/ 31. 5×12 inches, which is wider and taller than others. Large mouse pad can perfectly fit your keyboard and mouse of any size, and there is also ample space for peripherals such as phones, tablets, etc.
- 【LED backlight mouse pad】:Blade Hawks RGB mouse pad provides 7 static modes and 7 dynamic modes will give you the options you are looking for. Power-off memory function remembers the last lighting mode you selected. The super glow fiber Chroma will give you a colorful gaming setup that you want.
- 【Anti-slip rubber base】:Made from Natural rubber, this gaming mousepad will firmly grip your desktop, allowing you to enjoy the ultimate precision in the games you are most passionate about. It also comes with a texture that enhances this ability even further.
- 【Smooth and waterproof surface】: Micro-textured cloth surface, for extremely precise mouse control and a smooth movement. When liquid splashes on the gaming mouse pad, it forms water droplets and slides down. Will not delay your work or gameplay.
- 【Plug and play】: This mouse and keyboard pad is powered by USB, plug and play, no driver required. One button control light modes. Press one time to change the lighting mode, press twice to change the brightness, press and hold about 3 seconds turn ON/OFF.
- name: Gather only a selected category
hosts: all
gather_facts: true
gather_subset:
- network
tasks:
- name: Continue with network-related work
ansible.builtin.debug:
msg: 'Selected fact collection completed'
If a task later needs a fact outside the selected category, either broaden the subset or gather the complete set. A missing key is usually a collection choice, not evidence that the host has no such property.
Understand parallel and serial fact modules
The gather-facts module can run fact modules in parallel. Its parallel toggle controls that behavior; serial execution provides deterministic merge order when several fact modules contribute values. Parallel collection can reduce waiting time, while serial collection is useful when merge order matters for your fact modules.
- name: Gather facts serially
ansible.builtin.gather_facts:
parallel: false
Use this option deliberately. Changing it does not change the dictionary syntax; it changes how the fact modules are executed and merged.
Inspect facts outside a playbook
For a quick inventory-wide inspection, run the fully qualified gather-facts module ad hoc:
Recommended Free Tools
ansible all -m ansible.builtin.gather_facts --tree /tmp/facts
The command writes each host’s gathered facts to a file below /tmp/facts. This is useful when you want to examine the returned structure without editing a playbook. Check the individual host files to confirm the exact key spelling and value before writing a conditional around it.
Ad hoc collection does not alter the dictionary syntax used by a playbook. In both cases, a value such as the distribution is read as ansible_facts['distribution'].
Why ansible_distribution still appears—and why to replace it
Injected variables are a compatibility layer
Ansible can expose gathered facts twice: in the ansible_facts dictionary and as top-level variables whose names look like ansible_distribution. The behavior is controlled by the INJECT_FACTS_AS_VARS setting. Its current default is True, and the injected form drops the ansible_ prefix only when it becomes a dictionary key.
Rank #4
- 【Softer and More Comfortable】Vaydeer wrist rest has unique diamond pattern, which is the combination of softness and aesthetics. The materials of wrist rest are improved into higher quality memory foam and covered with silky smooth lycra. The computer wrist rest makes you as comfortable and cushiony as like rest your wrists on clouds.
- 【Ergonomic Wrist Saver】The wrist rests for keyboard and mouse comes with a 17.32×3.15×0.83 inch keyboard wrist pad and a 5.94×3.15×0.83 inch mouse wrist support. Based on ergonomic design, the unique concave shape is the perfect fit for your wrist joints. The wrist rest pad fits most computer keyboards and laptops, improve hand and wrist posture, release your wrist and arm stress.
- 【Non-Slip Rubber Bottom】Featuring an anti-skid silicone base on the bottom, this wrist keyboard support stays firmly in place on your desk, preventing the padding from sliding around, ensuring stable and consistent wrist support during extended computer sessions.
- 【Better Experience & Pain Relief】Our keyboard arm rest is beneficial to alleviate the soreness caused by direct contact and friction between your arm and a hard desk surface, reducing the risk of wrist fatigue or carpal tunnel. The soft texture of memory foam can evenly distribute the pressure around your wrists and provide good support with just enough give.
- 【Helpful in Multiple Scenarios】Whether you're working, studying, writing, typing, gaming, this keyboard and mouse rest combo is an essential accessory to add comfort and support to your hands and wrists. It’s also a great gift for men, women, family, friend, coworker, gamer, teacher, etc.
That compatibility behavior is deprecated. Accessing an injected name can produce a deprecation warning recommending the dictionary expression instead. Replace code such as:
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →- name: Legacy form
ansible.builtin.debug:
msg: "{{ ansible_distribution }}"
with:
- name: Supported dictionary form
ansible.builtin.debug:
msg: "{{ ansible_facts['distribution'] }}"
Prepare for the planned default change
Ansible porting guidance and a related community discussion report a planned change in ansible-core 2.24: the default for INJECT_FACTS_AS_VARS is expected to switch to False. The change is planned rather than a guarantee of a particular release date, but it is a practical upgrade risk. A playbook that relies on ansible_distribution can stop working when injection is disabled even though fact gathering itself still succeeds.
Warnings have been reported for ansible-core 2.20 and later. The linter does not currently report this particular deprecation, so a clean lint run is not proof that all injected fact names have been removed.
Test with injection disabled
Use the inject_facts_as_vars option in the [defaults] section of ansible.cfg to test the non-injected behavior before upgrading. Set it to the disabled value for your ansible-core version, run the complete playbook suite, and fix every undefined reference by converting it to ansible_facts['key']. Also check the configuration dump for the environment-variable spelling supported by the installed version; do not copy an environment-variable name from a different release without verifying it.
[defaults]
inject_facts_as_vars = False
Keep the setting change in a test configuration first. The goal is to expose assumptions in CI and development, not to hide warnings by changing production configuration.
Special case: community.sops.load_vars
The porting guidance calls out community.sops.load_vars as a known caveat. Some versions of that plugin can emit repeated injected-fact warnings because the plugin did not have an alternative way to set variables at the time of the guidance. The same guidance advises against mechanically changing SOPS-loaded variables to ansible_facts. Treat those warnings as a plugin-specific case and follow the plugin and porting guidance for the exact version you run.
Troubleshoot facts that are missing or undefined
Check whether the play disabled gathering
First inspect the play header for gather_facts: false. If it is present, either remove it or add an explicit gathering task before the first fact-dependent task:
Best Value
- 【No Drill Mounted】Cable management tray can be assembled in as little as 3 minutes or less-simply. Side clips easily clampe the edge of desk, pass through the holes on the sides, and secure excess cables with baskets. Desk cable management supports inward or outward installation to meet your needs in different scenarios, and provides you with great convenience when collecting and organizing wires.
- 【Rubber Pad Protects Desk】Wire organizer under desk built-in soft rubber pads on the clamp protect your desk from scratches, so you will not damage your furniture or office.
- 【Sturdy and Beautiful】Cord management under desk is made of high-quality carbon steel and holds about 15 lbs. The wire basket has 2 holes on each side of the tray to enable your cables to pass freely. Cable baskets are suitable for desk thickness use from 0.4" to 2.4".
- 【Space Saving & Keep Organized】Desk cable management tray holds all your power cords, outlet strips, USB hubs and computer transformers hidden from your feet, and the data cables will not enter the vacuum cleaner to keep your desk clean and tidy. Desk wire organizer is also suitable for use in the kitchen and outdoors.
- 【Reduce Safety Risks】Cable tray under desk keeps all plugs away from your kids, no more worry about tripping. Using 2 holes wire tray saves extra space, helps you easily cabling and wire protection. The mesh design is not easy to accumulate dust, but avoids safety accidents caused by messy wires.
- name: Gather facts after an intentionally skipped setup step
ansible.builtin.gather_facts:
Remember that a setting on one play does not automatically provide facts to another play. Each play has its own gathering behavior.
Check the key spelling and prefix
If ansible_facts['ansible_system'] is undefined, the problem is the extra prefix. Use ansible_facts['system']. If ansible_system is undefined while the dictionary value exists, injection is disabled or unavailable; changing the code to the dictionary form is the durable fix.
Check whether a subset omitted the value
A restricted gather_subset can leave unrelated categories uncollected. Temporarily gather the complete fact set, inspect the resulting dictionary, and then choose the smallest subset that still contains every key your tasks require.
Check the actual returned structure
Use ansible.builtin.debug with var: ansible_facts or the ad hoc --tree command to see what the host reported. This distinguishes a spelling error from a genuinely absent or uncollected value and avoids guessing at key names.
Check the controller and host versions
Deprecation behavior is tied to ansible-core versions. Record the controller’s ansible-core version when reproducing a warning, then test with the same version and with the injection setting disabled. A playbook can appear healthy on an older controller simply because the compatibility variables are still injected there.
A migration checklist for existing playbooks
- Search tasks, handlers, templates, and included files for bare names beginning with
ansible_, especiallyansible_distribution,ansible_os_family, andansible_system. - For each match, remove the prefix from the dictionary key and write
ansible_facts['key']. - Confirm that the relevant play gathers facts, either through the default or an explicit
ansible.builtin.gather_factstask. - Review any
gather_subsetrestriction to ensure it includes every fact the converted task uses. - Run the playbook with injected fact variables disabled in a test configuration.
- Exercise every operating-system branch, because an untested branch can retain a legacy lookup even when the main path has been converted.
- Record and investigate deprecation warnings on ansible-core 2.20 or newer; do not rely on ansible-lint to find this particular issue.
- Retest before adopting an ansible-core release in which the planned default for
INJECT_FACTS_AS_VARSmay be disabled.
Common mistakes and their fixes
| Mistake | What happens | Fix |
|---|---|---|
Using ansible_facts['ansible_distribution'] |
The dictionary key includes an extra prefix and is not the normal fact name. | Use ansible_facts['distribution']. |
Using ansible_distribution everywhere |
The play depends on deprecated injected variables and may fail when injection is disabled. | Convert to the dictionary form. |
Setting gather_facts: false and then reading facts |
The dictionary is absent or lacks the expected values. | Enable gathering or call ansible.builtin.gather_facts before the dependent task. |
| Assuming a limited subset contains every category | A valid key is missing because it was not collected. | Broaden the subset or gather the full set, then verify with debug. |
| Silencing warnings by changing only configuration | Legacy references remain and can break after an upgrade. | Use the configuration change only for testing; update the playbook expressions. |
Practical design rules
- Use
ansible_facts['key']as the single interface in new code. - Keep fact gathering visible in the play header or as an explicit task when the play’s behavior depends on it.
- Use fully qualified module names such as
ansible.builtin.gather_factsandansible.builtin.debug. - Inspect the returned dictionary before adding a conditional for a key you have not used on that host class.
- When limiting collection, document which categories the tasks require and test that the subset still supplies them.
- Treat the 2.24 injection change as a compatibility deadline, while recognizing that the exact release behavior is planned and can change.
What to remember
The reliable pattern is simple: gather facts, then read the value from the dictionary without the ansible_ prefix. Use ansible_facts['distribution'], ansible_facts['os_family'], or ansible_facts['system'] as appropriate. If a value is missing, check gathering, subsets, and the exact returned key before changing anything else. Replacing injected names now is the safest way to keep playbooks working as ansible-core moves toward disabling that compatibility layer.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

