如何在Ansible Playbook中正确格式化files_to_index配置?
解决Ansible Playbook中Splunk索引配置的格式错误
你的问题本质是YAML缩进错误,而非引号问题,TeamCity的错误提示属于误导。files_to_index下的每个列表项(- path:开头的条目)内部的属性(index、sourcetype等)必须和path:保持相同的缩进层级,不能随意增加缩进。
修正后的完整配置代码如下:
- name: Configure Splunk Indexes include_role: name: ansible-role-risk-splunkforwarder vars: action: config splunk_enabled: true splunk_server: "{{ splunk_server_url }}" sw_version: "{{ splunk_version }}" service_name: splunkforwarder tags: [splunk] files_to_index: - path: "{{ base_logs_dir }}/*.log" index: "{{ splunk_index }}" sourcetype: "{{ project_name }}-info" ignore_older_than: 48h time_before_close: 120
关键修正点:
- 将
index、sourcetype等属性的缩进调整为和path:一致(同属-列表项的子层级,保持相同空格数) - 原代码中
index:的缩进比path:多,导致YAML解析器无法识别它是path:所属的子属性,进而抛出错误
内容的提问来源于stack exchange,提问作者MikiBelavista
相关产品推荐
相关产品推荐

