Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
运行ansible playbook时出现模糊的弃用错误_Ansible_Configuration Management_Logrotate - Fatal编程技术网

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

运行ansible playbook时出现模糊的弃用错误,ansible,configuration-management,logrotate,Ansible,Configuration Management,Logrotate,我的剧本包含传递给角色的变量。当我运行它时,我得到[弃用警告]:由于未定义的错误而跳过任务,将来这将是一个致命错误。 以下是我所拥有的: --- - hosts: hadoopL0X become: yes become_method: sudo vars: logrotate_scripts: - name: "{{ item }}" with_items: - zookeeper - sa

我的剧本包含传递给角色的变量。当我运行它时,我得到
[弃用警告]:由于未定义的错误而跳过任务,将来这将是一个致命错误。

以下是我所拥有的:

---

- 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 }}"

...
---

logrotate_conf_dir: "/etc/logrotate.d/"
logrotate_scripts: []

...
日志循环/默认值/main.yml

---

- name: Setup logrotate.d scripts
  template:
    src: logrotate.d.j2
    dest: "{{ logrotate_conf_dir }}{{ item }}"
  with_items: "{{ logrotate_scripts }}"

...
---

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 -%}
}

任何帮助都将不胜感激

with_items
只能与任务一起使用,在定义变量时不能使用,因为
item
没有定义。看起来
服务
变量也没有定义。

感谢您的快速回复!这完全是有道理的,因为在我将变量放入组合之前,剧本已经运行了。定义多个服务来迭代logrotate模板任务的最佳方法是什么?在内部设置\u事实和\u项应该做什么want@MarcWKoser您可以使用Matt建议的方法,但我建议您修改您的角色,只传递要为其创建logrotate配置的服务的名称列表,因为就我所见,除了文件的路径之外,其他都是一样的,这些路径可以从服务的名称构建。