diff --git a/README.md b/README.md index 26faf0f..1e6c5eb 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,13 @@ # Ansible Collection - nephelaiio.plugins -[![Build Status](https://github.com/nephelaiio/ansible-collection-plugins/actions/workflows/molecule.yml/badge.svg)](https://github.com/nephelaiio/ansible-collection-plugins/actions/wofklows/molecule.yml) +[![Build Status](https://github.com/nephelaiio/ansible-collection-plugins/actions/workflows/pytest.yml/badge.svg)](https://github.com/nephelaiio/ansible-collection-plugins/actions/wofklows/molecule.yml) [![Ansible Galaxy](http://img.shields.io/badge/ansible--galaxy-nephelaiio.plugins-blue.svg)](https://galaxy.ansible.com/ui/repo/published/nephelaiio/plugins/) An [ansible collection](https://galaxy.ansible.com/ui/repo/published/nephelaiio/plugins/) for utility filters and tests ## Collection plugins -Filters: +### Filters: - is_hash(d): Checks if the given object has a callable 'get' attribute. - merge_dicts(x, y): Merges two dictionaries, with values from the second dictionary overwriting those from the first. @@ -43,11 +43,10 @@ Filters: - is_all_true(xs): Returns True if all elements in the provided iterable are truthy. - search_regex(r, s): Checks if a string matches a given regex pattern. -Test: +### Tests: - test_network(record=None, net="0.0.0.0/0", prop="ansible_host"): Tests if an IP address in a given record falls within a specified network range. - test_property(record=None, regex=".*", prop=""): Tests if the value of a specified property in a given record matches a regular expression. - ## Testing Role is tested using molecule through Github Actions on Ubuntu latest. You can test the collection directly from sources using command `make test` diff --git a/galaxy.yml b/galaxy.yml index 7baec2e..6aad6f5 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -1,7 +1,7 @@ --- namespace: nephelaiio name: plugins -version: 0.0.4 +version: 0.0.5 readme: README.md authors: - Ted Cook diff --git a/plugins/filter/custom_filter.py b/plugins/filter/custom_filter.py index a946c62..921d726 100644 --- a/plugins/filter/custom_filter.py +++ b/plugins/filter/custom_filter.py @@ -288,6 +288,7 @@ def alias_keys(d, alias=None): new_dict[v] = new_dict[k] return new_dict + def map_attributes(d, atts): """ Extracts values from the input dictionary (d) for the keys listed in atts. @@ -306,6 +307,7 @@ def map_attributes(d, atts): new_array = new_array + [d[k]] return new_array + def select_attributes(d, atts): """ Creates a new dictionary containing only the key-value pairs from the input dictionary (d) @@ -325,6 +327,7 @@ def select_attributes(d, atts): new_dict[k] = d[k] return new_dict + def drop_attributes(d, x): """ Returns a new dictionary with specified keys removed from the input dictionary (d). @@ -343,6 +346,7 @@ def drop_attributes(d, x): del new_dict[y] return new_dict + def to_dict(x, key=None): """ Converts the input into a dictionary. If a key function or mapping is provided, @@ -366,6 +370,7 @@ def to_dict(x, key=None): result = {key: x} return result + def merge_item(item, key_attr): """ Merges a tuple of two items (a key-value pair) into a single dictionary, @@ -377,6 +382,7 @@ def merge_item(item, key_attr): return dict(merge_dicts(item[1], to_dict(item[0], key_attr))) + def key_item(item, key_attr, remove_key=True): """ Extracts a value from the given item using a specified key or nested keys, and returns @@ -454,6 +460,7 @@ def list_to_dict(l, key_attr, remove_key=True): return dict([key_item(x, key_attr, remove_key) for x in l]) + def to_kv(d, sep=".", prefix=""): """ Recursively converts a nested dictionary or list into a flat list of key-value pairs with compound keys.