PHP code example of laijim / playbook

1. Go to this page and download the library: Download laijim/playbook 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/ */

    

laijim / playbook example snippets


composer 

//Instantiate
$pb = new \Laijim\Playbook\Playbook(
    new \Laijim\Playbook\Entity\Worker(
        __DIR__ . '/test',
        new \Laijim\Playbook\Entity\LocalHostsFileWriter(),
        new \Laijim\Playbook\Entity\LocalTasksFileWriter(),
        new \Laijim\Playbook\Entity\LocalVariablesFileWriter(),
        new Filesystem()
    )
);

//set host and variables
$pb->setHosts([
    'web' => ['node1', '127.0.0.1'],
    'db' => ['node1', '127.0.0.1'],
])->setVariables([
    'step1' => [
        "var1" => "var1",
        "var2" => "var2"
    ],
    'step2' => [
        "var1" => "var1",
        "var2" => "var2"
    ]
]);

//set tasks
$task1 = new \Laijim\Playbook\Task();
$task1->useHost('web')
    ->useVariables(['step1'])
    ->addTasks([
        ["name" => "debug 1", "debug" => "var=var1"],
        ["name" => "debug 2", "debug" => "var=var2"],
        ["name" => "step 3", "shell" => "echo handlers", "notify" => "step 4"],
    ])->directive('handlers', [
        ["name" => "step 4", "shell" => "echo final"],
    ]);

$task2 = new \Laijim\Playbook\Task();
$task2->useHost('db')
    ->useVariables(['step2'])
    ->addTasks([
        ["name" => "debug 1", "debug" => "var=var1"],
        ["name" => "debug 2", "debug" => "var=var2"],
        ["name" => "step 3", "shell" => "echo handlers", "notify" => "step 4"],
    ])->directive('handlers', [
        ["name" => "step 4", "shell" => "echo final"],
    ]);

//generate playbook files
$pb->register($task1)
->register($task2)
->generate();