Skip to content

Commit

Permalink
Changing the repo structure and first version of README
Browse files Browse the repository at this point in the history
  • Loading branch information
davidBMSTU committed Jan 24, 2022
1 parent 95b1b06 commit 388a0ad
Show file tree
Hide file tree
Showing 26 changed files with 99 additions and 19 deletions.
81 changes: 80 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,81 @@
# cotea
cotea: Ansible control tool

### 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 other systems
- **To debug** Ansible execution by getting the values of Ansible variables and by retrieving the results of the execution of Ansible tasks/plays

## Installation
At the moment, only installation from source is possible. In the future, it is planned to install cotea using pip.
It is assumed that Ansible is installed in the current environment.

You need just to clone this project:
```bash
git clone https://github.com/ispras/cotea
```
and use **from cotea.src.** to import any of cotea objects being in the same directory as the cotea folder.

## Quick start
```python
from cotea.src.runner import runner
from cotea.src.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():
setup_ok = r.setup_play_for_run()
current_play = r.get_cur_play_name()
print("PLAY:", current_play)

if setup_ok:
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

```python
# imports and object creation...

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

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

if setup_ok:
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](https://github.com/ispras/cotea/blob/main/docs/cotea_docs.md).
1 change: 1 addition & 0 deletions docs/cotea_docs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# cotea documentation
Binary file not shown.
Binary file added src/__pycache__/arguments_maker.cpython-38.pyc
Binary file not shown.
Binary file added src/__pycache__/runner.cpython-38.pyc
Binary file not shown.
File renamed without changes.
File renamed without changes.
20 changes: 10 additions & 10 deletions runner.py → src/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
from ansible.plugins.strategy.linear import StrategyModule
from ansible.executor.task_queue_manager import TaskQueueManager

from cotea.ansible_execution_sync import ans_sync
from cotea.arguments_maker import argument_maker
from cotea.wrappers.get_batches_wrapper import get_batches_wrapper
from cotea.wrappers.strategy_run_wrapper import strategy_run_wrapper
from cotea.wrappers.get_next_task_wrapper import get_next_task_wrapper
from cotea.wrappers.wait_pending_wrapper import wait_pending_wrapper
from cotea.wrappers.tqm_run_wrapper import tqm_run_wrapper
from cotea.wrappers.get_batch_len_wrapper import get_batch_len_wrapper
from cotea.wrappers.pbcli_run_wrapper import pbcli_run_wrapper
from cotea.wrappers.play_prereqs_wrapper import play_prereqs_wrapper
from cotea.src.ansible_execution_sync import ans_sync
from cotea.src.arguments_maker import argument_maker
from cotea.src.wrappers.get_batches_wrapper import get_batches_wrapper
from cotea.src.wrappers.strategy_run_wrapper import strategy_run_wrapper
from cotea.src.wrappers.get_next_task_wrapper import get_next_task_wrapper
from cotea.src.wrappers.wait_pending_wrapper import wait_pending_wrapper
from cotea.src.wrappers.tqm_run_wrapper import tqm_run_wrapper
from cotea.src.wrappers.get_batch_len_wrapper import get_batch_len_wrapper
from cotea.src.wrappers.pbcli_run_wrapper import pbcli_run_wrapper
from cotea.src.wrappers.play_prereqs_wrapper import play_prereqs_wrapper


class runner:
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added src/wrappers/__pycache__/wrapper_base.cpython-38.pyc
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from cotea.wrappers.wrapper_base import wrapper_base
from cotea.src.wrappers.wrapper_base import wrapper_base


# wraps ansible.inventory.manager.InventoryManager.restrict_to_hosts()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from cotea.wrappers.wrapper_base import wrapper_base
from cotea.src.wrappers.wrapper_base import wrapper_base


# wraps ansible.executor.playbook_executor.PlaybookExecutor._get_serialized_batches()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from cotea.wrappers.wrapper_base import wrapper_base
from cotea.src.wrappers.wrapper_base import wrapper_base


# wraps ansible.plugins.strategy.linear.StrategyModule._get_next_task_lockstep()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from cotea.wrappers.wrapper_base import wrapper_base
from cotea.src.wrappers.wrapper_base import wrapper_base


# wraps from ansible.cli.playbook.PlaybookCLI.run()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from cotea.wrappers.wrapper_base import wrapper_base
from cotea.src.wrappers.wrapper_base import wrapper_base


# wraps from ansible.cli.CLI._play_prereqs()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from cotea.wrappers.wrapper_base import wrapper_base
from cotea.src.wrappers.wrapper_base import wrapper_base


# wraps ansible.plugins.strategy.linear.StrategyModule.run()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from cotea.wrappers.wrapper_base import wrapper_base
from cotea.src.wrappers.wrapper_base import wrapper_base


# wraps ansible.executor.task_queue_manager.TaskQueueManager.run()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from cotea.wrappers.wrapper_base import wrapper_base
from cotea.src.wrappers.wrapper_base import wrapper_base


# wraps ansible.plugins.strategy.StrategyBase._wait_on_pending_results()
Expand Down
File renamed without changes.

0 comments on commit 388a0ad

Please sign in to comment.