我有一个文件,在该文件中我想添加模式:
dogstreams: /root/ddmonitor/pattern.txt:/opt/datadog-agent/agent/checks/libs/parsers.py:parse_web
到文件的末尾。
到目前为止,我已尝试过以下内容:
---
- name: Creates directory
file: path=/root/ddmonitor state=directory owner=root group=root mode=0775
- name: copy the pattern_search.txt file which has patterns to be grepped
copy: src=pattern_search.txt dest=/root/ddmonitor/pattern_search.txt owner=root group=root mode=755
- name: copy the logsearchtest.sh script which greps patterns and prints pattern.txt file
copy: src=logsearchtest.sh dest=/root/ddmonitor/logsearchtest.sh owner=root group=root mode=755
- name: schedule cron to run every 5 minutes
cron: name="logsearch script for grepping pega alert logs" minute="*/5" job="/root/ddmonitor/logsearchtest.sh > /dev/null"
- name: copy parsers.py fucntion to datadog lib path
copy: src=parsers.py dest=/opt/datadog-agent/agent/checks/libs/parsers.py owner=root group=root mode=755
- name: copy datadog agent configuration file
lineinfile: dest=/etc/dd-agent/datadog.conf regexp="^dogstreams: " line="dogstreams: /root/ddmonitor/pattern.txt:/opt/datadog-agent/agent/checks/libs/parsers.py:parse_web"
- name: wait a bit
service: name=datadog-agent state=restarted
when: not datadog_api_key == 'NONE'
但是当我运行我的主剧本时,它会显示以下错误:
ERROR! Syntax Error while loading YAML.
The error appears to have been in '/etc/ansible/roles/datadog-pegalogs-apptier/tasks/main.yml': line 19, column 65, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- name: copy datadog agent configuration file
lineinfile: dest=/etc/dd-agent/datadog.conf regexp="dogstreams: " line="dogstreams: /root/ddmonitor/pattern.txt:/opt/datadog-agent/agent/checks/libs/parsers.py:parse_web"
^ here
We could be wrong, but this one looks like it might be an issue with
unbalanced quotes. If starting a value with a quote, make sure the
line ends with the same set of quotes. For instance this arbitrary
example:
foo: "bad" "wolf"
Could be written as:
foo: '"bad" "wolf"'
答案 0 :(得分:0)
我相信你需要做类似的事情:
由于行上的':'而完全引用。请参阅YAML文档中的Gotchas。
- lineinfile: "dest=/etc/sudoers state=present regexp='^%wheel' line='%wheel ALL=(ALL) NOPASSWD: ALL'"
对于列出here
的“:”存在YAML限制您需要使用冒号引用任何哈希值,如下所示:
foo: "somebody said I should put a colon here: so I did"
所以你的行应该是这样的:
- name: copy datadog agent configuration file
lineinfile: "dest=/etc/dd-agent/datadog.conf regexp='^dogstreams: ' line='dogstreams: /root/ddmonitor/pattern.txt:/opt/datadog-agent/agent/checks/libs/parsers.py:parse_web'"
我猜你可以像{{“:”}}那样逃过冒号:
lineinfile: dest=/etc/dd-agent/datadog.conf regexp="^dogstreams{{ ":" }} " line="dogstreams: /root/ddmonitor/pattern.txt{{ ":" }}/opt/datadog-agent/agent/checks/libs/parsers.py:parse_web"