■ はじめに
StackStorm の環境を準備するには、インストールスクリプトを実行する方法や Ansible の Playbook を実行する方法などがありますが、先日の公式ブログでは vagrant で VMごと StackStorm の環境を準備する方法が紹介されていました。
stackstorm.com
公式ドキュメントの「Vagrant & Virtual Appliance」にも、記載されていましたので、これらの情報をもとに試しに、環境を準備して、ごく簡単な動作確認をします。
環境:
※ Ansible で StackStorm にインストールする場合はこちら
http://tekunabe.hatenablog.jp/entry/2018/03/12
■ StackStorm 入りのVMの準備と起動
以下の2行だけです。
vagrant init stackstorm/st2
vagrant up
vagrant init stackstorm/st2
で最低限の Vagrantfile
が生成され、その情報をもとに vagrant up
でVMを起動するという流れです。
akirapc:st2 akira$ vagrant init stackstorm/st2
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.
akirapc:st2 akira$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'stackstorm/st2' could not be found. Attempting to find and install...
default: Box Provider: virtualbox
default: Box Version: >= 0
==> default: Loading metadata for box 'stackstorm/st2'
default: URL: https://vagrantcloud.com/stackstorm/st2
==> default: Adding box 'stackstorm/st2' (v2.7.2-20180523) for provider: virtualbox
default: Downloading: https://vagrantcloud.com/stackstorm/boxes/st2/versions/2.7.2-20180523/providers/virtualbox.box
==> default: Successfully added box 'stackstorm/st2' (v2.7.2-20180523) for 'virtualbox'!
==> default: Importing base box 'stackstorm/st2'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'stackstorm/st2' is up to date...
==> default: Setting the name of the VM: stackstorm
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
default: Adapter 2: hostonly
==> default: Forwarding ports...
default: 443 (guest) => 9000 (host) (adapter 1)
default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 127.0.0.1:2222
default: SSH username: vagrant
default: SSH auth method: private key
default:
default: Vagrant insecure key detected. Vagrant will automatically replace
default: this with a newly generated keypair for better security.
default:
default: Inserting generated public key within guest...
default: Removing insecure key from the guest if it's present...
default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
[default] GuestAdditions 5.2.12 running --- OK.
==> default: Checking for guest additions in VM...
==> default: Setting hostname...
==> default: Configuring and enabling network interfaces...
==> default: Mounting shared folders...
default: /vagrant => /Users/akira/Documents/git/python_test/vagrant/st2
==> default: Running provisioner: st2-version (shell)...
default: Running: inline script
default: st2 2.7.2, on Python 2.7
==> default: Machine 'default' has a post `vagrant up` message. This is a message
==> default: from the creator of the Vagrantfile, and not from Vagrant itself:
==> default:
==> default: ███████╗████████╗██████╗ ██████╗ ██╗ ██╗
==> default: ██╔════╝╚══██╔══╝╚════██╗ ██╔═══██╗██║ ██╔╝
==> default: ███████╗ ██║ █████╔╝ ██║ ██║█████╔╝
==> default: ╚════██║ ██║ ██╔═══╝ ██║ ██║██╔═██╗
==> default: ███████║ ██║ ███████╗ ╚██████╔╝██║ ██╗
==> default: ╚══════╝ ╚═╝ ╚══════╝ ╚═════╝ ╚═╝ ╚═╝
==> default:
==> default: To access the Web UI, head to:
==> default: https://10.10.10.10/
==> default: Username: st2admin
==> default: Password: Ch@ngeMe
==> default:
==> default: Thanks for trying StackStorm!
そのまま vagrant ssh
コマンドでログインできます。
akirapc:st2 akira$ vagrant ssh
Welcome to StackStorm v2.7.2 (Ubuntu 16.04 LTS GNU/Linux x86_64)
* Documentation: https://docs.stackstorm.com/
* Community: https://stackstorm.com/community-signup
* Forum: https://forum.stackstorm.com/
* Enterprise: https://stackstorm.com/#product
Last login: Wed Jun 6 11:59:12 2018 from 10.0.2.2
vagrant@stackstorm:~$ hostname
stackstorm
vagrant@stackstorm:~$ uname -a
Linux stackstorm 4.4.0-116-generic #140-Ubuntu SMP Mon Feb 12 21:23:04 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
vagrant@stackstorm:~$
ログインできました。Ubutuを利用しているようです。
なお、VirtualBox の VM として SSH へポートフォワーディングは 2222/TCP に設定されますので、ssh コマンドやターミナルソフトでログインする場合は、 2222/TCP を指定します。
ユーザー名、パスワードともに vagrant
です。秘密鍵を利用する場合は .vagrant/machines/default/virtualbox/private_key
を指定します。
akirapc:st2 akira$ ssh vagrant@localhost -p 2222
vagrant@localhost's password:
Welcome to StackStorm v2.7.2 (Ubuntu 16.04 LTS GNU/Linux x86_64)
* Documentation: https://docs.stackstorm.com/
* Community: https://stackstorm.com/community-signup
* Forum: https://forum.stackstorm.com/
* Enterprise: https://stackstorm.com/#product
vagrant@stackstorm:~$ hostname
stackstorm
StackStorm ログイン(認証)
StackStormの各種操作には、StackStormへのログインが必要です。ここでは環境変数にトークンを仕込む方法でログインと同等の状態にします。
ユーザーは st2admin
、パスワードは Ch@ngeMe
です。
vagrant@stackstorm:~$ export ST2_AUTH_TOKEN=`st2 auth -t -p Ch@ngeMe st2admin`
st2 run 動作確認
簡単な動作確認として st2 run
コマンドで date
コマンドを実行します。
vagrant@stackstorm:~$ st2 run core.local -- date -R
.
id: 5b17d02802ebd505e4388361
status: succeeded
parameters:
cmd: date -R
result:
failed: false
return_code: 0
stderr: ''
stdout: Wed, 06 Jun 2018 12:14:33 +0000
succeeded: true
正常に実行できました。
■ GUI(Web)の確認
ログイン
今度は、Web画面の確認をします。
VMの設定で、9000/TCP から 443/TCP へのポートフォワーディングが設定されていますので、ホストOSのブラウザから https://localhost:9000
にアクセスします。
CLI と居と同じく、ユーザーは st2admin
、パスワードは Ch@ngeMe
です。
ログ確認
ログイン後トップ画面の左の方で、先程CLIから実行した st2 run core.local -- date -R
のログが確認できます。
■ ログイン情報まとめ
初期のログイン情報は以下のとおりです。
■ まとめ
Vagrant と VirtualBox で艱難に OSごと StackStorm の環境を準備できることが確認できました。
特に OS/ディストリビューションにこだわりがなく、とにかく手軽にローカルに StackStorm の独立した環境を準備するには、この Vagnrant の方法が良いのではないかと思います。