diff --git a/cf_remote/commands.py b/cf_remote/commands.py index 3d3f90b..92f0af9 100644 --- a/cf_remote/commands.py +++ b/cf_remote/commands.py @@ -761,10 +761,10 @@ def show(ansible_inventory): return 0 -def uninstall(hosts): +def uninstall(hosts, purge=False): errors = 0 for host in hosts: - errors += uninstall_host(host) + errors += uninstall_host(host, purge=purge) return errors diff --git a/cf_remote/main.py b/cf_remote/main.py index 053ef9d..28240de 100644 --- a/cf_remote/main.py +++ b/cf_remote/main.py @@ -103,6 +103,7 @@ def _get_arg_parser(): ) sp = subp.add_parser("uninstall", help="Uninstall CFEngine on the given hosts") + sp.add_argument("--purge", help="Complete uninstallation", action="store_true") sp.add_argument("--clients", "-c", help="Where to uninstall", type=str) sp.add_argument("--hub", help="Where to uninstall", type=str) sp.add_argument("--hosts", "-H", help="Where to uninstall", type=str) @@ -296,7 +297,7 @@ def run_command_with_args(command, args): ) elif command == "uninstall": all_hosts = (args.hosts or []) + (args.hub or []) + (args.clients or []) - return commands.uninstall(all_hosts) + return commands.uninstall(all_hosts, purge=args.purge) elif command == "packages": log.warning( "packages command is deprecated, please use the new command: download" diff --git a/cf_remote/remote.py b/cf_remote/remote.py index b8075a5..c41b600 100644 --- a/cf_remote/remote.py +++ b/cf_remote/remote.py @@ -283,7 +283,7 @@ def install_package(host, pkg, data, *, connection=None): @auto_connect -def uninstall_cfengine(host, data, *, connection=None): +def uninstall_cfengine(host, data, *, connection=None, purge=False): print("Uninstalling CFEngine on '{}'".format(host)) if "dpkg" in data["bin"]: @@ -328,6 +328,9 @@ def uninstall_cfengine(host, data, *, connection=None): run_command( host, "rm -rf /var/cfengine /opt/cfengine", connection=connection, sudo=True ) + if purge: + run_command(host, "rm -rf /var/log/CFEngine-Install*", connection=connection, sudo=True) + run_command(host, "rm -rf /etc/systemd/system/cf-php-fpm.service", connection=connection, sudo=True) @auto_connect @@ -553,7 +556,7 @@ def errors(self): @auto_connect -def uninstall_host(host, *, connection=None): +def uninstall_host(host, *, connection=None, purge=False): data = get_info(host, connection=connection) print_info(data) @@ -564,7 +567,7 @@ def uninstall_host(host, *, connection=None): ) ) - uninstall_cfengine(host, data, connection=connection) + uninstall_cfengine(host, data, connection=connection, purge=purge) data = get_info(host, connection=connection) if (not data) or data["agent_version"]: