运行ansible playbook时出现模糊的弃用错误提示

3

我的playbook包含一些变量,这些变量会传递给一个角色。当我运行它时,我收到了这样的警告信息:[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

...

这个角色的作用如下:

log-rotation/tasks/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: []

...

log-rotation/templates/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 -%}
}

任何帮助都将不胜感激!
1个回答

0

with_items 只能与任务一起使用,不能在定义变量时使用,因此 item 未定义。同时,service 变量似乎也未定义。


谢谢您的快速回复!在我将变量引入之前,playbook是可以正常工作的,这完全有道理。那么定义多个服务以迭代logrotate模板任务的最佳方法是什么? - IAmKiserWilhelm
set_fact内部与with_items一起使用可以实现您想要的功能。 - nitzmahone
@MarcWKoser,你可以使用Matt建议的方法,但我建议你修改你的角色,并只传递你想要创建logrotate配置的服务名称列表,因为据我所见,除了文件路径之外,一切都是相同的,文件路径可以从服务名称构造出来。 - Strahinja Kustudic

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接