Skip to main content

Tool that provides Python API to run Ansible programmatically.

Project description

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 -i https://test.pypi.org/simple/ cotea==1.3.2

Tested on Ansible 2.9.4, 2.12.2, 2.12.4 in ubuntu 20.04.

Quick start

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

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

am = argument_maker()
am.add_arg("-i", inv_path)

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.

Debugging

# imports and object creation...

specific_play = "s_play"
specific_task = "s_task"
s_var_name = "s_var"

while r.has_next_play():
    current_play = r.get_cur_play_name()

    while r.has_next_task():
        next_task = r.get_next_task_name()
        if current_play == specific_play and next_task == specific_task:
            # getting variable at specific execution point
            s_var_value = r.get_variable(s_var_name)

        r.run_next_task()

r.finish_ansible()

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

With the help of cotea one can do certain things dynamically at specific Ansible execution points. Getting the value of a specific variable at a specific execution point is shown above (the point is determined by a pair of Ansible play and task). If ansible exits with an error one can get the error message programmatically without processing a huge log file.

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cotea-1.3.13.tar.gz (17.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cotea-1.3.13-py3-none-any.whl (22.1 kB view details)

Uploaded Python 3

File details

Details for the file cotea-1.3.13.tar.gz.

File metadata

  • Download URL: cotea-1.3.13.tar.gz
  • Upload date:
  • Size: 17.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.22.0 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/18.0.1 rfc3986/2.0.0 colorama/0.4.3 CPython/3.8.10

File hashes

Hashes for cotea-1.3.13.tar.gz
Algorithm Hash digest
SHA256 3e905874e5dfa2031915f61120f22d4cab76c1eac5a4b200794e1e3f4f1fe340
MD5 bde47e5b52a390cc8c2e503bb64d7e68
BLAKE2b-256 ce840462c6d4ca3378500779af869a9e0c57513e4129d1e9d36c4a897eea2716

See more details on using hashes here.

File details

Details for the file cotea-1.3.13-py3-none-any.whl.

File metadata

  • Download URL: cotea-1.3.13-py3-none-any.whl
  • Upload date:
  • Size: 22.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.22.0 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/18.0.1 rfc3986/2.0.0 colorama/0.4.3 CPython/3.8.10

File hashes

Hashes for cotea-1.3.13-py3-none-any.whl
Algorithm Hash digest
SHA256 4c5aa61f233b5176ce2e21368d280c0546f1f9ce0d7c49c6d22d6e740fc7d1ee
MD5 45a50764470c1eccc2b07869a8b105be
BLAKE2b-256 47b7c0e1f076ea977fce5ce8a12326076a17c50c911f92691417e20db9e87c0f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page