Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve ansible-playbook command before execution #492

Merged
merged 2 commits into from
Oct 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions tdp/core/deployment/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import io
import logging
import shutil
import subprocess
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", str(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.extend(["--limit", host])
if extra_vars is not None:
for extra_var in extra_vars:
command.extend(["--extra-vars", extra_var])
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