protected function getInventoryFolder($ansibleSettings, $inventoryFolder)
{
// is there an Ansible.cfg file?
$cfgFile = $ansibleSettings->dir . DIRECTORY_SEPARATOR . 'ansible.cfg';
if (!file_exists($cfgFile)) {
return $inventoryFolder;
}
// if we get here, there is a config file to parse
$ansibleCfg = parse_ini_file($cfgFile, true);
if (!is_array($ansibleCfg)) {
// we can't parse the file
return $inventoryFolder;
}
if (!isset($ansibleCfg['defaults'], $ansibleCfg['defaults']['hostfile'])) {
// there's no inventory in the config file
return $inventoryFolder;
}
// is the inventory a folder?
$invDir = $inventoryFolder . DIRECTORY_SEPARATOR . $ansibleCfg['defaults']['hostfile'];
if (is_dir($invDir)) {
// this is where we need to write our variables to
return $invDir;
}
// give up
return $inventoryFolder;
}