utils

4Modules69Plugins74Dependencies

Overview

Description

Ansible Collection with utilities to ease the management, manipulation, and validation of data within a playbook

Readme

Ansible Utilities Collection

Codecov CI

The Ansible ansible.utils collection includes a variety of plugins that aid in the management, manipulation and visibility of data for the Ansible playbook developer.

Support

As a Red Hat Ansible Certified Content, this collection is entitled to support through Ansible Automation Platform (AAP).

If a support case cannot be opened with Red Hat and the collection has been obtained either from Galaxy or GitHub, there is community support available at no charge.

You can join us on #network:ansible.com room or the Ansible Forum Network Working Group.

For more information you can check the communication section below.

Communication

For more information about communication, see the Ansible communication guide.

Ansible version compatibility

This collection has been tested against following Ansible versions: >=2.16.0.

For collections that support Ansible 2.9, please ensure you update your network_os to use the fully qualified collection name (for example, cisco.ios.ios). Plugins and modules within a collection may be tested with only specific Ansible versions. A collection may contain metadata that identifies these versions. PEP440 is the schema used to describe the versions of Ansible.

Included content

Filter plugins

NameDescription
ansible.utils.cidr_mergeThis filter can be used to merge subnets or individual addresses.
ansible.utils.consolidateConsolidate facts together on common attributes.
ansible.utils.fact_diffFind the difference between currently set facts
ansible.utils.from_xmlConvert given XML string to native python dictionary.
ansible.utils.get_pathRetrieve the value in a variable using a path
ansible.utils.hwaddrHWaddr / MAC address filters
ansible.utils.index_ofFind the indices of items in a list matching some criteria
ansible.utils.ip4_hexThis filter is designed to convert IPv4 address to Hexadecimal notation with optional delimiter.
ansible.utils.ipaddrThis filter is designed to return the input value if a query is True, else False.
ansible.utils.ipcutThis filter is designed to get 1st or last few bits of IP address.
ansible.utils.ipmathThis filter is designed to do simple IP math/arithmetic.
ansible.utils.ipsubnetThis filter can be used to manipulate network subnets in several ways.
ansible.utils.ipv4To filter only Ipv4 addresses Ipv4 filter is used.
ansible.utils.ipv6To filter only Ipv6 addresses Ipv6 filter is used.
ansible.utils.ipv6formThis filter is designed to convert ipv6 address in different formats. For example expand, compressetc.
ansible.utils.ipwrapThis filter is designed to Wrap IPv6 addresses in [ ] brackets.
ansible.utils.keep_keysKeep specific keys from a data recursively.
ansible.utils.macaddrmacaddr / MAC address filters
ansible.utils.network_in_networkThis filter returns whether an address or a network passed as argument is in a network.
ansible.utils.network_in_usableThe network_in_usable filter returns whether an address passed as an argument is usable in a network.
ansible.utils.next_nth_usableThis filter returns the next nth usable ip within a network described by value.
ansible.utils.nthhostThis filter returns the nth host within a network described by value.
ansible.utils.param_list_compareGenerate the final param list combining/comparing base and provided parameters.
ansible.utils.previous_nth_usableThis filter returns the previous nth usable ip within a network described by value.
ansible.utils.reduce_on_networkThis filter reduces a list of addresses to only the addresses that match a given network.
ansible.utils.remove_keysRemove specific keys from a data recursively.
ansible.utils.replace_keysReplaces specific keys with their after value from a data recursively.
ansible.utils.slaacThis filter returns the SLAAC address within a network for a given HW/MAC address.
ansible.utils.to_pathsFlatten a complex object into a dictionary of paths and values
ansible.utils.to_xmlConvert given JSON string to XML
ansible.utils.usable_rangeExpand the usable IP addresses
ansible.utils.validateValidate data with provided criteria

Lookup plugins

NameDescription
ansible.utils.get_pathRetrieve the value in a variable using a path
ansible.utils.index_ofFind the indices of items in a list matching some criteria
ansible.utils.to_pathsFlatten a complex object into a dictionary of paths and values
ansible.utils.validateValidate data with provided criteria

Modules

NameDescription
ansible.utils.cli_parseParse cli output or text using a variety of parsers
ansible.utils.fact_diffFind the difference between currently set facts
ansible.utils.update_factUpdate currently set facts
ansible.utils.validateValidate data with provided criteria

Test plugins

