2016-08-30 19 views
3

我的剧本包含传递给角色的变量。当我运行它,我得到[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 }}" 

... 

log-rotation/defaults/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

with_items只能与任务一起使用,定义变量时不能使用,并且因为item未定义。它也看起来像service变量没有被定义好。

+0

感谢您的快速回复!在我将变量投入混合之前,这些剧本完全合理。定义多个服务以遍历logrotate模板任务的最佳方式是什么? –

+0

set_fact里面的with_items应该做你想做的事 – nitzmahone

+0

@MarcWKoser你可以使用Matt的建议,但是我建议你修改你的角色并且只传递你想创建logrotate配置的服务名字列表,因为到目前为止正如我所看到的,除了可以从服务名称构建的文件路径之外,所有内容都是相同的。 –