Skip to content
Snippets Groups Projects
Commit dc253a18 authored by hahn's avatar hahn
Browse files

task #4637 - awx plugin - handle empty vars

parent 98862ce8
Branches
No related tags found
1 merge request!12AWX - handling leerer AWX felder
......@@ -17,7 +17,15 @@ class rollout_awx extends rollout_base {
// no specific checks needed ... always true
return true;
}
/**
* check access to a deploy target
*/
public function checkConnectionToTarget() {
// do nothing ... always true
return true;
}
/**
* make an http get request and return the response body
* it is called by _makeRequest
......@@ -71,8 +79,6 @@ class rollout_awx extends rollout_base {
return $aReturn;
}
/**
* get AWX inventories and return them as array for select box
* [id] => array('value' => [ID], 'label' => [NAME] [ID])
......@@ -129,13 +135,6 @@ class rollout_awx extends rollout_base {
return $aReturn;
}
/**
* check access to a deploy target
*/
public function checkConnectionToTarget() {
// do nothing ... always true
return true;
}
/**
* get array with commands to execute to deploy a package
......@@ -146,17 +145,30 @@ class rollout_awx extends rollout_base {
public function getDeployCommands($sPhase){
$aReturn=array();
$aConfig=$this->getConfig($sPhase);
// ----- Checks:
if($aConfig['extravars']){
$aTmp=json_decode($aConfig['extravars']);
if (!$aTmp || !count($aTmp) ){
$aReturn[]='echo "ERROR: Value in extravars has wrong Syntax - this is no JSON: '.$aConfig['extravars'].'"';
}
$aConfig['extravars']=json_decode($aTmp, 1);
}
if(!(int)$aConfig['inventory']){
$aReturn[]='echo "ERROR: no inventory was given."; exit 1';
}
$sJson='{
"inventory": "'.$aConfig['inventory'].'",
"limit": "'.$aConfig['limit'].'",
"job_tags": "'.$aConfig['tags'].'",
"extra_vars": '.$aConfig['extravars'].'
}';
$aBodyvars=array();
foreach(['inventory'=>'inventory', 'limit'=>'limit', 'job_tags'=>'tags', 'extra_vars'=>'extravars'] as $sParam=>$sVarkey){
if ($aConfig[$sVarkey]) {
$aBodyvars[$sParam]=$aConfig[$sVarkey];
}
}
$sAuth=($aConfig['user'] ? '--user '.$aConfig['user'].':'.$aConfig['password'] : '');
$aReturn[]="curl -f -k -H 'Content-Type: application/json' -XPOST -d '".$sJson."' $sAuth ".$aConfig['url']."/job_templates/".$aConfig['jobtemplate']."/launch/";
$aReturn[]="curl -f -k -H 'Content-Type: application/json' -XPOST -d '". json_encode($aBodyvars, JSON_PRETTY_PRINT)."' $sAuth ".$aConfig['url']."/job_templates/".$aConfig['jobtemplate']."/launch/";
return $aReturn;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment