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
No related branches found
No related tags found
1 merge request!12AWX - handling leerer AWX felder
...@@ -17,7 +17,15 @@ class rollout_awx extends rollout_base { ...@@ -17,7 +17,15 @@ class rollout_awx extends rollout_base {
// no specific checks needed ... always true // no specific checks needed ... always true
return 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 * make an http get request and return the response body
* it is called by _makeRequest * it is called by _makeRequest
...@@ -71,8 +79,6 @@ class rollout_awx extends rollout_base { ...@@ -71,8 +79,6 @@ class rollout_awx extends rollout_base {
return $aReturn; return $aReturn;
} }
/** /**
* get AWX inventories and return them as array for select box * get AWX inventories and return them as array for select box
* [id] => array('value' => [ID], 'label' => [NAME] [ID]) * [id] => array('value' => [ID], 'label' => [NAME] [ID])
...@@ -129,13 +135,6 @@ class rollout_awx extends rollout_base { ...@@ -129,13 +135,6 @@ class rollout_awx extends rollout_base {
return $aReturn; 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 * get array with commands to execute to deploy a package
...@@ -146,17 +145,30 @@ class rollout_awx extends rollout_base { ...@@ -146,17 +145,30 @@ class rollout_awx extends rollout_base {
public function getDeployCommands($sPhase){ public function getDeployCommands($sPhase){
$aReturn=array(); $aReturn=array();
$aConfig=$this->getConfig($sPhase); $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']){ if(!(int)$aConfig['inventory']){
$aReturn[]='echo "ERROR: no inventory was given."; exit 1'; $aReturn[]='echo "ERROR: no inventory was given."; exit 1';
} }
$sJson='{
"inventory": "'.$aConfig['inventory'].'", $aBodyvars=array();
"limit": "'.$aConfig['limit'].'", foreach(['inventory'=>'inventory', 'limit'=>'limit', 'job_tags'=>'tags', 'extra_vars'=>'extravars'] as $sParam=>$sVarkey){
"job_tags": "'.$aConfig['tags'].'", if ($aConfig[$sVarkey]) {
"extra_vars": '.$aConfig['extravars'].' $aBodyvars[$sParam]=$aConfig[$sVarkey];
}'; }
}
$sAuth=($aConfig['user'] ? '--user '.$aConfig['user'].':'.$aConfig['password'] : ''); $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; return $aReturn;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment