From 5194b248a9b99483c678d402c288567817348387 Mon Sep 17 00:00:00 2001 From: Ole Herman Schumacher Elgesem Date: Tue, 9 Apr 2024 17:19:19 +0200 Subject: [PATCH] Fixed issue where policy server IP was not printed in info command sudo is already used / needed for other parts of cf-remote (such as cf-remote install and deploy), so attempting to use it here should be acceptable. Ticket: CFE-4361 Signed-off-by: Ole Herman Schumacher Elgesem --- cf_remote/remote.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cf_remote/remote.py b/cf_remote/remote.py index 450fda5..edb1d30 100644 --- a/cf_remote/remote.py +++ b/cf_remote/remote.py @@ -217,6 +217,12 @@ def get_info(host, *, users=None, connection=None): data["policy_server"] = ssh_cmd( connection, "cat /var/cfengine/policy_server.dat" ) + if user != "root" and not data["policy_server"]: + # If we are not SSHing as root and we failed to read + # the policy_server.dat file try again using sudo: + data["policy_server"] = ssh_sudo( + connection, "cat /var/cfengine/policy_server.dat" + ) agent = r"/var/cfengine/bin/cf-agent" data["agent"] = agent