Skip to content

Commit

Permalink
feat: resolve ansible-playbook command
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulFarault committed Oct 31, 2023
1 parent e888eea commit 98d06c4
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion tdp/core/deployment/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import io
import logging
import subprocess
import shutil
from collections.abc import Iterable
from typing import Optional

Expand Down Expand Up @@ -77,13 +78,21 @@ def execute(
Returns:
A tuple with the state of the command and the output of the command in UTF-8.
"""
command = ["ansible-playbook"]
# Check if ansible is available
ansible_path = shutil.which("ansible-playbook")
if ansible_path is None:
logger.error("'ansible-playbook' not found in PATH")
return OperationStateEnum.FAILURE, b""
# Build command
command = [ansible_path]
command += [str(playbook)]
if host is not None:
command += ["--limit", host]
for extra_var in extra_vars or []:
command += ["--extra-vars", extra_var]
# Execute command
if self._dry:
# Operation always succeed in dry mode
logger.info("[DRY MODE] Ansible command: " + " ".join(command))
return OperationStateEnum.SUCCESS, b""
logger.debug("Ansible command: " + " ".join(command))
Expand Down

0 comments on commit 98d06c4

Please sign in to comment.