Skip to content

Commit

Permalink
plugins (become, callback, filter): style adjustments (#9535)
Browse files Browse the repository at this point in the history
* plugins (become, callback, filter, inventory): style adjustments

* remove inventory plugins from PR

* adjustments from review

* typo
  • Loading branch information
russoz authored Jan 7, 2025
1 parent 8cef0ee commit 3af793c
Show file tree
Hide file tree
Showing 22 changed files with 720 additions and 723 deletions.
4 changes: 2 additions & 2 deletions plugins/become/pfexec.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
become_user:
description:
- User you 'become' to execute the task.
- This plugin ignores this setting as pfexec uses its own C(exec_attr) to figure this out, but it is supplied here
for Ansible to make decisions needed for the task execution, like file permissions.
- This plugin ignores this setting as pfexec uses its own C(exec_attr) to figure this out, but it is supplied here for
Ansible to make decisions needed for the task execution, like file permissions.
type: string
default: root
ini:
Expand Down
2 changes: 1 addition & 1 deletion plugins/callback/default_without_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
stdout_callback = community.general.default_without_diff
# Enable callback with environment variables:
environment_variable: |
environment_variable: |-
ANSIBLE_STDOUT_CALLBACK=community.general.default_without_diff
"""

Expand Down
3 changes: 2 additions & 1 deletion plugins/callback/yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
short_description: YAML-ized Ansible screen output
deprecated:
removed_in: 13.0.0
why: Starting in ansible-core 2.13, the P(ansible.builtin.default#callback) callback has support for printing output in YAML format.
why: Starting in ansible-core 2.13, the P(ansible.builtin.default#callback) callback has support for printing output in
YAML format.
alternative: Use O(ansible.builtin.default#callback:result_format=yaml).
description:
- Ansible output that can be quite a bit easier to read than the default JSON formatting.
Expand Down
53 changes: 27 additions & 26 deletions plugins/filter/accumulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,44 @@
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later

DOCUMENTATION = '''
name: accumulate
short_description: Produce a list of accumulated sums of the input list contents
version_added: 10.1.0
author: Max Gautier (@VannTen)
description:
- Passthrough to the L(Python itertools.accumulate function,https://docs.python.org/3/library/itertools.html#itertools.accumulate).
- Transforms an input list into the cumulative list of results from applying addition to the elements of the input list.
- Addition means the default Python implementation of C(+) for input list elements type.
options:
_input:
description: A list.
type: list
elements: any
required: true
'''

RETURN = '''
_value:
description: A list of cumulated sums of the elements of the input list.
DOCUMENTATION = r"""
name: accumulate
short_description: Produce a list of accumulated sums of the input list contents
version_added: 10.1.0
author: Max Gautier (@VannTen)
description:
- Passthrough to the L(Python itertools.accumulate function,https://docs.python.org/3/library/itertools.html#itertools.accumulate).
- Transforms an input list into the cumulative list of results from applying addition to the elements of the input list.
- Addition means the default Python implementation of C(+) for input list elements type.
options:
_input:
description: A list.
type: list
elements: any
'''
required: true
"""

EXAMPLES = '''
RETURN = r"""
_value:
description: A list of cumulated sums of the elements of the input list.
type: list
elements: any
"""

EXAMPLES = r"""
- name: Enumerate parent directories of some path
ansible.builtin.debug:
var: >
"/some/path/to/my/file"
| split('/') | map('split', '/')
| community.general.accumulate | map('join', '/')
"/some/path/to/my/file"
| split('/') | map('split', '/')
| community.general.accumulate | map('join', '/')
# Produces: ['', '/some', '/some/path', '/some/path/to', '/some/path/to/my', '/some/path/to/my/file']
- name: Growing string
ansible.builtin.debug:
var: "'abc' | community.general.accumulate"
# Produces ['a', 'ab', 'abc']
'''
"""

from itertools import accumulate
from collections.abc import Sequence
Expand Down
43 changes: 22 additions & 21 deletions plugins/filter/counter.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,35 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

DOCUMENTATION = '''
name: counter
short_description: Counts hashable elements in a sequence
version_added: 4.3.0
author: Rémy Keil (@keilr)
description:
- Counts hashable elements in a sequence.
options:
_input:
description: A sequence.
type: list
elements: any
required: true
'''
DOCUMENTATION = r"""
name: counter
short_description: Counts hashable elements in a sequence
version_added: 4.3.0
author: Rémy Keil (@keilr)
description:
- Counts hashable elements in a sequence.
options:
_input:
description: A sequence.
type: list
elements: any
required: true
"""

EXAMPLES = '''
EXAMPLES = r"""
- name: Count occurrences
ansible.builtin.debug:
msg: >-
{{ [1, 'a', 2, 2, 'a', 'b', 'a'] | community.general.counter }}
# Produces: {1: 1, 'a': 3, 2: 2, 'b': 1}
'''
"""

RETURN = '''
_value:
description: A dictionary with the elements of the sequence as keys, and their number of occurrences in the sequence as values.
type: dictionary
'''
RETURN = r"""
_value:
description: A dictionary with the elements of the sequence as keys, and their number of occurrences in the sequence as
values.
type: dictionary
"""

from ansible.errors import AnsibleFilterError
from ansible.module_utils.common._collections_compat import Sequence
Expand Down
50 changes: 25 additions & 25 deletions plugins/filter/crc32.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,33 @@
HAS_ZLIB = False


DOCUMENTATION = '''
name: crc32
short_description: Generate a CRC32 checksum
version_added: 5.4.0
description:
- Checksum a string using CRC32 algorithm and return its hexadecimal representation.
options:
_input:
description:
- The string to checksum.
type: string
required: true
author:
- Julien Riou
'''
DOCUMENTATION = r"""
name: crc32
short_description: Generate a CRC32 checksum
version_added: 5.4.0
description:
- Checksum a string using CRC32 algorithm and return its hexadecimal representation.
options:
_input:
description:
- The string to checksum.
type: string
required: true
author:
- Julien Riou
"""

EXAMPLES = '''
- name: Checksum a test string
ansible.builtin.debug:
msg: "{{ 'test' | community.general.crc32 }}"
'''
EXAMPLES = r"""
- name: Checksum a test string
ansible.builtin.debug:
msg: "{{ 'test' | community.general.crc32 }}"
"""

RETURN = '''
_value:
description: CRC32 checksum.
type: string
'''
RETURN = r"""
_value:
description: CRC32 checksum.
type: string
"""


def crc32s(value):
Expand Down
42 changes: 21 additions & 21 deletions plugins/filter/dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@
from __future__ import absolute_import, division, print_function
__metaclass__ = type

DOCUMENTATION = '''
name: dict
short_description: Convert a list of tuples into a dictionary
version_added: 3.0.0
author: Felix Fontein (@felixfontein)
description:
- Convert a list of tuples into a dictionary. This is a filter version of the C(dict) function.
options:
_input:
description: A list of tuples (with exactly two elements).
type: list
elements: tuple
required: true
'''
DOCUMENTATION = r"""
name: dict
short_description: Convert a list of tuples into a dictionary
version_added: 3.0.0
author: Felix Fontein (@felixfontein)
description:
- Convert a list of tuples into a dictionary. This is a filter version of the C(dict) function.
options:
_input:
description: A list of tuples (with exactly two elements).
type: list
elements: tuple
required: true
"""

EXAMPLES = '''
EXAMPLES = r"""
- name: Convert list of tuples into dictionary
ansible.builtin.set_fact:
dictionary: "{{ [[1, 2], ['a', 'b']] | community.general.dict }}"
Expand Down Expand Up @@ -53,13 +53,13 @@
# "k2": 42,
# "k3": "b"
# }
'''
"""

RETURN = '''
_value:
description: A dictionary with the provided key-value pairs.
type: dictionary
'''
RETURN = r"""
_value:
description: A dictionary with the provided key-value pairs.
type: dictionary
"""


def dict_filter(sequence):
Expand Down
52 changes: 26 additions & 26 deletions plugins/filter/dict_kv.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,37 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

DOCUMENTATION = '''
name: dict_kv
short_description: Convert a value to a dictionary with a single key-value pair
version_added: 1.3.0
author: Stanislav German-Evtushenko (@giner)
description:
- Convert a value to a dictionary with a single key-value pair.
positional: key
options:
_input:
description: The value for the single key-value pair.
type: any
required: true
key:
description: The key for the single key-value pair.
type: any
required: true
'''

EXAMPLES = '''
DOCUMENTATION = r"""
name: dict_kv
short_description: Convert a value to a dictionary with a single key-value pair
version_added: 1.3.0
author: Stanislav German-Evtushenko (@giner)
description:
- Convert a value to a dictionary with a single key-value pair.
positional: key
options:
_input:
description: The value for the single key-value pair.
type: any
required: true
key:
description: The key for the single key-value pair.
type: any
required: true
"""

EXAMPLES = r"""
- name: Create a one-element dictionary from a value
ansible.builtin.debug:
msg: "{{ 'myvalue' | dict_kv('mykey') }}"
# Produces the dictionary {'mykey': 'myvalue'}
'''
"""

RETURN = '''
_value:
description: A dictionary with a single key-value pair.
type: dictionary
'''
RETURN = r"""
_value:
description: A dictionary with a single key-value pair.
type: dictionary
"""


def dict_kv(value, key):
Expand Down
Loading

0 comments on commit 3af793c

Please sign in to comment.