Skip to main content

cotea

(COntrol Thread Execution Ansible)

cotea is:

Tool that provides Python API to run Ansible programmatically.

cotea allows:

  • To control Ansible execution by iterating over the Ansible plays and tasks
  • To embed Ansible into another system
  • To debug Ansible execution by getting the values of Ansible variables and by retrieving the results of the execution of Ansible tasks/plays

Installation

pip install cotea

Quick start

from cotea.runner import runner
from cotea.arguments_maker import argument_maker

inv_path = "/path/to/inventory"
playbook_path = "/path/to/playbook"

arg_maker = argument_maker()

# setting ansible-playbook flags
arg_maker.add_arg("-i", inv_path)
arg_maker.add_arg("-vvv")

# setting extra-vars
extra_vars = {"SPARK_VERSION": "3.0.2"}
arg_maker.add_arg("--extra-vars", extra_vars)

r = runner(playbook_path, am)

while r.has_next_play():
    current_play = r.get_cur_play_name()
    print("PLAY:", current_play)

    while r.has_next_task():
        next_task = r.get_next_task_name()
        print("\tTASK:", next_task)
            
        r.run_next_task()

r.finish_ansible()

Any argument of the "ansible-playbook" command can be passed by using argument_maker objects. The launch and control of the Ansible is carried out using the runner object. With the help of cotea one can do certain things dynamically at specific Ansible execution points.

Debugging

# imports and object creation...

while r.has_next_play():
    while r.has_next_task():
        task_results = r.run_next_task()
    
        some_task_failed = False
        failed_task = None

        already_ignore_failed = r.get_already_ignore_failed()
        already_ignore_unrch = r.get_already_ignore_unrch()

        for task in task_results:
            task_uuid = task.original_task_uuid
            
            # checking that task didn't have ignore_errors: true
            if task.is_failed:    
                if not task_uuid in already_ignore_failed:
                    some_task_failed = True
                    failed_task = task.task_ansible_object
                    break
            
            # checking that task didn't have ignore_unreachable: true
            if task.is_unreachable:    
                if not task_uuid in already_ignore_unrch:
                    some_task_failed = True
                    failed_task = task.task_ansible_object
                    break
        
        # the task was failed and didn't have
        # ignore_errors or ignore_unreachable flags -
        # going to interactive debugging mod
        if some_task_failed:
            interactive_discotech(failed_task, r)

        r.ignore_errors_of_next_task()


r.finish_ansible()

if r.was_error():
    print("Ansible error was:", r.get_error_msg())

Cotea also contains interactive debugging mode. Using the cotea one can detects that the task was failed in runtime (including the check that task didn't have ignore_errors or ignore_unreachable flag) and call the interactive_discotech() method in that case as shown above. Supported commands:

  • 'ft' - print info about the Failed Task
  • 'msg' - print all ansible error MSGs (including the ignored ones)
  • 'p' - print Progress bar
  • 'h'/'help' - print help message
  • 're' - RErun of the failed task
  • 'v' - add new Variable as extra var
  • 'c' - Continue ansible execution (go to the next task)
  • 'nt' - add New Task
  • 'w' - Watch ansible variable value

A detailed overview of all interfaces is provided in cotea documentation.

Metadata

Release files for cotea 1.3.20

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cotea 1.3.20
File Size Uploaded Provenance Actions
cotea-1.3.20.tar.gz 19.7 kB Without provenance Details for cotea-1.3.20.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cotea 1.3.20
File Interpreter ABI Platform Actions
cotea-1.3.20-py3-none-any.whl Python 3 none any Details for cotea-1.3.20-py3-none-any.whl

Total release size: 43.8 kB

Release files / cotea-1.3.20.tar.gz

Download URL cotea-1.3.20.tar.gz
Size 19.7 kB
Tags Source
SHA-256 checksum
How to use checksums
7b446be14e63cbec605cbabf922c24b55d4bca6c7b78b9deadc81a3b50bb67f4
BLAKE2b-256 checksum
How to use checksums
b1d7e924e862881c8d551ad6fa6a6102b583c61dec4d97966ead5b08889d2dee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.31.0 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/24.3.1 rfc3986/2.0.0 colorama/0.4.3 CPython/3.8.10

Release files / cotea-1.3.20-py3-none-any.whl

Download URL cotea-1.3.20-py3-none-any.whl
Size 24.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d941336c7f5727d6c9f356ae11bf62cbddf7a24c2f3062116ceed4bc68c17e3f
BLAKE2b-256 checksum
How to use checksums
f7187e6ecaa2c134d09934cb43921489dd9e9ec831a39134df4de9c5214f4687
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.31.0 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/24.3.1 rfc3986/2.0.0 colorama/0.4.3 CPython/3.8.10

Security for cotea 1.3.20

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page