apenella / go-ansible

Go-ansible is a Go package that enables the execution of ansible-playbook or ansible commands directly from Golang applications. It supports a wide range of options for each command, enabling smooth integration of Ansible functionality into your projects.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Async callback

clementblaise opened this issue · comments

Right now the only way to have result while launching a playbook is to launch ansible-playbook with de default callback. But this doesn't allow the use of result on the fly.

All other callback are synchronous, the execution need finish to get result (ex: json callback)

I went through the Ansible community callback plugins but none would enable async. Though it was been done for specific use case like AWX or ARA.

Would you be open to the idea of adding such feature ? It would require writing a custom Ansible callback plugin

hi @clementblaise
I don't know if I catch your proposal but go-ansible is just a wrapper to call ansble commands and it couldn't update ansible behavior.

If you mean to run multiple ansible commands concurrently you could do it but managing it from outside the library.
I have done it on stevedore project.
On that project there is a dispatcher with n workers an you could run as many concurrent commands as workers you have.
On the snipped below you could see two ansible-playbooks running at the same time. Since the playbooks run concurrently their outputs are mixed each other.

$ stevedore build ubuntu -P
 ansible-playbook  --inventory ./inventory/containers.ini --extra-vars '{<redacted>}'  ./site.yml
 ansible-playbook  --inventory ./inventory/containers.ini --extra-vars '{<redacted>}'  ./site.yml
ubuntu:18.04 ──
ubuntu:18.04 ── PLAY [builder] *****************************************************************
ubuntu:16.04 ──
ubuntu:16.04 ── PLAY [builder] *****************************************************************
ubuntu:16.04 ──
ubuntu:16.04 ── TASK [Gathering Facts] *********************************************************
ubuntu:18.04 ──
ubuntu:18.04 ── TASK [Gathering Facts] *********************************************************
ubuntu:16.04 ── ok: [image_builder]
ubuntu:18.04 ── ok: [image_builder]
ubuntu:16.04 ──
ubuntu:16.04 ── skipping: [image_builder]
ubuntu:18.04 ── skipping: [image_builder]
ubuntu:16.04 ──
ubuntu:16.04 ── PLAY [Rise Up an empty container] **********************************************
ubuntu:16.04 ──
ubuntu:16.04 ── TASK [Gathering Facts] *********************************************************
ubuntu:18.04 ── changed: [image_builder]
ubuntu:18.04 ──
ubuntu:18.04 ── PLAY [Rise Up an empty container] **********************************************
ubuntu:18.04 ──
ubuntu:18.04 ── TASK [Gathering Facts] *********************************************************
ubuntu:16.04 ── ok: [image_builder]
ubuntu:16.04 ──
ubuntu:16.04 ── TASK [Include vars to prepare container builder ubuntu] ************************
ubuntu:18.04 ── ok: [image_builder]
ubuntu:16.04 ── ok: [image_builder]
ubuntu:16.04 ──
ubuntu:16.04 ── TASK [Validate container_name variable] ****************************************
ubuntu:18.04 ──
ubuntu:18.04 ── TASK [Include vars to prepare container builder ubuntu] ************************
ubuntu:16.04 ── skipping: [image_builder]
ubuntu:16.04 ──
ubuntu:16.04 ── TASK [Validate target_namespace variable] **************************************
ubuntu:16.04 ── skipping: [image_builder]
ubuntu:18.04 ── ok: [image_builder]
ubuntu:18.04 ──
ubuntu:18.04 ── TASK [Validate container_name variable] ****************************************
ubuntu:16.04 ──
...

Hi @apenella, I was looking for a way to programmatically get tasks status in a playbook while it is still running.

Your response is not exactly answering to the specific issue, but it does provide an alternative implementation of what I'm looking to do. The goal was to track the progress of multiple playbook that are run in parallel with a progress bar.

Altogether what I wanted to do initially will take too long, so I am probably going to implement what you suggested, thanks for your response.

hi @clementblaise
I been thinking about you said, the progress bar, and it should be tackled from ansible side, using a plugin or whatelse. go-ansible is just a wrapper that execute ansible commands and does not know anything that happens inside ansible.

If you don't mind, since you have a solution to run several playbooks concurrently, I close that issue.

Thanks for all!