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 -%}
}
任何幫助,將不勝感激!
感謝您的快速回復!在我將變量投入混合之前,這些劇本完全合理。定義多個服務以遍歷logrotate模板任務的最佳方式是什麼? –
set_fact裏面的with_items應該做你想做的事 – nitzmahone
@MarcWKoser你可以使用Matt的建議,但是我建議你修改你的角色並且只傳遞你想創建logrotate配置的服務名字列表,因爲到目前爲止正如我所看到的,除了可以從服務名稱構建的文件路徑之外,所有內容都是相同的。 –