newbie to ansible

23 views
Skip to first unread message

mahesh g o

unread,
Apr 7, 2020, 12:59:36 AM4/7/20
to Ansible Project

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

Vladimir Botka

unread,
Apr 7, 2020, 1:18:20 AM4/7/20
to mahesh g o, ansible...@googlegroups.com
On Mon, 6 Apr 2020 21:59:36 -0700 (PDT)
mahesh g o <mahe...@gmail.com> wrote:

> i have parameter called *type *which has 2 values [ rw and dp].
> How to create 10 volumes with type rw and 10 volumes type dp in
> one playbook.

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

Vladimir Botka

unread,
Apr 7, 2020, 9:32:41 AM4/7/20
to ansible...@googlegroups.com, mahesh g o
On Tue, 7 Apr 2020 18:08:48 +0530
mahesh g o <mahe...@gmail.com> wrote:

> can this be created alternatively like
> vol1: rw
> vol2: dp
> vol3:rw
> vol4:dp
> .
> .
> vol29:rw
> vol30:dp

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

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

HTH,

-vlado
Reply all
Reply to author
Forward
0 new messages