Skip to content

About

A collection of ansible utilities for the content creator.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

97 stars

Watchers

10 watching

Forks

Latest commit

 

History

376 Commits

Folders and files

Ansible Utilities Collection

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.

Requirements

  • Python 3.10 or later.
  • The Python packages jsonschema, textfsm, ttp, xmltodict, and netaddr (version 0.10.1 or later), listed in the collection's requirements.txt.

Support

As Red Hat Ansible Certified Content, it is entitled to support through Ansible Automation Platform (AAP). Red Hat customers can open a support case by selecting the Create issue button in the top right corner of this collection's page in Automation Hub.

If you obtained this collection from Ansible Galaxy or GitHub, community support is available at no charge. Join us on the #network:ansible.com Matrix room or the Ansible Forum Network Working Group.

Communication

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

Ansible version compatibility

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

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

Install the certified ansible.utils collection from Red Hat Ansible Automation Hub. Access to certified content requires a Red Hat account with an active Ansible Automation Platform subscription and an Automation Hub offline token. In the Red Hat Hybrid Cloud Console, go to Automation Hub > Connect Hub, load the offline token, and store it securely. See the Red Hat token management instructions.

Configure your ansible.cfg to use the hosted Automation Hub service:

[galaxy]
server_list = automation_hub

[galaxy_server.automation_hub]
url = https://console.redhat.com/api/automation-hub/content/published/
auth_url = https://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/token
token = <your_automation_hub_token>

Keep the token secret and out of source control. Then install the collection:

ansible-galaxy collection install ansible.utils --server automation_hub

For a requirements.yml file, identify Automation Hub as the source:

---
collections:
  - name: ansible.utils
    source: automation_hub

Install the requirements with ansible-galaxy collection install -r requirements.yml.

Installing from Ansible Galaxy for community use

For community use outside Red Hat supported environments, install the collection from Ansible Galaxy:

ansible-galaxy collection install ansible.utils

You can also add it to a requirements.yml file:

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

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.

About

A collection of ansible utilities for the content creator.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

97 stars

Watchers

10 watching

Forks

Releases

Contributors

Languages