provision files

This commit is contained in:
CHIEFSOFT\ameye
2025-01-25 11:10:05 -05:00
parent bbb78a514e
commit 5cd374af24
3 changed files with 84 additions and 2 deletions
+68
View File
@@ -0,0 +1,68 @@
# 1. Login
curl -c /tmp/semaphore-cookie -XPOST \
-H 'Content-Type: application/json' -H 'Accept: application/json' \
-d '{"auth": "admin", "password": "may12002"}' \
"http://172.16.4.90:3000/api/auth/login"
# 2. Get token
curl -b /tmp/semaphore-cookie \
-H 'Content-Type: application/json' -H 'Accept: application/json' \
"http://172.16.4.90:3000/api/user/tokens" > tokens.txt
# 2.1. Generate a new token & get it
curl -v -b /tmp/semaphore-cookie -XPOST \
-H 'Content-Type: application/json' -H 'Accept: application/json' \
"http://172.16.4.90:3000/api/user/tokens"
# 2.2. Get a new token
curl -v -b /tmp/semaphore-cookie \
-H 'Content-Type: application/json' -H 'Accept: application/json' \
"http://172.16.4.90:3000/api/user/tokens" > tokens.txt
# get the last one from array:
export TOKEN=`cat tokens.txt | jq .[-1].id | xargs echo`
echo "Obtained token: $TOKEN"
# DEBUG
# curl \
# -H 'Content-Type: application/json' -H 'Accept: application/json' -H "Authorization: Bearer $TOKEN" \
# "http://172.16.4.90:3000/api/projects" -v
#curl -b /tmp/semaphore-cookie "http://172.16.4.90:3000/api/projects"
# 3. Pre-created project (playbooks are stored in git repository and configured through templates 7 variables)
# Sample is here https://gitlab.chiefsoft.net/MERMS/AnsibleTest
export PROJECT_ID=8
# 4. Lauch task
curl -XPOST \
-H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer '$TOKEN \
-d '{"template_id": 1, "debug": false, "dry_run": false, "playbook": "23607_devprov_mermsemr_com.yml", "environment": "{}"}' \
"http://172.16.4.90:3000/api/project/$PROJECT_ID/tasks" > task.txt
export TASK_ID=`cat task.txt | jq .id | xargs echo`
echo "Task queued ID: $TASK_ID"
# 5. Check task status
# need to loop here until it is finished while it is "waiting" and it turns either to "success" or "error"
curl \
-H 'Content-Type: application/json' -H 'Accept: application/json' -H "Authorization: Bearer $TOKEN" \
"http://172.16.4.90:3000/api/project/$PROJECT_ID/tasks/$TASK_ID" > status.txt
export STATUS=`cat status.txt | jq .status | xargs echo`
echo "Task status is: $STATUS"
# 6. Get output
curl \
-H 'Content-Type: application/json' -H 'Accept: application/json' -H "Authorization: Bearer $TOKEN" \
"http://172.16.4.90:3000/api/project/$PROJECT_ID/tasks/$TASK_ID/output"
# 7. Expire token
curl -XDELETE \
-H 'Content-Type: application/json' -H 'Accept: application/json' -H "Authorization: Bearer $TOKEN" \
"http://172.16.4.90:3000/api/user/tokens/$TOKEN"
# 8. Logout
curl -c /tmp/semaphore-cookie -XPOST \
-H 'Content-Type: application/json' -H 'Accept: application/json' \
"http://172.16.4.90:3000/api/auth/logout"
+1
View File
@@ -9,3 +9,4 @@ $routes->get('/', 'Home::index');
$routes->get('/provision/prepare', 'Provision::prepareProvision');
$routes->get('/provision/update', 'Provision::updateProvision');
$routes->get('/provision/release', 'Provision::releaseProvision');
+15 -2
View File
@@ -33,9 +33,9 @@ class Provision extends BaseController
];
foreach ($provArrv as $svv){
$tgt = $ansible_folder = str_replace(".", "_", $svv).".yml";
// $this->runAnsibleShell($tgt);
$this->runAnsibleShell("/var/www/html/ANSIBLE/".$tgt);
}
// $this->runAnsibleShell('94099_devprov_mermsemr_com.yml');
// $this->runAnsibleShell('/var/www/html/ANSIBLE/94099_devprov_mermsemr_com.yml');
return 0;
}
@@ -239,6 +239,19 @@ class Provision extends BaseController
return 0;
}
public function releaseProvision(){
// Use ls command with shell_exec function
$output = shell_exec('ls -alt /var/www/html/ANSIBLE/');
// Display the list of all files and directories
echo "<pre>$output</pre>";
$shellCommand ="/var/www/html/ANSIBLE/auto_play.sh ";
log_message('critical', $shellCommand);
$output = shell_exec($shellCommand );
var_dump($output);
return 0;
}
public function runAnsibleShell($provisionFile){
try{
log_message('critical', "***** ***** Provision :: runAnsibleShell($provisionFile) ");