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

add ssh port to inventory #560

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public AnsibleImageMeasureCommand(T parameters, CommandContext cmdContext) {
@Override
protected AnsibleCommandConfig createCommand() {
return new AnsibleCommandConfig()
.hosts(getVds())
.host(getVds())
.variable("image_path", getParameters().getVariables().get("image_path"))
.playAction(getParameters().getPlayAction())
// /var/log/ovirt-engine/ova/ovirt-image-measure-ansible-{hostname}-{correlationid}-{timestamp}.log
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ protected AnsibleCommandConfig createCommand() {
EngineLocalConfig.getInstance().getInteger("ANSIBLE_PLAYBOOK_EXEC_DEFAULT_TIMEOUT"));
Map<String, Object> vars = getParameters().getVariables();
return new AnsibleCommandConfig()
.hosts(getVds())
.host(getVds())
.variable("target_directory", vars.get("target_directory"))
.variable("entity_type", vars.get("entity_type"))
.variable("ova_size", vars.get("ova_size"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private String runAnsibleQueryOvaInfoPlaybook() {
EngineLocalConfig.getInstance().getInteger("ANSIBLE_PLAYBOOK_EXEC_DEFAULT_TIMEOUT"));
VDS host = vdsDao.get(getParameters().getVdsId());
AnsibleCommandConfig command = new AnsibleCommandConfig()
.hosts(host)
.host(host)
.variable("ovirt_query_ova_path", getParameters().getPath())
.variable("list_directory", getParameters().isListDirectory() ? "True" : "False")
.variable("entity_type", getEntityType().name().toLowerCase())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ private boolean executeValidation() {

private void runAnsibleMigrationCerts() {
AnsibleCommandConfig commandConfig = new AnsibleCommandConfig()
.hosts(getVds())
.host(getVds())
// /var/log/ovirt-engine/host-deploy/ovirt-host-mgmt-ansible-migration-certs-{hostname}-{correlationid}-{timestamp}.log
.logFileDirectory(AnsibleConstants.HOST_DEPLOY_LOG_DIRECTORY)
.logFilePrefix("ovirt-host-mgmt-ansible-migration-certs")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ private void runAnsibleRemovePlaybook() {

try {
AnsibleCommandConfig commandConfig = new AnsibleCommandConfig()
.hosts(vds)
.host(vds)
.playbook(AnsibleConstants.HOST_REMOVE_PLAYBOOK);

auditLogDirector.log(auditable, AuditLogType.VDS_ANSIBLE_HOST_REMOVE_STARTED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private ValidationResult validateTargetFolder() {
long timeout = TimeUnit.MINUTES.toSeconds(
EngineLocalConfig.getInstance().getInteger("ANSIBLE_PLAYBOOK_EXEC_DEFAULT_TIMEOUT"));
AnsibleCommandConfig commandConfig = new AnsibleCommandConfig()
.hosts(getVds())
.host(getVds())
.variable("target_directory", getParameters().getDirectory())
.variable("validate_only", "True")
.variable("ansible_timeout", timeout)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ private boolean runAnsibleImportOvaPlaybook(String disksPathToFormat) {
long timeout = TimeUnit.MINUTES.toSeconds(
EngineLocalConfig.getInstance().getInteger("ANSIBLE_PLAYBOOK_EXEC_DEFAULT_TIMEOUT"));
AnsibleCommandConfig commandConfig = new AnsibleCommandConfig()
.hosts(getVds())
.host(getVds())
.variable("ovirt_import_ova_path", getParameters().getOvaPath())
.variable("ovirt_import_ova_disks", disksPathToFormat)
.variable("ovirt_import_ova_image_mappings",
Expand Down Expand Up @@ -146,7 +146,7 @@ private boolean runAnsibleImportOvaPlaybook(String disksPathToFormat) {

private String runAnsibleOvaExternalDataPlaybook() {
AnsibleCommandConfig command = new AnsibleCommandConfig()
.hosts(getVds())
.host(getVds())
.variable("ovirt_ova_path", getParameters().getOvaPath())
// /var/log/ovirt-engine/ova/ovirt-ova-external-data-ansible-{hostname}-{timestamp}.log
.logFileDirectory(ExtractOvaCommand.IMPORT_OVA_LOG_DIRECTORY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ private void runAnsibleCreateBrickPlaybook() throws IOException, InterruptedExce
: getParameters().getNoOfPhysicalDisksInRaidVolume();

AnsibleCommandConfig commandConfig = new AnsibleCommandConfig()
.hosts(getVds())
.host(getVds())
.variable("ssd", ssdDevice)
.variable("disks", disks)
.variable("vgname", "RHGS_vg_" + getParameters().getLvName())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public HostUpgradeManagerResult checkForUpdates(final VDS host) {
AnsibleReturnValue ansibleReturnValue = null;
try {
AnsibleCommandConfig command = new AnsibleCommandConfig()
.hosts(host)
.host(host)

// /var/log/ovirt-engine/host-deploy/ovirt-host-mgmt-ansible-check-{hostname}-{correlationid}-{timestamp}.log
.logFileDirectory(AnsibleConstants.HOST_DEPLOY_LOG_DIRECTORY)
Expand Down Expand Up @@ -136,7 +136,7 @@ public EnumSet<VDSType> getHostTypes() {
@Override
public void update(final VDS host, int timeout) {
AnsibleCommandConfig commandConfig = new AnsibleCommandConfig()
.hosts(host)
.host(host)
// /var/log/ovirt-engine/host-deploy/ovirt-host-mgmt-ansible-{hostname}-{correlationid}-{timestamp}.log
.logFileDirectory(AnsibleConstants.HOST_DEPLOY_LOG_DIRECTORY)
.logFilePrefix("ovirt-host-mgmt-ansible")
Expand Down Expand Up @@ -170,7 +170,6 @@ private void setAnsibleCommandConfigVars(AnsibleCommandConfig command, final VDS
// PKI variables:
.variable("ovirt_pki_dir", config.getPKIDir())
.variable("ovirt_vds_hostname", host.getHostName())
.variable("ansible_port", host.getSshPort())
.variable("ovirt_san", CertificateUtils.getSan(host.getHostName()))
.variable("ovirt_engine_usr", config.getUsrDir())
.variable("ovirt_organizationname", Config.getValue(ConfigValues.OrganizationName))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public boolean validate() {
protected void executeCommand() {
setVdsStatus(VDSStatus.Installing);
AnsibleCommandConfig commandConfig = new AnsibleCommandConfig()
.hosts(getVds())
.host(getVds())
.variable("ovirt_pki_dir", config.getPKIDir())
.variable("ovirt_vds_hostname", getVds().getHostName())
.variable("ovirt_san", CertificateUtils.getSan(getVds().getHostName()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ private void runAnsibleHostDeployPlaybook() {
}
String clusterVersion = hostCluster.getCompatibilityVersion().getValue();
AnsibleCommandConfig commandConfig = new AnsibleCommandConfig()
.hosts(vds)
.host(vds)
.variable("host_deploy_cluster_version", clusterVersion)
.variable("host_deploy_cluster_name", hostCluster.getName())
.variable("host_deploy_cluster_switch_type",
Expand Down Expand Up @@ -384,7 +384,7 @@ private void runAnsibleReconfigureGluster(String oldGlusterClusterNode, String f
log.info("Started Replace Host playbook");
VDS vds = getVds();
AnsibleCommandConfig commandConfig = new AnsibleCommandConfig()
.hosts(maintenanceVds)
.host(maintenanceVds)
.variable("gluster_maintenance_old_node", oldGlusterClusterNode)
.variable("gluster_maintenance_new_node", newGlusterClusterNode)
.variable("gluster_maintenance_cluster_node", firstGlusterClusterNode)
Expand Down Expand Up @@ -429,7 +429,7 @@ private List<VDS> getOnlyActiveHosts(List<VDS> hostlist) {
private void fetchHostedEngineConfigFile(String tmpHEConfigFileName) {
VDS vds = vdsDao.get(hostedEngineHelper.getRunningHostId());
AnsibleCommandConfig commandConfig = new AnsibleCommandConfig()
.hosts(vds)
.host(vds)
.variable("temp_he_config_file", tmpHEConfigFileName)
// /var/log/ovirt-engine/host-deploy/ovirt-host-deploy-ansible-{hostname}-{correlationid}-{timestamp}.log
.logFileDirectory(AnsibleConstants.HOST_DEPLOY_LOG_DIRECTORY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,11 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.stream.Collectors;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.ovirt.engine.core.common.businessentities.VDS;
import org.ovirt.engine.core.utils.CorrelationIdTracker;
import org.ovirt.engine.core.utils.EngineLocalConfig;
Expand All @@ -34,8 +30,7 @@ public class AnsibleCommandConfig implements LogFileConfig, PlaybookConfig {
public static final String ANSIBLE_EXECUTION_METHOD = "start";

private String cluster;
private List<String> hostnames;
private List<VDS> hosts;
private VDS host;
private Map<String, Object> variables;
private String variableFilePath;
private String limit;
Expand Down Expand Up @@ -107,10 +102,6 @@ public String playbook() {
return playbook;
}

public List<String> hostnames() {
return shallowCopy(hostnames);
}

public String cluster() {
return cluster;
}
Expand Down Expand Up @@ -139,8 +130,8 @@ public String playAction() {
return playAction;
}

public List<VDS> hosts() {
return hosts;
public VDS host() {
return this.host;
}

/**
Expand Down Expand Up @@ -186,11 +177,8 @@ public AnsibleCommandConfig cluster(String cluster) {
return this;
}

public AnsibleCommandConfig hosts(VDS... hosts) {
this.hostnames = Arrays.stream(hosts)
.map(h -> h.getHostName())
.collect(Collectors.toList());
this.hosts = Arrays.asList(hosts);
public AnsibleCommandConfig host(VDS host) {
this.host = host;
return this;
}

Expand Down Expand Up @@ -307,15 +295,15 @@ private File setupAnsibleRunnerExecutionDir() throws IOException {
}

private void createHostFile(File inventory) {
File hostsFile = new File(String.format("%1$s/hosts", inventory));
if (CollectionUtils.isNotEmpty(hostnames())) {
try {
hostsFile.createNewFile();
Files.write(hostsFile.toPath(), StringUtils.join(hostnames(), System.lineSeparator()).getBytes());
} catch (IOException ex) {
throw new AnsibleRunnerCallException(
String.format("Failed to create inventory file '%s':", hostsFile.toString()), ex);
}
File hostFile = new File(String.format("%1$s/hosts", inventory));
try {
hostFile.createNewFile();
Files.write(hostFile.toPath(),
String.format(this.host.getHostName() + " ansible_port=%1$s", this.host.getSshPort()).getBytes());
smelamud marked this conversation as resolved.
Show resolved Hide resolved
} catch (IOException ex) {
throw new AnsibleRunnerCallException(
String.format("Failed to create inventory file '%s':", hostFile.toString()),
ex);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ public AnsibleReturnValue runCommand(AnsibleCommandConfig command,
}

public AnsibleReturnValue runCommand(AnsibleCommandConfig commandConfig, int timeout, BiConsumer<String, String> fn, boolean async) {
if (commandConfig.host() == null) {
throw new AnsibleRunnerCallException("Invalid host");
}
if (timeout <= 0) {
timeout = EngineLocalConfig.getInstance().getInteger("ANSIBLE_PLAYBOOK_EXEC_DEFAULT_TIMEOUT");
}
Expand Down Expand Up @@ -190,14 +193,8 @@ public AnsibleReturnValue runCommand(AnsibleCommandConfig commandConfig, int tim
}

private AuditLogable createAuditLogable(AnsibleCommandConfig command, String taskName) {
if (command.hosts() == null) {
return AuditLogableImpl.createEvent(
command.correlationId(),
Map.of("Message", taskName, "PlayAction", command.playAction())
);
}
return AuditLogableImpl.createHostEvent(
command.hosts().get(0),
command.host(),
command.correlationId(),
Map.of("Message", taskName, "PlayAction", command.playAction())
);
Expand Down