HEX
Server: LiteSpeed
System: Linux kapuas.iixcp.rumahweb.net 5.14.0-427.42.1.el9_4.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Nov 1 14:58:02 EDT 2024 x86_64
User: mirz4654 (1666)
PHP: 8.1.33
Disabled: system,exec,escapeshellarg,escapeshellcmd,passthru,proc_close,proc_get_status,proc_nice,proc_open,proc_terminate,shell_exec,popen,pclose,dl,pfsockopen,leak,apache_child_terminate,posix_kill,posix_mkfifo,posix_setsid,posix_setuid,posix_setpgid,ini_alter,show_source,define_syslog_variables,symlink,syslog,openlog,openlog,closelog,ocinumcols,listen,chgrp,apache_note,apache_setenv,debugger_on,debugger_off,ftp_exec,dll,ftp,myshellexec,socket_bind,mail,posix_getwpuid
Upload Files
File: //lib/python3.9/site-packages/ansible_collections/cloud/common/plugins/modules/turbo_demo.py
# -*- coding: utf-8 -*-

# Copyright: (C) 2020, Gonéri Le Bouder <[email protected]>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

DOCUMENTATION = r"""
---
module: turbo_demo
short_description: A demo module for ansible_module.turbo
version_added: "1.0.0"
description:
- "This module is an example of an ansible_module.turbo integration."
author:
- Gonéri Le Bouder (@goneri)
"""

EXAMPLES = r"""
- name: Run the module
  cloud.common.turbo_demo:
"""

import os

from ansible_collections.cloud.common.plugins.module_utils.turbo.module import (
    AnsibleTurboModule as AnsibleModule,
)


def counter():
    counter.i += 1
    return counter.i


# NOTE: workaround to avoid a warning with ansible-doc
if True:  # pylint: disable=using-constant-test
    counter.i = 0


def get_message():
    return f"This is me running with PID: {os.getpid()}, called {counter.i} time(s)"


def run_module():
    result = {}

    # the AnsibleModule object will be our abstraction working with Ansible
    # this includes instantiation, a couple of common attr would be the
    # args/params passed to the execution, as well as if the module
    # supports check mode
    module = AnsibleModule(argument_spec={}, supports_check_mode=True)
    module.collection_name = "cloud.common"
    previous_value = counter.i
    if not module.check_mode:
        counter()
        result["changed"] = True
    result["message"] = get_message()
    result["counter"] = counter.i
    result["envvar"] = os.environ.get("TURBO_TEST_VAR")

    if module._diff:
        result["diff"] = {"before": previous_value, "after": counter.i}

    module.exit_json(**result)


def main():
    from ansible_collections.cloud.common.plugins.module_utils import turbo_demo

    run_module()


if __name__ == "__main__":
    main()