with_sequence出现奇怪的语法错误

时间:2017-03-24 20:43:58

标签: ansible jinja2

代码是这样的:

- name: Enable monitoring ports (SELinux)
  firewalld:
    ports: "{{ _loadbalancer_https_stat_base + item|int }}"
    proto: tcp
    setype: http_port_t
    state: present
  become: yes
  with_sequence:
    count: "{{ __loadbalancer_processor_count }}"
  notify: Restart firewalld

我得到的错误是:

fatal: [loadbalancer.vbox]: FAILED! => {"failed": true, "msg": "unknown error parsing with_sequence arguments: u'count'. Error was: unrecognized arguments to with_sequence: [u'_raw_params']"}

我尝试了一些替代语法:

  with_sequence:
    - count: "{{ __loadbalancer_processor_count }}"

给出了:

fatal: [loadbalancer.vbox]: FAILED! => {"failed": true, "msg": "unknown error parsing with_sequence arguments: {u'count': 4}. Error was: expected string or buffer"}

  with_sequence: "count={{ __loadbalancer_processor_count }}"

给出了:

failed: [loadbalancer.vbox] (item=1) => {"failed": true, "item": "1", "msg": "unsupported parameter for module: proto"}
failed: [loadbalancer.vbox] (item=2) => {"failed": true, "item": "2", "msg": "unsupported parameter for module: proto"}
failed: [loadbalancer.vbox] (item=3) => {"failed": true, "item": "3", "msg": "unsupported parameter for module: proto"}
failed: [loadbalancer.vbox] (item=4) => {"failed": true, "item": "4", "msg": "unsupported parameter for module: proto"}

相关文档提供了序列符号或key = value表示法。这些都不起作用,并不清楚为什么。在Google上搜索这些错误并没有任何相似之处。

1 个答案:

答案 0 :(得分:2)

with_sequence不接受dict参数,仅作为字符串! 以快捷方式格式[start-]end[/stride][:format]
或者使用key=value格式start=5 end=11 stride=2 format=0x%02x

快捷方式语法被破坏(似乎很久以前)。我将发布问题/公关来修复它。

您可以检查documentation和参数parsing的代码:

因此,只有有效的语法(根据当前的Ansible ver 2.2.1):

with_sequence:
  - "count={{ __loadbalancer_processor_count }}" # one sequence
  - "count={{ another_count }}" # another sequence in the same loop

with_sequence: "count={{__loadbalancer_processor_count}}" # single sequence

更新:IssuePR