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

Made uninstall remove "everything" #101

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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 @@ -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", nargs="?", const=True, type=bool)
olehermanse marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -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"]:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand All @@ -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"]:
Expand Down
Loading