NameDescription
ansible.utils.in_any_networkTest if an IP or network falls in any network
ansible.utils.in_networkTest if IP address falls in the network
ansible.utils.in_one_networkTest if IP address belongs in any one of the networks in the list
ansible.utils.ipTest if something in an IP address or network
ansible.utils.ip_addressTest if something in an IP address
ansible.utils.ipv4Test if something is an IPv4 address or network
ansible.utils.ipv4_addressTest if something is an IPv4 address
ansible.utils.ipv4_hostmaskTest if an address is a valid hostmask
ansible.utils.ipv4_netmaskTest if an address is a valid netmask
ansible.utils.ipv6Test if something is an IPv6 address or network
ansible.utils.ipv6_addressTest if something is an IPv6 address
ansible.utils.ipv6_ipv4_mappedTest if something appears to be a mapped IPv6 to IPv4 mapped address
ansible.utils.ipv6_sixtofourTest if something appears to be a 6to4 address
ansible.utils.ipv6_teredoTest if something appears to be an IPv6 teredo address
ansible.utils.loopbackTest if an IP address is a loopback
ansible.utils.macTest if something appears to be a valid MAC address
ansible.utils.multicastTest for a multicast IP address
ansible.utils.privateTest if an IP address is private
ansible.utils.publicTest if an IP address is public
ansible.utils.reservedTest for a reserved IP address
ansible.utils.resolvableTest if an IP or name can be resolved via /etc/hosts or DNS
ansible.utils.subnet_ofTest if a network is a subnet of another network
ansible.utils.supernet_ofTest if a network is a supernet of another network
ansible.utils.unspecifiedTest for an unspecified IP address
ansible.utils.validateValidate data with provided criteria

Installing this collection

You can install the ansible.utils collection with the Ansible Galaxy CLI:

ansible-galaxy collection install ansible.utils

You can also include it in a requirements.yml file and install it with ansible-galaxy collection install -r requirements.yml, using the format:

---
collections:
  - name: ansible.utils

Using this collection

The most common use case for this collection is when you want to work with the complex data structures present in an Ansible playbook, inventory, or returned from modules. See each plugin documentation page for detailed examples for how these utilities can be used in tasks.

NOTE: For Ansible 2.9, you may not see deprecation warnings when you run your playbooks with this collection. Use this documentation to track when a module is deprecated.

See Also:

Contributing to this collection

This collection is intended for plugins that are not platform or discipline specific. Simple plugin examples should be generic in nature. More complex examples can include real world platform modules to demonstrate the utility of the plugin in a playbook.

We welcome community contributions to this collection. If you find problems, please open an issue or create a PR against the ansible.utils collection repository. See Contributing to Ansible-maintained collections for complete details.

See the Ansible Community Guide for details on contributing to Ansible.

Developer notes

  • 100% code coverage is the goal, although it's not always possible. Please include unit and integration tests with all PRs. PRs should not cause a decrease in code coverage.
  • Filter plugins should be 1 per file, with an included DOCUMENTATION string, or reference a lookup plugin with the same name.
  • Action, filter, and lookup plugins should use argspec validation. See AnsibleArgSpecValidator.
  • This collection should not depend on other collections for imported code
  • Use of the latest version of black is required for formatting (black -l79)
  • The README contains a table of plugins. Use the collection_prep utilities to maintain this.

Code of Conduct

This collection follows the Ansible project's Code of Conduct. Please read and familiarize yourself with this document.

Release notes

Release notes are available here For automated release announcements refer here.

Roadmap

For information on releasing, versioning and deprecation see the stratergy document.

In general, major versions can contain breaking changes, while minor versions only contain new features (like new plugin addition) and bugfixes. The releases will be done on an as-needed basis when new features and/or bugfixes are done.

More information

Licensing

GNU General Public License v3.0 or later.

See LICENSE to see the full text.

Certification

Product
Red Hat Ansible Automation Platform 2.4
Red Hat Ansible Automation Platform 2.5
DocumentationDependencies
No dependencies
This collection does not require any additional collections for use.

This collection is used by the following collections:

1 - 10 of 74 items
NameSummaryVersionType
View in Automation Hub
Red Hat logoLinkedInYouTubeFacebookTwitter

Platforms

Products & services

Try, buy, sell

Help

About Red Hat Ecosystem Catalog

The Red Hat Ecosystem Catalog is the official source for discovering and learning more about the Red Hat Ecosystem of both Red Hat and certified third-party products and services.

We’re the world’s leading provider of enterprise open source solutions—including Linux, cloud, container, and Kubernetes. We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2025 Red Hat