siride
siride

Reputation: 209915

Strange syntax errors with with_sequence

The code is this:

- 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

The error I get is:

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']"}

I've tried some alternate syntaxes:

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

Which gives:

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

And:

  with_sequence: "count={{ __loadbalancer_processor_count }}"

Which gives:

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"}

The relevant documentation gives either the sequence notation or the key=value notation. None of these are working and it's not at all clear why. Searching for these errors on Google is turning up nothing similar.

Upvotes: 1

Views: 1280

Answers (1)

Konstantin Suvorov
Konstantin Suvorov

Reputation: 68309

with_sequence doesn't accept parameters as dict, only as string!
Either in shortcut format [start-]end[/stride][:format],
or in key=value format start=5 end=11 stride=2 format=0x%02x.

Shortcut syntax is broken (seems long ago). I'll make Issue/PR to fix it.

You can inspect code for documentation and parameters parsing:

So only valid syntax for you is (as per current Ansible ver 2.2.1):

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

or

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

Update: Issue, PR

Upvotes: 2

Related Questions