PHP code example of yanggs07 / yii2-salt-api

1. Go to this page and download the library: Download yanggs07/yii2-salt-api library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

yanggs07 / yii2-salt-api example snippets



ient = new \yanggs07\saltapi\ApiClient([
    'host' => 'salt-master.server',
    'port' => 8000,
    'cacert' => '/path/to/your/salt-api_self-signed/ca.crt', // or use
    // if you do not have the ca crt file, use this instead
    // 'skipCertCheck' => true 
    'username' => 'saltapi',
    'password' => 'saltapi',
]);

$session = $client->pamLogin();
$ret = $client->localAsyncRun($session, "*", 'cmd.run', 'w');
$jid = $ret['jid'];
for ($i = 0;$i < 30; $i++) {
    $ret = $client->job($session, $jid);
    var_dump($ret);
    sleep(1);
}