Skip to content

Commit

Permalink
Merge pull request #103 from olehermanse/uninstall-purge
Browse files Browse the repository at this point in the history
ENT-12386: Made uninstall remove "everything"
  • Loading branch information
olehermanse authored Dec 18, 2024
2 parents 6fccfb4 + bb19a4f commit a5c1588
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions cf_remote/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
3 changes: 2 additions & 1 deletion cf_remote/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"
Expand Down
9 changes: 6 additions & 3 deletions cf_remote/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,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"]:
Expand Down Expand Up @@ -329,6 +329,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
Expand Down Expand Up @@ -554,7 +557,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)

Expand All @@ -565,7 +568,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"]:
Expand Down

0 comments on commit a5c1588

Please sign in to comment.