LoginSignup
5
6

More than 5 years have passed since last update.

sue445製itamaeプラグインいろいろ

Posted at

20日目なので僕が今まで作った itamae プラグインをまとめて紹介します 1

sushi_counter.png

itamae-plugin-resource-encrypted_remote_file

itamaeで暗号化されたファイルを復号化して転送するためのプラグインです

使い方

ファイルを暗号化

別途 reversible_cryptography をインストールして暗号化してください

gem install reversible_cryptography

reversible_cryptography encrypt --password=PASSWORD --src-file=/path/to/secret_file.txt --dst-file=/pass/to/encrypted_file.txt

レシピ

remote_file の代わりに encrypted_remote_file を使うことで、暗号化されたファイルを転送時に復号化します

recipe.rb
encrypted_remote_file "/home/deployer/.ssh/id_rsa" do
  owner    "root"
  group    "root"
  source   "files/id_rsa.encrypted"
  password ENV["ID_RSA_PASSWORD"]
end

password 以外は remote_file と使い方は全く同じです。

応用編:dotenvと組み合わせて使う

パスワードをソースコード中に書くのも嫌なので、自分は dotenv を使って .env にパスワードを書くようにしています。(.envはコミットしない)

.env
ID_RSA_PASSWORD=12345678
.gitignore
.env
recipe.rb
require 'dotenv'
Dotenv.load

ENV["ID_RSA_PASSWORD"]
#=> "12345678"

encrypted_remote_file "/home/deployer/.ssh/id_rsa" do
  owner    "root"
  group    "root"
  source   "files/id_rsa.encrypted"
  password ENV["ID_RSA_PASSWORD"]
end

itamae-plugin-recipe-consul

itamaeでconsulをインストールするためのプラグイン

consul自体はバイナリを置くだけなのですが、daemon化する必要があったのでOSによってinitスクリプトやsystemd unitをいい感じに配置するためにプラグイン化しました。

起動スクリプトはこちらのを参考にさせてもらいました :bow:

consulのinitスクリプトとsystemdユニットファイルを書いてみた - Qiita

使い方

recipe.rb
include_recipe "consul"

内部でモジュール化しているので個別に読みたい場合は下記参照

recipe.rb
include_recipe "consul::setup"
include_recipe "consul::install"
include_recipe "consul::service"

node

node.yml
consul:
  # install consul version (required)
  version: "0.6.4"

  # download zip platform (default: "linux_amd64")
  platform: "linux_amd64"

  # path to downloaded zip file (default: "/usr/local/src")
  src_dir: "/usr/local/src"

  # path to consul executable file (default: "/usr/local/src")
  bin_dir: "/usr/local/bin"

  # consul agent -data-dir option (default: "/tmp/consul")
  data_dir: "/tmp/consul"

  # consul agent other options (default: none)
  options: "-server -bootstrap-expect 1"

  gomaxprocs: 2

  # consul service actions when after install (default: enable, start)
  service_actions:
    - enable
    - start
    # - disable
    # - stop

本番導入事例

こいつは弊社のitamaeレシピに組み込んで、実際に本番環境に投入されています :triumph:

詳しくは下記をご覧ください。

itamae-plugin-recipe-tmux

itamaeでtmuxをインストールするためのプラグイン

autohomeにtmuxをインストールしたい需要がたまにあって、その度にやり方をググるのに疲れたのでitamaeプラグインにしました。

使い方

recipe.rb
include_recipe "tmux"

Node

node.yml
tmux:
  # tmux prefix (default: /home/<username>/local)
  prefix: /usr/local

  # install version (default: 2.1)
  version: 2.1

libevent:
  # install version (default: 2.0.22)
  version: 2.0.22

ncurses:
  # install version (default: 6.0)
  version: 6.0    

itamae-plugin-recipe-tig

itamaeでtigをインストールするためのプラグイン

aptやyumに上がっているのが古すぎるので自分でビルドしてインストールするために作りました。

使い方

recipe.rb
include_recipe "tmux"

Node

node.yml
tmux:
  # tmux prefix (default: /home/<username>/local)
  prefix: /usr/local

  # install version (default: 2.1)
  version: 2.1

libevent:
  # install version (default: 2.0.22)
  version: 2.0.22

ncurses:
  # install version (default: 6.0)
  version: 6.0

itamae-plugin-recipe-git_now

itamaeで git-now をインストールするためのプラグインです。

開発環境で息をするように git nowしているので作りました。

使い方

recipe.rb
include_recipe "git_now"

Node

node.yml
git_now:
  # tig prefix (default: /usr/local)
  prefix: /usr/local

  # source dir (default: #{node[:git_now][:prefix]}/src)
  src: /usr/local/src

  # specify scheme to use in git clone (default: git)
  scheme: git

  # install revision (default: HEAD)
  revision: v0.1.1.0

itamae-plugin-recipe-omori_gohan

個別にプラグイン作るまでもない雑なプラグインです。

使い方

recipe.rb
include_recipe "omori_gohan"

おおもりご飯 のレシピを include する」という語感が面白いのでこういう名前にしました

共通していること

全部CIしている

Vagrant + Wercker + DigitalOcean という、itamaeServerspec と同等のCIを無駄に行ってます。(最低でもCentOSとDebianでテストでCI)

詳細


  1. 板前の絵は http://www.irasutoya.com/2013/08/blog-post_3071.html よりお借りしています :bow: 

5
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
6