diff --git a/osism/tasks/__init__.py b/osism/tasks/__init__.py index ec53df2b..8349eee2 100644 --- a/osism/tasks/__init__.py +++ b/osism/tasks/__init__.py @@ -25,13 +25,14 @@ class Config: task_default_queue = "default" task_track_started = (True,) task_routes = { + "osism.tasks.ansible.*": {"queue": "osism-ansible"}, "osism.tasks.ceph.*": {"queue": "ceph-ansible"}, "osism.tasks.conductor.*": {"queue": "conductor"}, "osism.tasks.kolla.*": {"queue": "kolla-ansible"}, + "osism.tasks.kubernetes.*": {"queue": "kubernetes"}, "osism.tasks.netbox.*": {"queue": "netbox"}, - "osism.tasks.ansible.*": {"queue": "osism-ansible"}, - "osism.tasks.reconciler.*": {"queue": "reconciler"}, "osism.tasks.openstack.*": {"queue": "openstack"}, + "osism.tasks.reconciler.*": {"queue": "reconciler"}, } @@ -129,6 +130,21 @@ def run_ansible_in_environment( env=env, ) + # execute roles from kubernetes + elif worker == "kubernetes": + if locking: + lock.acquire() + + command = f"/run.sh {role} {joined_arguments}" + logger.info(f"RUN {command}") + p = subprocess.Popen( + command, + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, + shell=True, + env=env, + ) + # execute roles from ceph-ansible elif worker == "ceph-ansible": if locking: diff --git a/osism/tasks/kubernetes.py b/osism/tasks/kubernetes.py new file mode 100644 index 00000000..e8792b40 --- /dev/null +++ b/osism/tasks/kubernetes.py @@ -0,0 +1,27 @@ +# SPDX-License-Identifier: Apache-2.0 + +from celery import Celery + +from osism.tasks import Config, run_ansible_in_environment + +app = Celery("kubernetes") +app.config_from_object(Config) + + +@app.on_after_configure.connect +def setup_periodic_tasks(sender, **kwargs): + pass + + +@app.task(bind=True, name="osism.tasks.kubernetes.run") +def run(self, environment, playbook, arguments, publish=True, auto_release_time=3600): + return run_ansible_in_environment( + self.request.id, + "kubernetes", + environment, + playbook, + arguments, + publish, + False, + auto_release_time, + )