def install_host(host, *, hub=False, package=None, bootstrap=None, version=None, demo=False, call_collect=False, connection=None, edition=None): data = get_info(host, connection=connection) print_info(data) if not package: tags = [] if edition == "enterprise": tags.append("hub" if hub else "agent") tags.append("64" if data["arch"] in ["x86_64", "amd64"] else data["arch"]) extension = None if "package_tags" in data and "msi" in data["package_tags"]: extension = ".msi" elif "dpkg" in data["bin"]: extension = ".deb" elif "rpm" in data["bin"]: extension = ".rpm" releases = Releases(edition) release = releases.default if version: release = releases.pick_version(version) artifacts = release.find(tags, extension) if not artifacts: user_error( "Could not find an appropriate package for host, please use --{}-package" .format("hub" if hub else "client")) artifact = artifacts[-1] package = download_package(artifact.url) scp(package, host, connection=connection) package = basename(package) install_package(host, package, data, connection=connection) data = get_info(host, connection=connection) if data["agent_version"] and len(data["agent_version"]) > 0: print("CFEngine {} was successfully installed on '{}'".format( data["agent_version"], host)) else: print("Installation failed!") sys.exit(1) if bootstrap: bootstrap_host(data, policy_server=bootstrap, connection=connection) if demo: if hub: demo_lib.install_def_json(host, connection=connection, call_collect=call_collect) demo_lib.agent_run(data, connection=connection) demo_lib.disable_password_dialog(host) demo_lib.agent_run(data, connection=connection)
def install_host( host, *, hub=False, package=None, bootstrap=None, version=None, demo=False, call_collect=False, connection=None): data = get_info(host, connection=connection) print_info(data) if not package: tags = [] tags.append("hub" if hub else "agent") tags.append("64" if data["arch"] in ["x86_64", "amd64"] else data["arch"]) extension = None if "dpkg" in data["bin"]: extension = ".deb" elif "rpm" in data["bin"]: extension = ".rpm" releases = Releases() release = releases.default if version: release = releases.pick_version(version) artifacts = release.find(tags, extension) if not artifacts: user_error( "Could not find an appropriate package for host, please use --{}-package".format( "hub" if hub else "client")) artifact = artifacts[-1] package = download_package(artifact.url) scp(package, host, connection=connection) package = basename(package) install_package(host, package, data, connection=connection) data = get_info(host, connection=connection) if data["agent_version"] and len(data["agent_version"]) > 0: print( "CFEngine {} was successfully installed on '{}'".format(data["agent_version"], host)) else: print("Installation failed!") sys.exit(1) if bootstrap: bootstrap_host(host, policy_server=bootstrap, connection=connection) if demo: if hub: demo_lib.install_def_json(host, connection=connection, call_collect=call_collect) demo_lib.agent_run(host, connection=connection) demo_lib.disable_password_dialog(host) demo_lib.agent_run(host, connection=connection)
def install_host(host, *, hub=False, packages=None, bootstrap=None, version=None, demo=False, call_collect=False, connection=None, edition=None, show_info=True, remote_download=False, trust_keys=None): data = get_info(host, connection=connection) if show_info: print_info(data) package = None if packages and type(packages) is str: package = packages elif packages and len(packages) == 1: package = packages[0] if not package: tags = [] if edition == "enterprise": tags.append("hub" if hub else "agent") tags.append("64" if data["arch"] in ["x86_64", "amd64"] else data["arch"]) if data["arch"] in ["i386", "i486", "i586", "i686"]: tags.append("32") extension = None if "package_tags" in data and "msi" in data["package_tags"]: extension = ".msi" data["package_tags"].remove("msi") elif "dpkg" in data["bin"]: extension = ".deb" elif "rpm" in data["bin"]: extension = ".rpm" if "package_tags" in data and data["package_tags"]: tags.extend(data["package_tags"]) if packages is None: # No commandd line argument given package = _package_from_releases(tags, extension, version, edition, remote_download) else: package = _package_from_list(tags, extension, packages) if not package: log.error("Installation failed - no package found!") return 1 if remote_download: print(f"Downloading '{package}' on '{host}' using curl") r = ssh_cmd(cmd="curl --fail -O {}".format(package), connection=connection, errors=True) if r is None: return 1 else: scp(package, host, connection=connection) package = basename(package) install_package(host, package, data, connection=connection) data = get_info(host, connection=connection) if data["agent_version"] and len(data["agent_version"]) > 0: print("CFEngine {} was successfully installed on '{}'".format( data["agent_version"], host)) else: log.error("Installation failed!") return 1 if trust_keys: for key in trust_keys: scp(key, host, connection=connection) run_command(host, "mv %s /var/cfengine/ppkeys/" % basename(key), connection=connection, sudo=True) if bootstrap: ret = bootstrap_host(data, policy_server=bootstrap, connection=connection, trust_server=(not trust_keys)) if not ret: return 1 if demo: if hub: demo_lib.install_def_json(host, connection=connection, call_collect=call_collect) demo_lib.agent_run(data, connection=connection) demo_lib.disable_password_dialog(host) demo_lib.agent_run(data, connection=connection) return 0