Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions cf_remote/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -1056,10 +1056,10 @@ def agent(hosts, bootstrap=None):
for host in hosts:
data = get_info(host)

if not data["agent_location"]:
if not data["agent"]:
raise CFRExitError("CFEngine not installed on {}".format(host))

command = "{}".format(data["agent_location"])
command = "{}".format(data["agent"])
if bootstrap:
command += "--bootstrap {}".format(bootstrap[0])

Expand Down
32 changes: 25 additions & 7 deletions cf_remote/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,16 +216,31 @@ def get_info(host, *, users=None, connection=None):
data["ssh_user"] = user

systeminfo = ssh_cmd(connection, "systeminfo")
if systeminfo and "command not found" not in systeminfo:
assert systeminfo is None or (type(systeminfo) is str and len(systeminfo) > 0)
# Note: ssh_cmd is supposed to return None on failure however, it seems
# like there are some cases where it returns output on failure
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

specifically I think this is the case e.g. centos-7 which has a rather old version of the script command which we use in case no pty is present (the vagrant shell provisioning case). Agreed about "command not found" being not very robust... we could be more specific or try to find another way around no-pty case other than script command that works back info old distributions like centos-7.

# because the exit code was 0
# TODO / Workaround:
if systeminfo == "bash: systeminfo: command not found":
systeminfo = None
if systeminfo:
data["os"] = "windows"
data["systeminfo"] = parse_systeminfo(systeminfo)
data["package_tags"] = ["x86_64", "msi"]
data["arch"] = "x86_64"
agent = r"& 'C:\Program Files\Cfengine\bin\cf-agent.exe'"
data["agent"] = agent
version_cmd = powershell("{} -V".format(agent))
data["agent_version"] = parse_version(ssh_cmd(connection, version_cmd))
version_output = ssh_cmd(connection, version_cmd)
if version_output:
data["agent"] = agent
else:
data["agent"] = None
data["agent_version"] = parse_version(version_output)
data["role"] = "client"
if data["agent_version"]:
data["role"] = "client"
else:
data["role"] = None
else:
data["os"] = "unix"

Expand Down Expand Up @@ -270,12 +285,15 @@ def get_info(host, *, users=None, connection=None):

data["package_tags"] = get_package_tags(os_release_data, redhat_release_data)
data["cfengine_id"] = discovery.get("NTD_CFENGINE_ID")
data["agent_location"] = discovery.get("NTD_CFAGENT_PATH")
data["agent"] = discovery.get("NTD_CFAGENT_PATH")
data["policy_server"] = discovery.get("NTD_POLICY_SERVER")
agent = r"/var/cfengine/bin/cf-agent"
data["agent"] = agent
data["agent_version"] = parse_version(discovery.get("NTD_CFAGENT_VERSION"))
data["role"] = "hub" if discovery.get("NTD_CFHUB") else "client"
if discovery.get("NTD_CFHUB"):
data["role"] = "hub"
elif discovery.get("NTD_CFAGENT_PATH"):
data["role"] = "client"
else:
data["role"] = None

data["bin"] = {}
for bin in [
Expand Down
3 changes: 2 additions & 1 deletion cf_remote/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import shutil
import signal
import subprocess
from typing import Union
from urllib.parse import urlparse

from cf_remote import aramid
Expand Down Expand Up @@ -243,7 +244,7 @@ def scp(file, remote, connection=None, rename=None, hide=False):
return 0


def ssh_cmd(connection, cmd, errors=False, needs_pty=True):
def ssh_cmd(connection, cmd, errors=False, needs_pty=True) -> Union[str, None]:
assert connection

if needs_pty:
Expand Down
Loading