任务中的Ansible语法错误

时间:2014-12-03 06:36:57

标签: ansible ansible-playbook

此代码在1.7中运行良好。我更新到1.8,现在我收到语法错误。

这是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

这是我得到的语法错误:

  

错误:加载YAML脚本时出现语法错误,

     

... /剧本/任务/ nagios_iptables.yml

     

注意:错误实际上可能出现在此位置之前:第14行,   第3栏

     

命令:/ 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

我不知道问题是什么,希望它是显而易见的。

1 个答案:

答案 0 :(得分:0)

嗯,结果显而易见。

然而,这是相当阴险的。

问题是这一行缺少空间:

command:/sbin/iptables -I INPUT 1 -p tcp --dport 5666 --source 127.0.0.1 -j ACCEPT -m comment --comment "nagios"

command:/sbin/iptables之间缺少空格会导致问题。

这似乎是1.8的新限制,或者我可能会发疯。

相关问题