pytoccaz.utils.python_module_info (1.4.0) — module

Checks whether a python module is installed or not

| "added in version" 1.1.0 of pytoccaz.utils"

Authors: Olivier Bernard (@pytoccaz)

Install collection

Install with ansible-galaxy collection install pytoccaz.utils:==1.4.0


Add to requirements.yml

  collections:
    - name: pytoccaz.utils
      version: 1.4.0

Description

Checks a python module or package is available on target host

importlib.util.find_spec wrapper

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Is python-docker available ?
  pytoccaz.utils.python_module_info:
    name: docker
  register: module_docker
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- debug:
    var: module_docker.is_installed
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Is html.parser available ?
  pytoccaz.utils.python_module_info:
    name: html.parser
  register: module_parser
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- debug:
    var: module_parser.is_installed
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Is html.parser available (using package parameter) ?
  pytoccaz.utils.python_module_info:
    name: .parser
    package: html
  register: module_parser
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- debug:
    var: module_parser.is_installed

Inputs

    
name:
    aliases:
    - module_name
    - module
    description:
    - Fully qualified name of the python module or package.
    - Relative name preceded with a dot if used in combinaison with C(package) parameter
    required: true
    type: str
    version_added: 1.1.0
    version_added_collection: pytoccaz.utils

package:
    description:
    - Fully qualified name of the python package
    - Start C(name) parameter value with a dot
    required: false
    type: str
    version_added: 1.1.0
    version_added_collection: pytoccaz.utils

Outputs

is_installed:
  description: If the python module or package is actually installed
  returned: success
  sample: true
  type: bool
name:
  description: The python module fully qualified name C(package_name.?module_name)
  returned: succes
  sample: html.parser
  type: str