LoginSignup
29
28

More than 5 years have passed since last update.

ansible v2.0にアップデートする前に

Last updated at Posted at 2015-12-07

まもなくリリースされるAnsible v2.0(rc1)を一足早く触ってみて地雷を踏んでみた。

v2.0の主な変更点

  • Coreのリファクタリング
  • 新しい構文の追加(block/rescue/always)
  • Syntax Errorがより詳細に
  • Strategy Plugins
  • モジュールの追加

インストール

$ pip install paramiko PyYAML Jinja2 httplib2 six
$ git clone -b stable-2.0 git://github.com/ansible/ansible.git --recursive
$ cd ansible/
$ source ./hacking/env-setup
$ ansible --version
ansible 2.0.0 (stable-2.0 f241c70740) last updated 2015/12/08 02:59:55 (GMT +900)
...

既存のplaybookをv2.0で実行する上での注意

基本的にv1.9までのplaybookをそのまま実行できるよう、互換は保たれているが、一部注意する必要がある。

Templateで空のvarは"None"ではなく空の文字列になる

# template
var a is {{ a }}!!
# playbook
vars:
  a:
tasks:
  name check empty value in template
  template: src=path/to/template.j2 dest=/path/to/template.out
# v1.9.4 in template
var a is None!!  # "None"が展開される

# v2.0.0 in template
var a is !!  # 空の文字列""が展開される

varが暗示的に文字列へ変換しない

# playbook

vars:
  b: 123
  c: true
tasks:
  - name: check integer value
    debug:
      var: "{{ b }}"
  - name: check boolean value
    debug:
      var: "{{ c }}"
# v1.9.4 output
TASK: [check integer value] ***************************************************
ok: [xxx.xxx.xxx.xxx] => {
    "var": "123"
}

TASK: [check boolean value] ***************************************************
ok: [xxx.xxx.xxx.xxx] => {
    "var": "True"
}

# v2.0.0 output
TASK [check integer value] *****************************************************
ok: [xxx.xxx.xxx.xxx] => {
   "var": 123
}

TASK [check boolean value] *****************************************************
ok: [xxx.xxx.xxx.xxx] => {
    "var": true
}

改行コードが残る

# Syntax in 1.9.2
vars:
  message: >
    Testing
    some things
tasks:
- debug:
    msg: "{{ message }}"

# Syntax in 2.0.x
vars:
  old_message: >
    Testing
    some things
  message: "{{ old_messsage[:-1] }}"
- debug:
    msg: "{{ message }}"
# Output
"msg": "Testing some things"

引用:https://github.com/ansible/ansible/blob/stable-2.0/CHANGELOG.md

エスケープの挙動が違う

# Syntax in 1.9.x
- debug:
   msg: "{{ 'test1_junk 1\\\\3' | regex_replace('(.*)_junk (.*)', '\\\\1 \\\\2') }}"
# Syntax in 2.0.x
- debug:
    msg: "{{ 'test1_junk 1\\3' | regex_replace('(.*)_junk (.*)', '\\1 \\2') }}"
# Output:
"msg": "test1 1\\3"

引用:https://github.com/ansible/ansible/blob/stable-2.0/CHANGELOG.md

参考資料

29
28
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
29
28