On Fri, 8 May 2020 08:49:14 -0700 (PDT) Albert Short <[email protected]> wrote:
> Scenario: > Variables I am using > access_hostname: > - name: dariusz_access1 > nodeid_access: 1001 > from_port: '04' > vlanid: > - 201-204,500-510 > podid: 1 > int_mode: regular > depl_immediacy: lazy > > - name: dariusz_access2 > nodeid_access: 1001 > from_port: '05' > vlanid: > - 10,1200 > podid: 1 > int_mode: regular > depl_immediacy: lazy > > What I want to achieve is to expand my 'vlanid' variable into a list of > individual items: It's possible to create "filter_plugins" https://docs.ansible.com/ansible/latest/dev_guide/developing_plugins.html#filter-plugins For example shell> cat filter_plugins/my_filters.py def my_range(s): interval = str(s).split("-") start = int(interval[0]) if len(interval) > 1: stop = int(interval[1]) + 1 else: stop = start + 1 return [i for i in range(start,stop)] def my_split(s): return str(s).split(",") class FilterModule(object): def filters(self): return { 'my_range': my_range, 'my_split': my_split } Then this task does the job - debug: msg: "{{ item.vlanid| map('my_split')|flatten| map('my_range')|flatten }}" loop: "{{ access_hostname }}" HTH, -vlado -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/20200508210617.471bc01c%40gmail.com.
pgp5TUReM8m4p.pgp
Description: OpenPGP digital signature
