【问题标题】:Vague deprecation error when running ansible playbook运行 ansible playbook 时出现模糊的弃用错误
【发布时间】:2016-08-31 04:44:23
【问题描述】:

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

任何帮助将不胜感激!

【问题讨论】:

    标签: ansible configuration-management logrotate


    【解决方案1】:

    with_items 只能用于任务,不能在定义变量时使用,因此没有定义item。看起来service 变量也没有定义。

    【讨论】:

    • 感谢您的快速回复!这完全有道理,因为在我将变量加入混合之前,剧本就起作用了。定义多个服务以迭代 logrotate 模板任务的最佳方式是什么?
    • set_fact 里面 with_items 应该做你想做的事
    • @MarcWKoser 您可以使用 Matt 建议的内容,但我建议您修改您的角色并仅传递您想要为其创建 logrotate 配置的服务的名称列表,因为据我所知可以看到,除了文件的路径,一切都一样,可以从服务的名称来构造。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-10
    • 1970-01-01
    • 2021-06-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多