newbie to ansible

I have the below playbook which creates 20 volumes

i have parameter called type which has 2 values [ rw and dp].

my req is: how to create 10 volumes with type rw and 10 volumes type dp in one playbook.

tasks:

  • name: Create FlexVol
    na_ontap_volume:
    state: absent
    name: vol1{{item}}
    is_infinite: False
    aggregate_name: aggr1
    type:
    size: 10
    size_unit: gb
    junction_path: “/vol{{ item }}”
    tiering_policy: auto
    policy: default
    percent_snapshot_space: 20
    vserver: systemic_iscsi_aggr3svm1
    wait_for_completion: True
    space_slo: none
    nvfail_enabled: False
    comment: ansible created volume
    hostname: “{{aiqumip }}”
    username: “{{ aiqumusername }}”
    password: “{{ aiqumpassword }}”
    with_sequence: start=1 end=20
    loop_control:
    loop_var: volume_item
    register: volcreate
    ignore_errors: True
  • name: 100 volumes created successfully
    debug: msg “{{ volcreate }}”

An option would be the "ternary" filter. For example
https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html#id8

  tasks:
     - name: Create FlexVol
       na_ontap_volume:
         ...
         type: "{{ (volume_item|int < 11)|ternary('rw', 'dp') }}"
         ...
       with_sequence: start=1 end=20
       loop_control:
         loop_var: volume_item

HTH,

  -vlado

Yes. It's possible. Fit the condition to your needs. For example

      type: "{{ (volume_item|int is odd)|ternary('rw', 'dp') }}"

HTH,

  -vlado