diff --git a/contributing/contr_inv b/contributing/contr_inv new file mode 100644 index 0000000..876f10c --- /dev/null +++ b/contributing/contr_inv @@ -0,0 +1,5 @@ +[host1] +host1 ansible_host=localhost ansible_connection=ssh ansible_ssh_port=2223 ansible_user=root ansible_password=veronika + +[targets] +host1 diff --git a/contributing/contr_pb.yaml b/contributing/contr_pb.yaml new file mode 100644 index 0000000..602fd5f --- /dev/null +++ b/contributing/contr_pb.yaml @@ -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 + diff --git a/contributing/contributing.md b/contributing/contributing.md new file mode 100644 index 0000000..e9f9c54 --- /dev/null +++ b/contributing/contributing.md @@ -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 +``` diff --git a/contributing/cotea_ansible_run.py b/contributing/cotea_ansible_run.py new file mode 100644 index 0000000..39f871a --- /dev/null +++ b/contributing/cotea_ansible_run.py @@ -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")