>100 Views
August 24, 26
スライド概要
2026年5月に ansible-core 2.21.0 がリリースされました。
このリリースでは、レジスタ変数を柔軟に定義できる Register projections という機能追加などが行われました。
便利な点や注意点を中心にご紹介します。
動画 は https://www.youtube.com/@apcommunications9928 にて公開予定
APC勉強会「8a1」の資料です。
https://8a1-apc.connpass.com/event/400759/
ansible
#apc8a1 ansible-core 2.21 のアップデート情報 2026/08/24 「8a1」APC勉強会 #44 株式会社エーピーコミュニケーションズ 横地 晃 1
#apc8a1 はじめに ◼ 2026年5月に ansible-core 2.21.0 がリリース ◼ 目玉は Register projections ◼ 本資料では、個人的に便利そうだと思った点や注意点をご紹介します 2
#apc8a1 自己紹介 横地 晃 @akira6592 所属 (株)エーピーコミュニケーションズ 業務 ネットワーク自動化のご支援 コミュニティ Ansible ユーザー会、JANOG 共著書 Ansible実践ガイド 第4版[基礎編]、Ansibleクックブック てくなべ(ブログ) https://tekunabe.hatenablog.jp/ 3
#apc8a1 事前アンケート結果 4
#apc8a1 「ご利用の ansible-core の主なバージョンはいくつですか?」 事前アンケートで ansible-core 2.18 以下をお使いの方もいらっしゃいました ◼ 2.19 では大きな変更があったので、2.19 と 2.20 にも少し触れます ◼ ご協力ありがとうございました! * 2026/08/24 18:30 現在 5
#apc8a1 ansible-core 2.21 の概要 6
#apc8a1 ansible-core 2.21 の概要 ◼ 2026年5月にリリースされた Ansible のコア部分 ◼ ◼ Register 変数を柔軟に定義できるようになった(Register projections) ◼ ◼ ansible-core 2.21 は、Ansible 14 (*1)に含まれる Playbook がちょっとスッキリ書けるようになる 大きな混乱をきたすような破壊的な変更はない(*2) *1: ansible-core とコミュニティによって選定されたコレクション群のセットである Ansible Community Package のこと。 「pip install ansible」でインストールされるのはこのパッケージ *2: ansible-core 2.19 の影響度との比較 7
#apc8a1 便利な点 8
#apc8a1 レジスタ変数を柔軟に定義できる Register projections (1/2) これまで 1つのタスクに対して 1つの Register 変数しか定義できなかった ◼ Register projections という機能により、1つのタスクに複数の Register 変数 を定義できるようなった ◼ さらに変数に格納する際に Jinja2 書式も指定できるようになった ◼ - name: Execute show commands cisco.ios.ios_command: 複数の Register 変数の指定でき、 commands: Jinja2 書式の指定が可能に - show version - show ip route register: result_show_version: _task.result.stdout_lines[0] result_show_ip_route: _task.result.stdout_lines[1] 9
#apc8a1 レジスタ変数を柔軟に定義できる Register projections (2/2) ◼ set_fact などで整えるワンクッションが不要になってスッキリする 2.20 までの書き方 - name: Execute show commands cisco.ios.ios_command: commands: - show version - show ip route register: result_show_commands 2.21 から可能な書き方 まず1つの変数に格納 set_fact で複数の変数にバラす - name: set_fact ansible.builtin.set_fact: result_show_version: "{{ result_show_commands.stdout_lines[0] }}" result_show_ip_route: "{{ result_show_commands.stdout_lines[1] }}" - name: Debug result_show_version ansible.builtin.debug: msg: "{{ result_show_version }}" - name: Debug result_show_ip_route ansible.builtin.debug: msg: "{{ result_show_ip_route }}" - name: Execute show commands cisco.ios.ios_command: commands: いきなり複数の変数にバラす - show version - show ip route register: result_show_version: _task.result.stdout_lines[0] result_show_ip_route: _task.result.stdout_lines[1] 複数の Register 変数の指定 &Jinja2 書式の指定が可能に - name: Debug result_show_version ansible.builtin.debug: msg: "{{ result_show_version }}" - name: Debug result_show_ip_route ansible.builtin.debug: msg: "{{ result_show_ip_route }}" * ansible-core 2.21 でも 2.20 までの書き方は可能 10
#apc8a1 暗黙的なタスクオブジェクト _task による register の省略 register を指定しなくても、そのタスク内であれば「_task」を通じて タスクの実行結果を参照できるようになった ◼ 後続のタスクで利用しないのであれば、わざわざ変数名を付けなくてよい ◼ 2.20 までの書き方 - name: Test command ansible.builtin.command: cmd: diff test1.txt test2.txt register: my_result failed_when: my_result.rc >= 2 2.21 から可能な書き方 - name: Test command ansible.builtin.command: cmd: diff test1.txt test2.txt failed_when: _task.result.rc >= 2 明示的な Register 変数を定義せずに タスクの実行結果を参照可能 * ansible-core 2.21 でも 2.20 までの書き方は可能 * loop と併用する場合、ループごとの結果は「 _task.result」 ではなく「_task.loop_results」に入る 11
#apc8a1
include_* 系の読み込みログの出力有無を切り替え可能に
ansible.builtin.include_tasks などの include_* 系のモジュールによる動的読み込み
の際、Playbook 実行ログに included ~ というログが表示される
◼ この表示を設定で無効化できるようになった
◼
◼
ansible.builtin.default コールバックプラグインの設定 display_included_hosts を false に
% ansible-playbook -i localhost, include.yml
PLAY [Test Play] *********************************************************************************
TASK [Test include_tasks] ************************************************************************
included: /Users/sakana/ansible/ac221/tasks1.yml for localhost => (item=tasks1.yml)
included: /Users/sakana/ansible/ac221/tasks2.yml for localhost => (item=tasks2.yml)
included: /Users/sakana/ansible/ac221/tasks3.yml for localhost => (item=tasks3.yml)
このログを非表示に
できるようなった
(デフォルトは従来どおり表示)
TASK [Test debug] ********************************************************************************
ok: [localhost] => {
"msg": "in tasks1.yml"
}
...(略)...
* 弊社社員による機能追加
12
#apc8a1 注意点 13
#apc8a1 コレクションインストール時の互換性チェックの導入 各コレクション側で、サポートする ansible-core のバージョンを指定できる ◼ ansible-galaxy collection コマンドでコレクションをインストールする時、サポートする バージョンをチェックするようになった ◼ ◼ サポートされていないバージョンの場合はインストールできない コレクション側が要求する ansible-core の サポートバージョンを満たしていないのでエラー $ ansible-galaxy collection install コレクション名 Process install dependency map [ERROR]: Failed to resolve the requested dependencies map. Could not satisfy the following requirements: * コレクション名 :6.0.2 (dependency of git collection from a Git repo) requires ansible-core >=2.22.0 (略) $ echo $? 1 * COLLECTIONS_ON_ANSIBLE_VERSION_MISMATCH という設定を ignore に変更すれば、サポート条件を無視できる 14
#apc8a1 おまけ 15
#apc8a1 ansible-core 2.19 と 2.20 ◼ ansible-core 2.19 ◼ ◼ ◼ ◼ 2025年7月リリース。Ansible 12 に含まれる テンプレート処理に大きな変更が加わり、パフォーマンス改善が見込める一方で既存の Playbook がエラーになることも 日本語参考資料 https://www.docswell.com/s/akira6592/K7RXP6-ansible-core2.19-updates ansible-core 2.20 ◼ ◼ ◼ 2025年11月リリース。Ansible 13 に含まれる 2.19 ほどの大きなインパクトはないが、サポート Python のバージョンは引き上げられた 日本語参考記事 https://tekunabe.hatenablog.jp/entry/2025/11/10/ansible-core2.20.0 16
#apc8a1 ansible-core がサポートする Python バージョンの遷移 ansible-core 2.20 で引き上げ * https://docs.ansible.com/projects/ansible/latest/reference_appendices/release_and_maintenance.html#ansible-core-support-matrix から引用(赤線、青線は追加) 17
#apc8a1 Register projections に伴うドキュメントの追記 ◼ 公式ドキュメントの Register 変数の説明の箇所も追記されている 新しい書き方 * 対応PR https://github.com/ansible/ansible-documentation/pull/3752 18
#apc8a1 まとめ 19
#apc8a1 まとめ ◼ ◼ 目玉は Register 変数を柔軟に定義できる Register projections ◼ 1つのタスクに複数の Register 変数を定義可能。Jinja2 書式も指定可能 ◼ 暗黙的なタスクオブジェクト「_task」の導入 大きな破壊的変更はない(ansible-core 2.19 の影響度との比較) この書き方にびっくりしない ようにしていきましょう! - name: Execute show commands cisco.ios.ios_command: commands: - show version - show ip route register: result_show_version: _task.result.stdout_lines[0] result_show_ip_route: _task.result.stdout_lines[1] 20
#apc8a1 参考資料 ◼ ansible-core 2.21 系 CHANGELOG ◼ ◼ ansible-core 2.21 Porting Guide (移行ガイド) ◼ ◼ ◼ https://github.com/ansible/ansible/blob/stable-2.21/changelogs/CHANGELOG-v2.21.rst https://docs.ansible.com/projects/ansible-core/devel/porting_guides/porting_guide_core_2.21.html Red Hat 社サポート状況 ◼ https://access.redhat.com/support/policy/updates/ansible-automation-platform ◼ https://access.redhat.com/articles/7137844 個人ブログ ◼ ansible-core 2.21.0 リリース全体情報 ◼ https://tekunabe.hatenablog.jp/entry/2026/05/22/ansible-core2.21.0 ◼ Register projections ◼ https://tekunabe.hatenablog.jp/entry/2026/05/22/ansible_register_projection 21