Skip to content

Commit

Permalink
Contributing guide was added
Browse files Browse the repository at this point in the history
  • Loading branch information
davidBMSTU committed Nov 8, 2023
1 parent 4182d8d commit 0589b5c
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 0 deletions.
5 changes: 5 additions & 0 deletions contributing/contr_inv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[host1]
host1 ansible_host=localhost ansible_connection=ssh ansible_ssh_port=2223 ansible_user=root ansible_password=veronika

[targets]
host1
15 changes: 15 additions & 0 deletions contributing/contr_pb.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
- name: Play1
hosts: host1
tasks:
- name: Pinge-Ponge
ping:

# - name: Bad task (will fail)
# shell: "mv biba boba"

- name: Creates very important directory
file:
path: /home/ubuntu/important_dir
state: directory

41 changes: 41 additions & 0 deletions contributing/contributing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Contributing
For development purposes you have to be able to run Ansible. If you don't have Ansible host, inventory files and etc, or you don't want to run Ansible against your hosts in cotea development purposes, there is a guide below for you.

1. Run Ansible host
(our special container)

```bash
docker run --name ans_host --rm -d -p 2222:22 dbadalyan/ansible_host_for_cotea /path/to/your/public_key.pub
```
Port 2222 is used here as a *ansible_ssh_port*. You can use the preferred one.

2. Get required files

If you have your own inventory or playbook files - you can use ones instead.

Clone cotea repo:
```bash
git clone https://github.com/ispras/cotea
```

You need an inventory file:
```bash
cp cotea/docs/contributing/contr_inv contr_inv
```
*ansible_port* is 2222 in this file, set the preferred one if you changed it in *docker run* command.

Playbook file:
```bash
cp cotea/docs/contributing/contr_pb.yaml contr_pb.yaml
```

Python file with cotea imports and Ansible launch:
```bash
cp cotea/docs/contributing/cotea_ansible_run.py cotea_ansible_run.py
```

3. Run Ansible using cotea

```bash
python3 cotea_ansible_run.py
```
38 changes: 38 additions & 0 deletions contributing/cotea_ansible_run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from cotea.runner import runner
from cotea.arguments_maker import argument_maker
from cotea.debug_utils import interactive_discotech


pb_path = "contr_pb.yaml"
inv = "contr_inv"

arg_maker = argument_maker()

arg_maker.add_arg("-i", inv)

r = runner(pb_path, arg_maker)

while r.has_next_play():
while r.has_next_task():
task_results = r.run_next_task()

some_task_failed = False
failed_task = None
for task in task_results:
if task.is_failed or task.is_unreachable:
some_task_failed = True
failed_task = task.task_ansible_object
break

if some_task_failed:
interactive_discotech(failed_task, r)

r.ignore_errors_of_next_task()

r.finish_ansible()

if r.was_error():
print("Ansible - failed:")
print(r.get_error_msg())
else:
print("Ansible - OK")

0 comments on commit 0589b5c

Please sign in to comment.