gpt4 book ai didi

ansible - 运行 ansible 剧本时出现模糊弃用错误

转载 作者:行者123 更新时间:2023-12-01 09:20:33 26 4
gpt4 key购买 nike

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

如有任何帮助,我们将不胜感激!

最佳答案

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

关于ansible - 运行 ansible 剧本时出现模糊弃用错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39236646/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com