/** extract key to a temp file, but one per machine, scheduled for deletion afterwards; * we extract the key because chef has no way to accept passphrases at present */ synchronized static File extractKeyFile(SshMachineLocation machine) { File f = new File(getExtractedKeysDir(), machine.getAddress().getHostName()+".pem"); if (f.exists()) return f; KeyPair data = machine.findKeyPair(); if (data==null) return null; try { f.deleteOnExit(); Files.write(SecureKeys.stringPem(data), f, Charset.defaultCharset()); return f; } catch (IOException e) { throw Throwables.propagate(e); } }
/** @deprecated since 0.6.0 (soon after introduced) use {@link #knifeConvergeRunList(String)} or {@link #knifeConvergeTask()} with fluent API */ @Deprecated public static KnifeTaskFactory<String> knifeConverge(final Function<? super Entity,String> runList, final boolean sudo, final String otherParameters) { return knifeConverge(runList, sudo, otherParameters, false); } /** @deprecated since 0.6.0 (soon after introduced) use {@link #knifeConvergeRunList(String)} or {@link #knifeConvergeTask()} with fluent API */ @Deprecated
/** knife converge task configured for this run list (and sudo) */ public static KnifeConvergeTaskFactory<String> knifeConvergeRunList(String runList) { return knifeConvergeTask() .knifeRunList(runList) .knifeSudo(true); }
@Override protected String startProcessesAtMachine(Supplier<MachineLocation> machineS) { ChefModes mode = entity().getConfig(ChefConfig.CHEF_MODE); if (mode == ChefModes.AUTODETECT) { ProcessTaskWrapper<Boolean> installCheck = DynamicTasks.queue( ChefServerTasks.isKnifeInstalled()); mode = installCheck.get() ? ChefModes.KNIFE : ChefModes.SOLO; log.debug("Using Chef in "+mode+" mode due to autodetect exit code "+installCheck.getExitCode()); } switch (mode) { case KNIFE: startWithKnifeAsync(); break; case SOLO: startWithChefSoloAsync(); break; default: throw new IllegalStateException("Unknown Chef mode "+mode+" when starting processes for "+entity()); } return "chef start tasks submitted ("+mode+")"; }
File keyfile = ChefServerTasks.extractKeyFile(machine); if (keyfile!=null) result.add("-i "+keyfile.getPath()); else result.add("-P "+checkNotNull(machine.findPassword(), "No password or private key data for "+machine));
protected void startWithKnifeAsync() { Entities.warnOnIgnoringConfig(entity(), ChefConfig.CHEF_RUN_LIST); Entities.warnOnIgnoringConfig(entity(), ChefConfig.CHEF_LAUNCH_ATTRIBUTES); DynamicTasks.queue( ChefServerTasks .knifeConvergeRunList("postgresql::server") .knifeAddAttributes(Jsonya .at("postgresql", "config").add( "port", entity().getAttribute(PostgreSqlNode.POSTGRESQL_PORT), "listen_addresses", "*").getRootMap()) .knifeAddAttributes(Jsonya .at("postgresql", "pg_hba").list().map().add( "type", "host", "db", "all", "user", "all", "addr", "0.0.0.0/0", "method", "md5").getRootMap()) // no other arguments currenty supported; chef will pick a password for us ); } protected void postStartCustom() {
/** knife converge task configured for this run list on windows (ssh) */ public static KnifeConvergeTaskFactory<String> knifeConvergeRunListWindowsSsh(String runList) { return knifeConvergeTask() .knifeRunList(runList) .knifeSudo(false) .knifeAddExtraBootstrapParameters("windows ssh"); }
/** knife converge task configured for this run list on windows (winrm) */ public static KnifeConvergeTaskFactory<String> knifeConvergeRunListWindowsWinrm(String runList) { return knifeConvergeTask() .knifeRunList(runList) .knifeSudo(false) .knifeAddExtraBootstrapParameters("windows winrm") .knifePortUseKnifeDefault(); }
/** @deprecated since 0.6.0 (soon after introduced) use {@link #knifeConvergeRunList(String)} or {@link #knifeConvergeTask()} with fluent API */ @Deprecated public static KnifeTaskFactory<String> knifeConverge() { return knifeConverge(new Function<Entity,String>() { public String apply(Entity input) { return Strings.join(Preconditions.checkNotNull(input.getConfig(ChefConfig.CHEF_RUN_LIST), "%s must be supplied for %s", ChefConfig.CHEF_RUN_LIST, input), ","); } }, true); } /** @deprecated since 0.6.0 (soon after introduced) use {@link #knifeConvergeRunList(String)} or {@link #knifeConvergeTask()} with fluent API */ @Deprecated
protected void startWithKnifeAsync() { DynamicTasks.queue( ChefServerTasks.knifeConvergeTask() .knifeRunList(Strings.join(Preconditions.checkNotNull(entity().getConfig(ChefConfig.CHEF_RUN_LIST), "%s must be supplied for %s", ChefConfig.CHEF_RUN_LIST, entity()), ",")) .knifeAddAttributes(entity().getConfig(CHEF_LAUNCH_ATTRIBUTES)) .knifeRunTwice(entity().getConfig(CHEF_RUN_CONVERGE_TWICE)) ); }
/** @deprecated since 0.6.0 (soon after introduced) use {@link #knifeConvergeRunList(String)} or {@link #knifeConvergeTask()} with fluent API */ @Deprecated public static KnifeTaskFactory<String> knifeConverge(final Function<? super Entity,String> runList, final boolean sudo) { return knifeConverge(runList, sudo, null); } /** @deprecated since 0.6.0 (soon after introduced) use {@link #knifeConvergeRunList(String)} or {@link #knifeConvergeTask()} with fluent API */ @Deprecated
/** @deprecated since 0.6.0 (soon after introduced) use {@link #knifeConvergeRunList(String)} or {@link #knifeConvergeTask()} with fluent API */ @Deprecated public static KnifeTaskFactory<String> knifeConverge(final String runList, boolean sudo) { return knifeConverge(Functions.constant(runList), sudo); } /** @deprecated since 0.6.0 (soon after introduced) use {@link #knifeConvergeRunList(String)} or {@link #knifeConvergeTask()} with fluent API */ @Deprecated