'Ansible - ACI configure a range

I need to create a script that creates multiple AP with one EPG each , for the AP I can find how to build the range using the ap module , this is what I have so far:

---
- name: ACI Link Level Management
  hosts: APIC
  connection: local
  gather_facts: no
  vars:
    username: admin
    password: Admin
    ap_list: "{{ lookup('sequence', 'start=11 count=5 format=ap%d', wantlist=True) }}"
  tasks:
    - name: Create link level policies
      cisco.aci.aci_ap:
        host: '{{ inventory_hostname }}'
        user: '{{ username }}'
        password: '{{ password }}'
        validate_certs: false
        tenant: DC
        ap: '{{ ap_list }}'
        description: default ap
        monitoring_policy: default
        state: present ...

But I'm getting the following error:

FAILED! => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python3"}, "changed": false, "msg": "Connection failed for /api/mo/uni/tn-DC/ap-['ap11', 'ap12', 'ap13', 'ap14', 'ap15'].json?rsp-prop-include=config-only&rsp-subtree=full&rsp-subtree-class=fvRsApMonPol. An unknown error occurred: URL can't contain control characters. "/api/mo/uni/tn-DC/ap-['ap11', 'ap12', 'ap13', 'ap14', 'ap15'].json?rsp-prop-include=config-only&rsp-subtree=full&rsp-subtree-class=fvRsApMonPol" (found at least ' ')"}



Solution 1:[1]

The parameter ap requires a string. You provided a list instead

ap_list: [ap11, ap12, ap13, ap14, ap15]

See the doc

shell> ansible-doc -t module cisco.aci.aci_ap

Maybe you'd like to iterate the list?

    - name: Create link level policies
      cisco.aci.aci_ap:
        host: '{{ inventory_hostname }}'
        user: '{{ username }}'
        password: '{{ password }}'
        validate_certs: false
        tenant: DC
        ap: '{{ item }}'
        description: default ap
        monitoring_policy: default
        state: present ...
      loop: '{{ ap_list }}'

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Vladimir Botka