theforeman / foreman-ansible-modules

Ansible modules for interacting with the Foreman API and various plugin APIs such as Katello
GNU General Public License v3.0
149 stars 166 forks source link

When publishing a ContentViewVersion to a LifeCycleEnvironment it would be helpful to have a way to wait for SmartProxy/Capsule synchronization to finish #1609

Open dabelenda opened 1 year ago

dabelenda commented 1 year ago
SUMMARY

In a use-case where we use a load-balanced setup of SmartProxies to distribute content, we want to use a single playbook to manage the ContentViewVersion promotion and the update of the machines to have a consistent and reproducible way to perform updates on clusters. This way we can perform all preparations for update, safety checks, and reboots in the playbook, and not need manual validation that the SmartProxies are synchronized.

However, since the Capsule Synchronization task is asynchronous to ContentViewVersion Promotions.

ISSUE TYPE

Currently there is no "native" way to chain ContentViewVersion Promotion and updating of the machines automatically when SmartProxies are involved.

A helper action to wait for completion of SmartProxy synchronization (or a generic way to wait for Foreman Task(s) completion) would help greatly in that case. It is involved to wait this in pure ansible, so I personnally think that it makes sense to have it in this repository.

evgeni commented 1 year ago

We have code for waiting for tasks: https://github.com/theforeman/foreman-ansible-modules/blob/d743378819718ab322e2bdcb6fe8c130d6929930/plugins/module_utils/foreman_helper.py#L1180-L1192

So we could expose that as a wait_for_task module and that part would be solved.

However, the problem will be to find out which task to wait for. As far as I know, the "sync proxies" task is triggered asynchronously from the publish/promote tasks, so there is no reference when the publish task is done what to wait on next.

Ideally, Katello would tell us what it spawned, so we can optionally wait on that. If it doesn't, we'd have to resort to a search, but that can be unreliable :/

dabelenda commented 1 year ago

From what I can see in the API, nothing tells us where the CapsuleSync tasks originate from...

{"parent_task_id":null,"start_at":"2023-05-23 15:57:24 +0200","start_before":null,"external_id":"f8be7b6b-815d-4db1-8eed-0aa9d0363081","id":"d2e946c0-e30a-439e-a7b6-913187f4e82d","label":"Actions::Katello::ContentView::CapsuleSync","pending":false,"action":"Sync Content View on Capsule(s)","username":"satellite-svc-accnt","started_at":"2023-05-23 15:57:24 +0200","ended_at":"2023-05-23 15:57:38 +0200","duration":"00:00:14.575","state":"stopped","result":"success","progress":1.0,"input":{"current_request_id":"4fafbba8-e670-4191-a401-0998404166ff","current_timezone":"UTC","current_organization_id":null,"current_location_id":null,"current_user_id":26},"output":{},"humanized":{"action":"Sync Content View on Capsule(s)","input":"","output":"","errors":[]},"cli_example":null,"available_actions":{"cancellable":false,"resumable":false},"execution_plan":{"state":"stopped","cancellable":false},"failed_steps":[],"running_steps":[],"help":null,"has_sub_tasks":true,"locks":[],"links":[],"username_path":"<a href=\"/users/26-satellite-svc-accnt/edit\">satellite-svc-accnt</a>","dynflow_enable_console":true}

The Promote task does not tell us which CapsuleSync task it spawned either...

{"parent_task_id":null,"start_at":"2023-05-23 15:57:11 +0200","start_before":null,"external_id":"ae8c9b71-035e-4c44-af44-8784f750829c","id":"055fe458-6b1d-44ee-a634-0c6051661256","label":"Actions::Katello::ContentView::Promote","pending":false,"action":"Promote content view 'RHEL7 ldap'; organization 'EXOP-GE'","username":"satellite-svc-accnt","started_at":"2023-05-23 15:57:11 +0200","ended_at":"2023-05-23 15:57:24 +0200","duration":"00:00:13.091","state":"stopped","result":"success","progress":1.0,"input":{"content_view":{"id":182,"name":"RHEL7 ldap","label":"RHEL7_ldap"},"organization":{"id":1,"name":"EXOP-GE","label":"EXOP-GE"},"environments":["ldap_rhel7-test"],"services_checked":["pulp3","candlepin","candlepin_auth"],"current_request_id":"4fafbba8-e670-4191-a401-0998404166ff","current_timezone":"UTC","current_organization_id":null,"current_location_id":null,"current_user_id":26},"output":{},"humanized":{"action":"Promote","input":[["content_view",{"text":"content view 'RHEL7 ldap'","link":"/content_views/182/versions"}],["organization",{"text":"organization 'EXOP-GE'","link":"/organizations/1/edit"}]],"output":"","errors":[]},"cli_example":null,"available_actions":{"cancellable":false,"resumable":false},"execution_plan":{"state":"stopped","cancellable":false},"failed_steps":[],"running_steps":[],"help":null,"has_sub_tasks":false,"locks":[],"links":[{"resource_type":"Katello::ContentView","resource_id":182,"exclusive":false},{"resource_type":"Organization","resource_id":1,"exclusive":false}],"username_path":"<a href=\"/users/26-satellite-svc-accnt/edit\">satellite-svc-accnt</a>","dynflow_enable_console":true}

The ContentViewVersion has a reference to the latest task associated with it, but it is the Promote Task not the CapsuleSync...

So wherever I look in the API the information does not seem to be present...

evgeni commented 1 year ago

I've opened https://projects.theforeman.org/issues/36434 as an RFE for Katello.

dabelenda commented 1 year ago

Ok, that would indeed be the best possible way to search for the capsule sync task. While waiting for this RFE to be implemented, would it be possible to get an ansible module to wait on a task by ID?

This would allow to search for all capsule sync tasks running after the Promote and wait on all of them. My guess is that after the RFE implemented the search could be refined to have more pin-point waiting.

dabelenda commented 1 year ago

Hello,

is there a way to know what is the status of this? Are you working on it or is it in a backlog ?

dabelenda commented 1 year ago

Hello @evgeni

no news about the state of this request ?

evgeni commented 1 year ago

There would be news in here, if I'd have any to share ;-)

That said, it is on my todo list, but not in the "today" or "this week" buckets :(

dabelenda commented 1 year ago

The reason I am asking is because I could get my employer to assign someone to make a PR for this feature. But the process itself takes time, and the person would need to learn how to contribute to this project. If I don't have a vision on the time it would take for this feature to get there without our involvement, I cannot decide if it is worth starting this process.

This RFE served two purposes:

evgeni commented 1 year ago

https://github.com/theforeman/foreman-ansible-modules/pull/1656 has been merged and we now have a module for waiting on tasks, thanks @JGodin-C2C!

Now my question would be: should we consider this issue sufficiently done, or shall we add an explicit "wait on proxy sync" example, or even wait until https://projects.theforeman.org/issues/36434 is implemented?

(I personally lean towards the example route, but I am no BDFL ;))