is there a way to define a range of data?

15 views
Skip to first unread message

lou

unread,
Oct 14, 2020, 2:55:33 AM10/14/20
to Ansible Development
Hi Ansible experts,

Is there a way to simplify writing the following (vlan):

---
- hosts: X
  connection: network_cli
  remote_user: admin
  become: yes
  become_method: enable
  vars:
    ansible_network_os: "eos"
  tasks:
    - eos_vlan:
        state: active
        aggregate:
          - { vlan_id: 1, name: default }
          - { vlan_id: 2, name: Vl2 }
          - { vlan_id: 3, state: suspend }
          - { vlan_id: 4 }
          - { vlan_id: 5 }
          - { vlan_id: 6 }
          - { vlan_id: 7 }
          - { vlan_id: 8 }
          - { vlan_id: 9 }
          - { vlan_id: 10 }
          - { vlan_id: 11 }
          - { vlan_id: 12 }
          - { vlan_id: 13 }
          - { vlan_id: 14 }
...
...
If I have to define thousands of vlan_ids, I would love to see Ansible provide some ways to write a range. I'm going to configure thousands of IP addresses, too. 
I can generate the yaml file using python, but it'd be nice to just kind of incorporate some sort of 'range' function . 
I thought Jinja can do this, but I couldn't find any examples - or perhaps Jinja is meant to read not to create data for Ansible. 

Ruby has a way to provide range in yaml.  

Any inputs are greatly appreciated. 

Thanks,
Lou

Sumit Jaiswal

unread,
Oct 14, 2020, 2:59:59 AM10/14/20
to lou, Ansible Development
Hi Lou,

You should be able to resolve the respective use case using Ansible loop param(https://docs.ansible.com/ansible/latest/user_guide/playbooks_loops.html).

Plz ref: https://docs.ansible.com/ansible/latest/user_guide/playbooks_loops.html#with-sequence as it talks about how you can imitate range functionality.


Regards,
Sumit Jaiswal (he/him)
Github/IRC: justjais


--
You received this message because you are subscribed to the Google Groups "Ansible Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-deve...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-devel/eaa8d343-fb1b-4b94-a06e-56cf815b942cn%40googlegroups.com.

lou

unread,
Oct 14, 2020, 11:41:39 AM10/14/20
to Ansible Development
Cool. Just what I needed. Thanks Sumit!
Reply all
Reply to author
Forward
0 new messages