Memo

メモ > サーバ > 各論: Deployer > 外部サーバへの接続

■外部サーバへの接続
※対象サーバにSSH接続できることが前提 ■パスワードでの接続 デプロイツール「Deployer」をつかってみた。PHPerなら簡単に使えます https://gootablog.com/use-deployer
$ cd $ mkdir deploy_target $ cd deploy_target $ vi file.yml … 接続先を定義
target: hostname: 192.168.33.11 user: vagrant pass: vagrant deploy_path: /home/vagrant
$ vi deploy.php … 処理内容を作成
<?php namespace Deployer; inventory('file.yml'); task('test', function () { run('cd ' . get('deploy_path')); writeln('hostname: ' . run('hostname')); writeln('id: ' . run('id')); writeln('pwd: ' . run('pwd')); writeln("ls:\n" . run('ls')); });
$ dep test target … Deployerを実行(接続先での実行結果が表示される) Executing task test hostname: target.localhost id: uid=1000(vagrant) gid=1000(vagrant) groups=1000(vagrant) pwd: /home/vagrant ls: test1.txt test2.txt Ok
■鍵での接続 鍵を設定済みなら、以下の設定だけで接続できる
$ vi file.yml … 接続先を定義
target: hostname: 192.168.33.11 user: vagrant deploy_path: /home/vagrant
■デバッグメッセージを表示して実行 「-vvv」を追加すれば、デバッグメッセージ付きで実行される ただしこの機能はVer6以降かも
$ dep test target -vvv Executing task test [target] > cd /home/vagrant [target] > hostname [target] < target.localhost hostname: target.localhost [target] > id [target] < uid=1000(vagrant) gid=1000(vagrant) groups=1000(vagrant) id: uid=1000(vagrant) gid=1000(vagrant) groups=1000(vagrant) [target] > pwd [target] < /home/vagrant pwd: /home/vagrant [target] > ls [target] < test1.txt [target] < test2.txt ls: test1.txt test2.txt done on [target] Ok [164ms]

Advertisement