此代码在1.7中正常工作。我更新到1.8,现在我得到一个语法错误。任务中的Ansible语法错误
这是nagios_iptables.yml代码
---
- name: get iptables rules
shell: iptables -L
register: iptablesrules
always_run: yes
changed_when: false
- name: add nagios iptables port 5666
command: /sbin/iptables -I INPUT 1 -p tcp --dport 5666 --source 192.168.1.59 -j ACCEPT -m comment --comment "nagios"
when: iptablesrules.stdout.find("nagios") == -1
- name: add nagios iptables port 5666 localhost
command:/sbin/iptables -I INPUT 1 -p tcp --dport 5666 --source 127.0.0.1 -j ACCEPT -m comment --comment "nagios"
when: iptablesrules.stdout.find("nagios") == -1
- name: save iptables
command: service iptables save
- name: restart iptables
service: name=iptables state=restarted
这是我怎么称呼它:
- include: tasks/nagios_iptables.yml
这是语法错误,我得到:
ERROR: Syntax Error while loading YAML script,
.../playbooks/tasks/nagios_iptables.yml
Note: The error may actually appear before this position: line 14, column 3
command:/sbin/iptables -I INPUT 1 -p tcp --dport 5666 --source 127.0.0.1 -j ACCEPT -m comment --comment "nagios" when: iptablesrules.stdout.find("nagios") == -1
我不知道问题是什么,希望它是明显的。
根据维基百科,YAML格式*需要*冒号后的空格:“键与冒号+空格分隔。”所以如果它以前有效,那就是错误,而不是现在的表现。资料来源:http://en.wikipedia.org/wiki/YAML#Associative_arrays – fukawi2 2014-12-04 03:12:43
看起来像一个“我们修正了错误”,这就是为什么它不再工作,情况。很公平。 – jgritty 2014-12-04 08:06:51