diff --git a/public_html/deployment/plugins/rollout/awx/rollout_awx.php b/public_html/deployment/plugins/rollout/awx/rollout_awx.php index 7ec6f2dcbbdccc55fb6aaa1c42afff493c27894c..f6e39e87261a96feaefeb9d4ca35abb49de2aaa7 100644 --- a/public_html/deployment/plugins/rollout/awx/rollout_awx.php +++ b/public_html/deployment/plugins/rollout/awx/rollout_awx.php @@ -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; }