More Related Content Similar to Ansible 2.8 アップデート情報 -機能追加と注意点- (20) Ansible 2.8 アップデート情報 -機能追加と注意点-2. はじめに
l 2019/05/16 に Ansible 2.8.0 がリリースされました。
l 様々な仕様変更や機能追加の中から、気になった
な点をご紹介します。
2
便利
地味に
便利
ちょっと
注意
4. ⾃⼰紹介
4
名前 横地 晃
所属 株式会社エーピーコミュニケーションズ
業務 ネットワーク⾃動化関連の技術開発
@akira6592
Software Design
2018年12⽉号 Ansible 特集
https://tekunabe.hatenablog.jp
https://www.slideshare.net/akira6592/
ブログ(てくなべ)
過去発表資料
https://gihyo.jp/magazine/SD/archive/2018/201812
JANOG44 Meeting in Kobe Day3 (2019/7/26)
ここからはじめよう、運⽤⾃動化
8. 8
Python Interpreter Discovery 機能
l リモートホスト上で利⽤する Python の
インタープリターを探す機能
◦ /usr/bin/python がない場合に本機能で⾒つけ出す
◦ Ansible 2.8 時点のデフォルトの挙動、将来は変更される予定
◦ 例えば RHEL8 のように /usr/bin/python がない環境
でも、ansible_python_interpreter を指定せずに、
/usr/libexec/platform-python を⾒つけ出せる
https://rheb.hatenablog.com/entry/ansible_interpreter_discovery
https://docs.ansible.com/ansible/2.8/reference_appendices/interpreter_discovery.html
便利
9. 9
PLAY RECAP に skipped、rescued、ignored 追加
https://docs.ansible.com/ansible/2.8/porting_guides/porting_guide_2.8.html#plugins
地味に
便利
※rescue された fail は failed にカウントされなくなった
追加
10. 10
retry file の⽣成がデフォルトで無効に
l Playbook 実⾏エラー時に、エラーホスト名
が記載される retry ファイルの⽣成が
デフォルトで無効になった
$ ansible-config dump | grep RETRY_FILES_ENABLED
RETRY_FILES_ENABLED(default) = False
https://docs.ansible.com/ansible/2.8/porting_guides/porting_guide_2.8.html#retry-file-creation-default
地味に
便利
$ ls –l
(…略…) playbook.yml
(…略…) playbook.retry
デフォルトでこれが
⽣成されなくなった
12. 12
l now()
◦ 第⼀引数: UTC 指定かどうか(True/False)。 デフォ
ルトは False。
◦ 第⼆引数: フォーマット
◦ 書式 https://docs.python.org/3/library/datetime.html#strftime-strptime-behavior
https://docs.ansible.com/ansible/2.8/user_guide/playbooks_templating.html#get-the-current-time
jinja2 で現在時刻を now() で取得可能に
- name: display date time
debug:
msg: "{{ now() }}" # 2019-04-29 21:03:16.958620
- name: display date time
debug:
msg: "{{ now(False, '%Y%m%d_%H%M%S') }}" # 20190429_210316
【例】
地味に
便利
14. 14
l ⼊れ⼦になった未定義のキー、インデックス
に default フィルターを利⽤可能に
https://docs.ansible.com/ansible/2.8/porting_guides/porting_guide_2.8.html#jinja-undefined-values
未定義変数へのアクセス柔軟性が向上
"{{ foo.bar.baz | default('DEFAULT') }}"
【例】foo ⾃体が未定義の場合でもこのように書ける
* 2.7 では エラー「The error was: ‘foo’ is undefined」になってしまう
{{ foo.bar.baz if (foo is defined and foo.bar is defined and foo.bar.baz is defined) else 'DEFAULT' }}
{{ ((foo | default({})).bar | default({})).baz | default('DEFAULT') }}
【参考】2.7 での実現⽅法
または
地味に
便利
16. 16
https://github.com/ansible/ansible/pull/49737
register 変数名等でテンプレートが使⽤不可に
TASK [ios_command] ******************************************
[WARNING]: "register" is not templatable, but we found:
result_{{ command }}, it will not betemplated and will be used
"as is".
(…略…)
ok: [iosal1]
TASK [debug] ************************************************
fatal: [iosal1]: FAILED! => {"msg": "The task includes an
option with an undefined variable. The error was:
'result_version' is undefined¥n¥nThe error appears to be in
(…略…)
テンプレート構⽂使⽤不可のWARNING
変数未定義エラー
前述のPlaybook実⾏時
ちょっと
注意
(続き)
20. 20
Windows ホストへの SSH 接続サポート
https://speakerdeck.com/hiyokotaisa/rhtn-ansible-2-dot-8-x-windows
https://docs.ansible.com/ansible/2.8/user_guide/windows_faq.html#can-i-connect-to-windows-hosts-over-ssh
https://docs.ansible.com/ansible/2.8/user_guide/windows_setup.html#windows-ssh-setup
便利
l WinRM に加えて SSH 接続をサポート(experimental)
追加サポート
Windows
ansible_connection: ssh
ansible_connection: winrm
25. 25
https://docs.ansible.com/ansible/2.8/plugins/inventory/netbox.html
NetBox をインベントリとして利⽤可能に
$ ansible-inventory -i i_nb.yml --host cat3750-1
{
"ansible_host": "172.16.0.101",
"device_roles": [
"switch"
],
(…略…)
}
$ ansible-inventory -i i_nb.yml --graph
@all:
|--@device_roles_firewall:
| |--vsrx1
| |--vsrx2
| |--vsrx3
|--@device_roles_switch:
| |--cat3750-1
| |--cat3750-2
|--@manufacturers_cisco:
| |--cat3750-1
| |--cat3750-2
|--@manufacturers_juniper:
| |--vsrx1
| |--vsrx2
| |--vsrx3
|--@sites_my_site:
| |--cat3750-1
| |--cat3750-2
| |--vsrx1
| |--vsrx2
| |--vsrx3
|--@ungrouped:
インベントリ
としての NetBox
グループ化も可能
便利
(続き)
27. 27
https://docs.ansible.com/ansible/devel/modules/read_csv_module.html
https://tekunabe.hatenablog.jp/entry/2019/03/29/ansible_read_csv_intro
read_csv モジュール
l CSVファイルをリストやディクショナリとして
読み込む
- hosts: testsv
gather_facts: no
tasks:
- name: Read users
read_csv:
path: users.csv
register: users
delegate_to: localhost
# ^ 省略するとリモートのファイルを参照
- name: debug csv
debug:
msg: "{{ users }}"
"msg": {
(…略…)
"list": [
{
"gid": "500",
"name": "dag",
"uid": "500"
},
{
"gid": "500",
"name": "jeroen",
"uid": "501"
}
]
}
name,uid,gid
dag,500,500
jeroen,501,500
読み込んだ
Playbook 実⾏
地味に
便利
CSV
28. 28
サンプル引⽤元 https://docs.ansible.com/ansible/2.8/modules/ios_bgp_module.html#examples
*_bgp モジュール
- name: configure global bgp as 64496
ios_bgp:
config:
bgp_as: 64496
router_id: 192.0.2.1
log_neighbor_changes: True
neighbors:
- neighbor: 203.0.113.5
remote_as: 64511
timers:
keepalive: 300
holdtime: 360
min_neighbor_holdtime: 360
- neighbor: 198.51.100.2
remote_as: 64498
networks:
- prefix: 198.51.100.0
route_map: RMAP_1
- prefix: 192.0.2.0
masklen: 23
address_family:
- afi: ipv4
safi: unicast
redistribute:
- protocol: ospf
id: 223
metric: 10
operation: merge
広報設定
ネイバー設定
再配布設定
* 今まではコマンドを直接指定する
ios_config で設定
便利
ios_bgp の例
31. まとめ
31
l Ansible 2.8 では多数のモジュール追加や、
仕様変更、便利な機能追加のほかに、
ちょっとした注意点もありました。
l アップデートの際の参考になれば幸いです。
便利
地味に
便利
ちょっと
注意
• Python Interpreter Discovery
• NetBox をインベントリとして利⽤可能に
• retry file の⽣成がデフォルトで無効に
• read_csv モジュール
• register 変数名等でテンプレートが使⽤不可に
• グループ名に利⽤できる⽂字の厳格化
例: