https://github.com/blue-yonder/ansible-remove-omit-entries

Omit for dictionary and list entries.

https://github.com/blue-yonder/ansible-remove-omit-entries

Science Score: 13.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (8.5%) to scientific vocabulary
Last synced: 6 months ago · JSON representation

Repository

Omit for dictionary and list entries.

Basic Info
  • Host: GitHub
  • Owner: blue-yonder
  • License: mit
  • Language: Python
  • Default Branch: master
  • Size: 5.86 KB
Statistics
  • Stars: 1
  • Watchers: 2
  • Forks: 2
  • Open Issues: 1
  • Releases: 0
Created about 8 years ago · Last pushed about 7 years ago
Metadata Files
Readme Changelog License

README.md

Ansible Role: remove-omit-entries

Build Status

In a nutshell, this role gives you behavior similar to Ansible's omit, but for dictionaries and lists instead of modules' parameters.

For this, the role defines two filters (remove_omit_entries and remove_omit_entries_get_marker [only used internally]) and one var (remove_omit_entries_marker). The role itself does not run any tasks.

Usage

  • Add the role to the roles section of your playbook.
  • Set remove_omit_entries_marker as a default value for entries that should be removed by the filter.
  • Run dicts or lists through remove_omit_entries to remove entries having remove_omit_entries_marker as their value.

Requirements and Dependencies

None

Example

The need for the role arose from the inadequacy of Ansible's omit when passing dicts as modules' parameters. omit can be used as default value for possibly undefined variables. When passing parameters to modules, Ansible will not pass omitted parameters.

~~~ debug: # debugmsg will not be passed to the debug module if undefined msg: "{{ debugmsg|default(omit) }}" ~~~

However, this does not work for entries of dictionaries. Ansible will pass the complete error_info dictionary to the debug module:

~~~ vars: errorinfo: code: 10 reason: "{{ errorreason|default(omit) }}"

tasks: - debug: msg: error_info ~~~

This will print something like:

~~~ TASK [debug] ******************************************************************** ok: [localhost] => { "msg": { "code": 10, "reason": "omitplaceholderab8264664a4f0a83fa01e9ee3f221d79acecefc8" } } ~~~

To prevent the debug module from seeing the undefined reason entry of the error_info dictionary, we can use the remove-omit-entries-role.

~~~ roles: # Include the remove-omit-entries role - role: remove-omit-entries

vars: errorinfo: code: 10 # Use removeomitentriesmarker as default value for possibly undefined values reason: "{{ errorreason|default(removeomitentriesmarker) }}"

tasks: - debug: # Pass the dict through the removeomitentries filter msg: "{{ errorinfo|removeomit_entries }}" ~~~

Now, the debug module will receive a dictionary that only contains the defined entry code.

~~~ TASK [debug] ******************************************************************** ok: [localhost] => { "msg": { "code": 10 } } ~~~

Behavior of remove_omit_entries filter

Removes dict entries whose value is OMIT_MARKER:

~~~

removeomitentries({'key1': 'somevalue', 'key2': OMITMARKER}) {'key1': 'some_value'} ~~~

Removes list items whose value is OMIT_MARKER: ~~~

removeomitentries([OMIT_MARKER]) [] ~~~

Works recursively: ~~~

removeomitentries({'key1': {'key11': OMIT_MARKER}}) {'key1': {}} ~~~

Returns everything else as is: ~~~

removeomitentries('') '' removeomitentries({OMITMARKER: 'somevalue'}) == {OMITMARKER: 'somevalue'} True removeomitentries(OMITMARKER) == OMITMARKER True ~~~

License

MIT

Owner

  • Name: Blue Yonder GmbH
  • Login: blue-yonder
  • Kind: organization
  • Location: Karlsruhe, Germany

GitHub Events

Total
Last Year

Issues and Pull Requests

Last synced: 12 months ago

All Time
  • Total issues: 0
  • Total pull requests: 1
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Total issue authors: 0
  • Total pull request authors: 1
  • Average comments per issue: 0
  • Average comments per pull request: 0.0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
  • simonsystem (1)
Top Labels
Issue Labels
Pull Request Labels