序章
ある日ansibleを走らせると以下の警告が出た。
[DEPRECATION WARNING]: Specifying include variables at the top-level of the task is deprecated.
Please see:
http://docs.ansible.com/ansible/playbooks_roles.html#task-include-files-and-encouraging-reuse
for currently supported syntax regarding included files and variables.
This feature will be removed in version 2.7.
Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
使用していたplaybookはこんな感じ。
# hoge.yml
---
- hosts: all
become: yes
roles:
- role: fuga
# roles/fuga/main.yml
---
- name: install middleware
include: install.yml
vars:
owner: yoko
group: chance
- name: start and enable middleware
include: start.yml
includeのトップレベルで変数指定しちゃだめだよと言っているようだったので、role全てチェックせども該当なし。
調査
検索してみるとissueがヒットした。
amenonsen commented on 8 Jun 2016
That tag: is the underlying problem. You probably meant tags:,
but it doesn't recognise tag: and thinks it's a variable.
JoelFeiner commented on 26 Aug 2017
please consider re-opening. The problem isn't just that the user made a syntax error. The problem is that the error message is both incorrect and not helpful. It says that specifying include variables at the top-level is deprecated, but the actual issue is something else.
おやっ?と思いつつ、調べてみるとincludeが非推奨になっている。
The bare include task (which was used for both Task files and Playbook-level includes) is still available, however it is now considered deprecated.
解決
さてはと思いincludeをimport_tasksに置き換える。
# hoge.yml
---
- hosts: all
become: yes
roles:
- role: fuga
# roles/fuga/main.yml
---
- name: install middleware
import_tasks: install.yml
vars:
owner: yoko
group: chance
- name: start and enable middleware
import_tasks: start.yml
走らせる。
警告は静まった。