LoginSignup
17
17

More than 5 years have passed since last update.

ansible_spec 機能追加

Posted at

下の記事で紹介したansible_specをバージョンアップしました。
Ansibleの設定ファイルを使ってServerspecを実行するテンプレート作成用Gem(ansible_spec)を作りました。

機能的な変更点

  • Serverspec v2の対応
  • InventoryParametersの対応(※)
    • ansible_ssh_port
    • ansible_ssh_user
    • ansible_ssh_host
    • ansible_ssh_private_key_file
  • hostlist expressionsの対応
  • Dynamic Inventoryの対応

※ 注意
ansibleではansible_ssh_passansible_sudo_pass非推奨となっているので、非対応です。
SSH鍵で認証を行ってください。Redhat系はssh-copy-idコマンドがあるので、それほど手間ではないと思います。

内部的な変更点

Rakefileの短縮

従来はコピペして使えるように、処理を全てRakefileにしていました。
しかしながら、機能の追加で内部処理のテストケースが増えたので、モジュール化とrspecのテスト追加を行いました。
結果として、Rakefileが短縮されています。

移行方法

# update
gem update ansible_spec
# delete old file
rm Rakefile
rm -rf spec
# run init
ansiblespec-init

インベントリファイルのサンプル

v0.1でインベントリファイルの書式対応が増えました。

[server]
# skip line(comment)
# normal
192.168.0.1
# use port 5309
192.168.0.3:5309
# use port 22
192.168.0.2 ansible_ssh_port=22
# use Private-key ~/.ssh/id_rsa
192.168.0.4 ansible_ssh_private_key_file=~/.ssh/id_rsa
# use user `git`
192.168.0.5 ansible_ssh_user=git
# use port 5555 & host 192.168.1.50
jumper ansible_ssh_port=5555 ansible_ssh_host=192.168.1.50

[web]
# www1.example.com to www99.example.com
www[1:99].example.com
# www01.example.com to www99.example.com
www[01:99].example.com

[databases]
# db-a.example.com to db-z.example.com
db-[a:z].example.com
# db-A.example.com to db-Z.example.com
db-[A:Z].example.com

# Multi Group. use server & databases
[parent:children]
server
databases

Dynamic Inventoryを使う場合

実行権限のあるファイルを.ansiblespecに書きます。

--- 
- 
  playbook: site.yml
  inventory: load_host.sh   # 実行権限を付けておく。

以上

17
17
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
17
17