From c802de865a096366a5870941d32c76c906c0a725 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Thu, 17 Sep 2020 16:39:57 +0000 Subject: [PATCH] Fix various sanity errors in plugins (#881) (#893) * Fix deprecation of callables. * Fix various sanity errors. * Revert callback_type -> type transform. * Fix stat_result times: these are float according to https://github.com/python/typeshed/blob/master/stdlib/3/os/__init__.pyi * Apply suggestions from code review Co-authored-by: Andrew Klychkov Co-authored-by: Andrew Klychkov (cherry picked from commit 7cf472855c5b488a719511d707249edfff68225d) Co-authored-by: Felix Fontein --- meta/runtime.yml | 13 +++++++++++++ plugins/become/pfexec.py | 6 +++--- plugins/callback/counter_enabled.py | 11 ++++++----- plugins/callback/mail.py | 2 +- plugins/inventory/gitlab_runners.py | 4 ++-- plugins/lookup/chef_databag.py | 4 +++- plugins/lookup/consul_kv.py | 1 + plugins/lookup/credstash.py | 3 ++- plugins/lookup/cyberarkpassword.py | 4 ++-- plugins/lookup/dig.py | 4 +++- plugins/lookup/dsv.py | 2 ++ plugins/lookup/etcd3.py | 1 + plugins/lookup/filetree.py | 28 +++++++++++++++++++++++----- plugins/lookup/gcp_storage_file.py | 2 ++ plugins/lookup/hashi_vault.py | 2 ++ plugins/lookup/hiera.py | 5 +++-- plugins/lookup/keyring.py | 4 +++- plugins/lookup/lastpass.py | 2 ++ plugins/lookup/lmdb_kv.py | 2 ++ plugins/lookup/nios.py | 1 - plugins/lookup/nios_next_ip.py | 1 - plugins/lookup/nios_next_network.py | 1 - plugins/lookup/onepassword.py | 2 ++ plugins/lookup/onepassword_raw.py | 2 ++ plugins/lookup/passwordstore.py | 2 ++ plugins/lookup/redis.py | 2 ++ plugins/lookup/shelvefile.py | 2 ++ plugins/lookup/tss.py | 2 ++ 28 files changed, 88 insertions(+), 27 deletions(-) diff --git a/meta/runtime.yml b/meta/runtime.yml index 2417bc901e..a7f8af610a 100644 --- a/meta/runtime.yml +++ b/meta/runtime.yml @@ -740,3 +740,16 @@ plugin_routing: removal_version: 2.0.0 warning_text: The mysql module_utils has been moved to the community.mysql collection. redirect: community.mysql.mysql + callback: + actionable: + deprecation: + removal_version: 2.0.0 + warning_text: see plugin documentation for details + full_skip: + deprecation: + removal_version: 2.0.0 + warning_text: see plugin documentation for details + stderr: + deprecation: + removal_version: 2.0.0 + warning_text: see plugin documentation for details diff --git a/plugins/become/pfexec.py b/plugins/become/pfexec.py index d20e860601..d86af6e3ed 100644 --- a/plugins/become/pfexec.py +++ b/plugins/become/pfexec.py @@ -14,7 +14,7 @@ DOCUMENTATION = ''' become_user: description: - User you 'become' to execute the task - - This plugin ignores this setting as pfexec uses it's own ``exec_attr`` to figure this out, + - This plugin ignores this setting as pfexec uses it's 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. default: root ini: @@ -80,8 +80,8 @@ DOCUMENTATION = ''' - name: ansible_pfexec_wrap_execution env: - name: ANSIBLE_PFEXEC_WRAP_EXECUTION - note: - - This plugin ignores ``become_user`` as pfexec uses it's own ``exec_attr`` to figure this out. + notes: + - This plugin ignores I(become_user) as pfexec uses it's own C(exec_attr) to figure this out. ''' from ansible.plugins.become import BecomeBase diff --git a/plugins/callback/counter_enabled.py b/plugins/callback/counter_enabled.py index 2bfff6a3ef..0b29bae51a 100644 --- a/plugins/callback/counter_enabled.py +++ b/plugins/callback/counter_enabled.py @@ -6,11 +6,6 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -from ansible import constants as C -from ansible.plugins.callback import CallbackBase -from ansible.utils.color import colorize, hostcolor -from ansible.template import Templar -from ansible.playbook.task_include import TaskInclude DOCUMENTATION = ''' callback: counter_enabled @@ -26,6 +21,12 @@ DOCUMENTATION = ''' - set as stdout callback in ansible.cfg (stdout_callback = counter_enabled) ''' +from ansible import constants as C +from ansible.plugins.callback import CallbackBase +from ansible.utils.color import colorize, hostcolor +from ansible.template import Templar +from ansible.playbook.task_include import TaskInclude + class CallbackModule(CallbackBase): diff --git a/plugins/callback/mail.py b/plugins/callback/mail.py index 247f7671fc..2172f45c19 100644 --- a/plugins/callback/mail.py +++ b/plugins/callback/mail.py @@ -52,7 +52,7 @@ options: ini: - section: callback_mail key: bcc -note: +notes: - "TODO: expand configuration options now that plugins can leverage Ansible's configuration" ''' diff --git a/plugins/inventory/gitlab_runners.py b/plugins/inventory/gitlab_runners.py index 47b56f3e1d..ce487f2f5c 100644 --- a/plugins/inventory/gitlab_runners.py +++ b/plugins/inventory/gitlab_runners.py @@ -10,8 +10,8 @@ __metaclass__ = type DOCUMENTATION = ''' name: gitlab_runners plugin_type: inventory - authors: - - Stefan Heitmüller (stefan.heitmueller@gmx.com) + author: + - Stefan Heitmüller (@morph027) short_description: Ansible dynamic inventory plugin for GitLab runners. requirements: - python >= 2.7 diff --git a/plugins/lookup/chef_databag.py b/plugins/lookup/chef_databag.py index 60598b8de0..78f1936eea 100644 --- a/plugins/lookup/chef_databag.py +++ b/plugins/lookup/chef_databag.py @@ -34,7 +34,9 @@ EXAMPLES = """ RETURN = """ _raw: description: - - The value from the databag + - The value from the databag. + type: list + elements: dict """ from ansible.errors import AnsibleError diff --git a/plugins/lookup/consul_kv.py b/plugins/lookup/consul_kv.py index 9a9c949a63..c8406305cc 100644 --- a/plugins/lookup/consul_kv.py +++ b/plugins/lookup/consul_kv.py @@ -98,6 +98,7 @@ RETURN = """ _raw: description: - Value(s) stored in consul. + type: dict """ import os diff --git a/plugins/lookup/credstash.py b/plugins/lookup/credstash.py index 80665c62da..99c9a8ca9b 100644 --- a/plugins/lookup/credstash.py +++ b/plugins/lookup/credstash.py @@ -78,7 +78,8 @@ EXAMPLES = """ RETURN = """ _raw: description: - - value(s) stored in Credstash + - Value(s) stored in Credstash. + type: str """ import os diff --git a/plugins/lookup/cyberarkpassword.py b/plugins/lookup/cyberarkpassword.py index 74bac8daca..6d1323ce4a 100644 --- a/plugins/lookup/cyberarkpassword.py +++ b/plugins/lookup/cyberarkpassword.py @@ -30,8 +30,8 @@ DOCUMENTATION = ''' default: 'password' _extra: description: for extra_params values please check parameters for clipasswordsdk in CyberArk's "Credential Provider and ASCP Implementation Guide" - note: - - For Ansible on windows, please change the -parameters (-p, -d, and -o) to /parameters (/p, /d, and /o) and change the location of CLIPasswordSDK.exe + notes: + - For Ansible on Windows, please change the -parameters (-p, -d, and -o) to /parameters (/p, /d, and /o) and change the location of CLIPasswordSDK.exe. ''' EXAMPLES = """ diff --git a/plugins/lookup/dig.py b/plugins/lookup/dig.py index 6d6dca1483..6dc8fc6e7a 100644 --- a/plugins/lookup/dig.py +++ b/plugins/lookup/dig.py @@ -77,8 +77,10 @@ EXAMPLES = """ RETURN = """ _list: description: - - list of composed strings or dictionaries with key and value + - List of composed strings or dictionaries with key and value If a dictionary, fields shows the keys returned depending on query type + type: list + elements: raw contains: ALL: description: diff --git a/plugins/lookup/dsv.py b/plugins/lookup/dsv.py index 286cb0dbd0..18165f9f8a 100644 --- a/plugins/lookup/dsv.py +++ b/plugins/lookup/dsv.py @@ -70,6 +70,8 @@ _list: description: - One or more JSON responses to C(GET /secrets/{path}). - See U(https://dsv.thycotic.com/api/index.html#operation/getSecret). + type: list + elements: dict """ EXAMPLES = r""" diff --git a/plugins/lookup/etcd3.py b/plugins/lookup/etcd3.py index 7f9836ecd8..a358238925 100644 --- a/plugins/lookup/etcd3.py +++ b/plugins/lookup/etcd3.py @@ -94,6 +94,7 @@ DOCUMENTATION = ''' seealso: - module: community.general.etcd3 - ref: etcd_lookup + description: The etcd v2 lookup. requirements: - "etcd3 >= 0.10" diff --git a/plugins/lookup/filetree.py b/plugins/lookup/filetree.py index 7d088a543d..4b05096870 100644 --- a/plugins/lookup/filetree.py +++ b/plugins/lookup/filetree.py @@ -53,42 +53,60 @@ EXAMPLES = r""" RETURN = r""" _raw: - description: list of dictionaries with file information + description: List of dictionaries with file information. + type: list + elements: dict contains: src: description: - - full path to file. - - not returned when C(item.state) is set to C(directory). + - Full path to file. + - Not returned when I(item.state) is set to C(directory). + type: path root: - description: allows filtering by original location. + description: Allows filtering by original location. + type: path path: - description: contains the relative path to root. + description: Contains the relative path to root. + type: path mode: description: The permissions the resulting file or directory. + type: str state: description: TODO + type: str owner: description: Name of the user that owns the file/directory. + type: raw group: description: Name of the group that owns the file/directory. + type: raw seuser: description: The user part of the SELinux file context. + type: raw serole: description: The role part of the SELinux file context. + type: raw setype: description: The type part of the SELinux file context. + type: raw selevel: description: The level part of the SELinux file context. + type: raw uid: description: Owner ID of the file/directory. + type: int gid: description: Group ID of the file/directory. + type: int size: description: Size of the target. + type: int mtime: description: Time of last modification. + type: float ctime: description: Time of last metadata update or creation (depends on OS). + type: float """ import os import pwd diff --git a/plugins/lookup/gcp_storage_file.py b/plugins/lookup/gcp_storage_file.py index 22659166e1..bf92e2c24f 100644 --- a/plugins/lookup/gcp_storage_file.py +++ b/plugins/lookup/gcp_storage_file.py @@ -40,6 +40,8 @@ RETURN = ''' _raw: description: - base64 encoded file content + type: list + elements: str ''' import base64 diff --git a/plugins/lookup/hashi_vault.py b/plugins/lookup/hashi_vault.py index 2c0eaaafa4..d1f026c771 100644 --- a/plugins/lookup/hashi_vault.py +++ b/plugins/lookup/hashi_vault.py @@ -241,6 +241,8 @@ RETURN = """ _raw: description: - secrets(s) requested + type: list + elements: dict """ import os diff --git a/plugins/lookup/hiera.py b/plugins/lookup/hiera.py index 1ce4887139..09b7c0a1c9 100644 --- a/plugins/lookup/hiera.py +++ b/plugins/lookup/hiera.py @@ -18,7 +18,7 @@ DOCUMENTATION = ''' description: - The list of keys to lookup on the Puppetmaster type: list - element_type: string + elements: string required: True _bin_file: description: @@ -55,7 +55,8 @@ RETURN = """ _raw: description: - a value associated with input key - type: strings + type: list + elements: str """ import os diff --git a/plugins/lookup/keyring.py b/plugins/lookup/keyring.py index 8b27856d3c..ea627b9635 100644 --- a/plugins/lookup/keyring.py +++ b/plugins/lookup/keyring.py @@ -29,7 +29,9 @@ EXAMPLES = """ RETURN = """ _raw: - description: secrets stored + description: Secrets stored. + type: list + elements: str """ HAS_KEYRING = True diff --git a/plugins/lookup/lastpass.py b/plugins/lookup/lastpass.py index 4fec81071a..93abfb66ad 100644 --- a/plugins/lookup/lastpass.py +++ b/plugins/lookup/lastpass.py @@ -32,6 +32,8 @@ EXAMPLES = """ RETURN = """ _raw: description: secrets stored + type: list + elements: str """ from subprocess import Popen, PIPE diff --git a/plugins/lookup/lmdb_kv.py b/plugins/lookup/lmdb_kv.py index 13c0687bbc..3764a43ca0 100644 --- a/plugins/lookup/lmdb_kv.py +++ b/plugins/lookup/lmdb_kv.py @@ -48,6 +48,8 @@ EXAMPLES = """ RETURN = """ _raw: description: value(s) stored in LMDB + type: list + elements: raw """ diff --git a/plugins/lookup/nios.py b/plugins/lookup/nios.py index 034daa369a..0875705424 100644 --- a/plugins/lookup/nios.py +++ b/plugins/lookup/nios.py @@ -83,7 +83,6 @@ RETURN = """ obj_type: description: - The object type specified in the terms argument - returned: always type: complex contains: obj_field: diff --git a/plugins/lookup/nios_next_ip.py b/plugins/lookup/nios_next_ip.py index e266ee26ac..72660748ac 100644 --- a/plugins/lookup/nios_next_ip.py +++ b/plugins/lookup/nios_next_ip.py @@ -64,7 +64,6 @@ RETURN = """ _list: description: - The list of next IP addresses available - returned: always type: list """ diff --git a/plugins/lookup/nios_next_network.py b/plugins/lookup/nios_next_network.py index 6c4b4da8d1..f93913cff9 100644 --- a/plugins/lookup/nios_next_network.py +++ b/plugins/lookup/nios_next_network.py @@ -74,7 +74,6 @@ RETURN = """ _list: description: - The list of next network addresses available - returned: always type: list """ diff --git a/plugins/lookup/onepassword.py b/plugins/lookup/onepassword.py index 6755b1e39f..4fe1b36c4a 100644 --- a/plugins/lookup/onepassword.py +++ b/plugins/lookup/onepassword.py @@ -86,6 +86,8 @@ EXAMPLES = """ RETURN = """ _raw: description: field data requested + type: list + elements: str """ import errno diff --git a/plugins/lookup/onepassword_raw.py b/plugins/lookup/onepassword_raw.py index fd38af6b7c..76423a230c 100644 --- a/plugins/lookup/onepassword_raw.py +++ b/plugins/lookup/onepassword_raw.py @@ -62,6 +62,8 @@ EXAMPLES = """ RETURN = """ _raw: description: field data requested + type: list + elements: dict """ import json diff --git a/plugins/lookup/passwordstore.py b/plugins/lookup/passwordstore.py index 04de8bb4bb..a0891d0fb5 100644 --- a/plugins/lookup/passwordstore.py +++ b/plugins/lookup/passwordstore.py @@ -91,6 +91,8 @@ RETURN = """ _raw: description: - a password + type: list + elements: str """ import os diff --git a/plugins/lookup/redis.py b/plugins/lookup/redis.py index 16af15db91..955d93d8bf 100644 --- a/plugins/lookup/redis.py +++ b/plugins/lookup/redis.py @@ -67,6 +67,8 @@ EXAMPLES = """ RETURN = """ _raw: description: value(s) stored in Redis + type: list + elements: str """ import os diff --git a/plugins/lookup/shelvefile.py b/plugins/lookup/shelvefile.py index 32bae8f988..aff52a5059 100644 --- a/plugins/lookup/shelvefile.py +++ b/plugins/lookup/shelvefile.py @@ -29,6 +29,8 @@ EXAMPLES = """ RETURN = """ _list: description: value(s) of key(s) in shelve file(s) + type: list + elements: str """ import shelve diff --git a/plugins/lookup/tss.py b/plugins/lookup/tss.py index 46057432a5..c4a5e0c454 100644 --- a/plugins/lookup/tss.py +++ b/plugins/lookup/tss.py @@ -66,6 +66,8 @@ _list: description: - The JSON responses to C(GET /secrets/{id}). - See U(https://updates.thycotic.net/secretserver/restapiguide/TokenAuth/#operation--secrets--id--get). + type: list + elements: dict """ EXAMPLES = r"""