我的剧本包含传递给角色的变种。当我运行它时,我得到[DEPRECATION WARNING]: Skipping task due to undefined Error, in the future this will be a fatal error..
这就是我所拥有的:
---
- hosts: hadoopL0X
become: yes
become_method: sudo
vars:
logrotate_scripts:
- name: "{{ item }}"
with_items:
- zookeeper
- sa
path: "/var/log{{ item }}/{{ item }}.log "
options:
- daily
- rotate 3
- missingok
- compress
- notifempty
roles:
- log-rotation
...
角色是这样的:
循环使用日志/任务/ main.yml
---
- name: Setup logrotate.d scripts
template:
src: logrotate.d.j2
dest: "{{ logrotate_conf_dir }}{{ item }}"
with_items: "{{ logrotate_scripts }}"
...
循环使用日志/默认/ main.yml
---
logrotate_conf_dir: "/etc/logrotate.d/"
logrotate_scripts: []
...
登录旋转/模板/ logrotate.d.j2
# {{ ansible_managed }}
"{{ item.path }}" {
{% if item.options is defined -%}
{% for option in item.options -%}
{{ option }}
{% endfor -%}
{% endif %}
{%- if item.scripts is defined -%}
{%- for name, script in item.scripts.iteritems() -%}
{{ name }}
{{ script }}
endscript
{% endfor -%}
{% endif -%}
}
非常感谢任何帮助!
答案 0 :(得分:0)
with_items
只能用于任务,在定义变量时不能使用,因为item
没有定义。它看起来似乎也没有定义service
变量。