Skip to content

ansible-collections/ansible.utils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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.15.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

Name Description
ansible.utils.cidr_merge This filter can be used to merge subnets or individual addresses.
ansible.utils.consolidate Consolidate facts together on common attributes.
ansible.utils.fact_diff Find the difference between currently set facts
ansible.utils.from_xml Convert given XML string to native python dictionary.
ansible.utils.get_path Retrieve the value in a variable using a path
ansible.utils.hwaddr HWaddr / MAC address filters
ansible.utils.index_of Find the indices of items in a list matching some criteria
ansible.utils.ip4_hex This filter is designed to convert IPv4 address to Hexadecimal notation with optional delimiter.
ansible.utils.ipaddr This filter is designed to return the input value if a query is True, else False.
ansible.utils.ipcut This filter is designed to get 1st or last few bits of IP address.
ansible.utils.ipmath This filter is designed to do simple IP math/arithmetic.
ansible.utils.ipsubnet This filter can be used to manipulate network subnets in several ways.
ansible.utils.ipv4 To filter only Ipv4 addresses Ipv4 filter is used.
ansible.utils.ipv6 To filter only Ipv6 addresses Ipv6 filter is used.
ansible.utils.ipv6form This filter is designed to convert ipv6 address in different formats. For example expand, compressetc.
ansible.utils.ipwrap This filter is designed to Wrap IPv6 addresses in [ ] brackets.
ansible.utils.keep_keys Keep specific keys from a data recursively.
ansible.utils.macaddr macaddr / MAC address filters
ansible.utils.network_in_network This filter returns whether an address or a network passed as argument is in a network.
ansible.utils.network_in_usable The network_in_usable filter returns whether an address passed as an argument is usable in a network.
ansible.utils.next_nth_usable This filter returns the next nth usable ip within a network described by value.
ansible.utils.nthhost This filter returns the nth host within a network described by value.
ansible.utils.param_list_compare Generate the final param list combining/comparing base and provided parameters.
ansible.utils.previous_nth_usable This filter returns the previous nth usable ip within a network described by value.
ansible.utils.reduce_on_network This filter reduces a list of addresses to only the addresses that match a given network.
ansible.utils.remove_keys Remove specific keys from a data recursively.
ansible.utils.replace_keys Replaces specific keys with their after value from a data recursively.
ansible.utils.slaac This filter returns the SLAAC address within a network for a given HW/MAC address.
ansible.utils.to_paths Flatten a complex object into a dictionary of paths and values
ansible.utils.to_xml Convert given JSON string to XML
ansible.utils.usable_range Expand the usable IP addresses
ansible.utils.validate Validate data with provided criteria

Lookup plugins

Name Description
ansible.utils.get_path Retrieve the value in a variable using a path
ansible.utils.index_of Find the indices of items in a list matching some criteria
ansible.utils.to_paths Flatten a complex object into a dictionary of paths and values
ansible.utils.validate Validate data with provided criteria

Modules

Name Description
ansible.utils.cli_parse Parse cli output or text using a variety of parsers
ansible.utils.fact_diff Find the difference between currently set facts
ansible.utils.update_fact Update currently set facts
ansible.utils.validate Validate data with provided criteria

Test plugins

Name Description
ansible.utils.in_any_network Test if an IP or network falls in any network
ansible.utils.in_network Test if IP address falls in the network
ansible.utils.in_one_network Test if IP address belongs in any one of the networks in the list
ansible.utils.ip Test if something in an IP address or network
ansible.utils.ip_address Test if something in an IP address
ansible.utils.ipv4 Test if something is an IPv4 address or network
ansible.utils.ipv4_address Test if something is an IPv4 address
ansible.utils.ipv4_hostmask Test if an address is a valid hostmask
ansible.utils.ipv4_netmask Test if an address is a valid netmask
ansible.utils.ipv6 Test if something is an IPv6 address or network
ansible.utils.ipv6_address Test if something is an IPv6 address
ansible.utils.ipv6_ipv4_mapped Test if something appears to be a mapped IPv6 to IPv4 mapped address
ansible.utils.ipv6_sixtofour Test if something appears to be a 6to4 address
ansible.utils.ipv6_teredo Test if something appears to be an IPv6 teredo address
ansible.utils.loopback Test if an IP address is a loopback
ansible.utils.mac Test if something appears to be a valid MAC address
ansible.utils.multicast Test for a multicast IP address
ansible.utils.private Test if an IP address is private
ansible.utils.public Test if an IP address is public
ansible.utils.reserved Test for a reserved IP address
ansible.utils.resolvable Test if an IP or name can be resolved via /etc/hosts or DNS
ansible.utils.subnet_of Test if a network is a subnet of another network
ansible.utils.supernet_of Test if a network is a supernet of another network
ansible.utils.unspecified Test for an unspecified IP address
ansible.utils.validate Validate 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.