# query on ansible

**URL:** <https://forum.ansible.com/t/query-on-ansible/32710>\
**Category:** Ansible Project\
**Created:** [April 17, 2020, 8:54am UTC](https://forum.ansible.com/t/query-on-ansible/32710 "2020-04-17T08:54:51Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mahesh\_g\_o](https://avatars.discourse-cdn.com/v4/letter/m/e9bcb4/32.png) [@mahesh\_g\_o](https://forum.ansible.com/u/mahesh_g_o)\
**Post date:** [April 17, 2020, 8:54am UTC](https://forum.ansible.com/t/query-on-ansible/32710/1 "2020-04-17T08:54:51Z")

</div>

I have below playbook:

i have put a loop, there are 8 aggr and 4 protocols: this playbook output is like after every 4 loop, it increments aggr and protocols.

output of the playbook is:

svm1,svm2,svm3,svm4—aggr1 and nfs  
svm5,svm6,svm7,svm8—aggr2 and iscsi

svm9,svm10,svm11,svm12—aggr3 and cifs

svm13,svm14,svm15,svm16—aggr4 and fcp

currently the ansible is failing because after 16th loop it is not finding any protocols.

but after 16th loop i want protcols to repeat :

expecting ouput:

svm17,svm18,svm19,svm20—aggr5 and nfs  
svm21,svm22,svm23,svm24—aggr6 and iscsi

svm25,svm26,svm27,svm28—aggr7 and cifs

svm29,svm30,svm31,svm32—aggr8 and fcp

- hosts: localhost  
gather\_facts: false  
vars\_files:
- /etc/ansible/group\_vars/host\_vars

vars:  
aggr:

- aggr\_1
- aggr\_2
- aggr\_3
- aggr\_4
- aggr\_5
- aggr\_6
- aggr\_7
- aggr\_8  
protocols:
- nfs
- iscsi
- cifs
- fcp  
tasks:
- name: Create SVM  
na\_ontap\_svm:  
state: present  
name: “svm{{ item }}”  
root\_volume: “svm{{ item }}\_root\_vol”  
root\_volume\_aggregate: “{{ aggr[((item|int-1)//4)] }}”  
allowed\_protocols: “{{ protocols[(((item)|int-1)//4)] }}”  
root\_volume\_security\_style: mixed  
hostname: “{{ aiqumip }}”  
username: “{{ aiqumusername }}”  
password: “{{ aiqumpassword }}”  
https: false  
with\_sequence: start=1 end=32

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [April 17, 2020, 9:19am UTC](https://forum.ansible.com/t/query-on-ansible/32710/2 "2020-04-17T09:19:00Z")

</div>

There is better way to handle all permutations. Replace with\_sequence:

&nbsp;&nbsp;loop: "{{ aggr | product(protocols) | list }}"  
&nbsp;&nbsp;loop\_control:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;index\_var: "loop\_index"

Then adjust your module parameters:

&nbsp;&nbsp;name: "svm{{ loop\_index + 1 }}"  
&nbsp;&nbsp;root\_volume: "svm{{ loop\_index + 1 }}\_root\_vol"  
&nbsp;&nbsp;root\_volume\_aggregate: "{{ item[0] }}"  
&nbsp;&nbsp;allowed\_protocols: "{{ item[1] }}"

That should do the trick.

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![mahesh\_g\_o](https://avatars.discourse-cdn.com/v4/letter/m/e9bcb4/32.png) [@mahesh\_g\_o](https://forum.ansible.com/u/mahesh_g_o)\
**Post date:** [April 17, 2020, 10:55am UTC](https://forum.ansible.com/t/query-on-ansible/32710/3 "2020-04-17T10:55:40Z")

</div>

Thank u very much …it worked.

I need one more help…the aggr is coming from the playbook1. every time i run that playbook1 individually and i enter the aggr array in playbook2.  
so how do i get the output of the playbook1 in the form of array so that i dont have to enter the aggr array in the playbook2.

playbook2: is the one i shared earlier.

playbook1:

tasks:

- name: Create Aggregates and wait 5 minutes until aggregate is online  
na\_ontap\_aggregate:  
state: absent  
service\_state: online  
name: “aggr\_{{item }}”  
disk\_count: 5  
wait\_for\_online: True  
nodes: “{{ node[((item|int-1)//2)] }}”  
time\_out: 300  
hostname: “{{ aiqumip }}”  
username: “{{ aiqumusername }}”  
password: “{{ aiqumpassword }}”  
validate\_certs: false  
with\_sequence: start=1 end=8

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [April 17, 2020, 10:58am UTC](https://forum.ansible.com/t/query-on-ansible/32710/4 "2020-04-17T10:58:55Z")

</div>

> Thank u very much ...it worked.

You are welcome.

> I need one more help....the aggr is coming from the playbook1. every time i run that playbook1 individually and i enter  
> the aggr array in playbook2.  
> so how do i get the output of the playbook1 in the form of array so that i dont have to enter the aggr array in the  
> playbook2.
> 
> playbook2: is the one i shared earlier.

First question would be why do you have two separate playbooks?

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![mahesh\_g\_o](https://avatars.discourse-cdn.com/v4/letter/m/e9bcb4/32.png) [@mahesh\_g\_o](https://forum.ansible.com/u/mahesh_g_o)\
**Post date:** [April 17, 2020, 11:08am UTC](https://forum.ansible.com/t/query-on-ansible/32710/5 "2020-04-17T11:08:29Z")

</div>

I am newbie to ansible…i have to create many objects like this(aggr,svm,volumes,luns,policies,network interfaces) so i have created playbook for each objects and thought of stitching it together.

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [April 17, 2020, 11:12am UTC](https://forum.ansible.com/t/query-on-ansible/32710/6 "2020-04-17T11:12:41Z")

</div>

> I am newbie to ansible....i have to create many objects like this(aggr,svm,volumes,luns,policies,network interfaces) so  
> i have created playbook for each objects and thought of stitching it together.

Yes it is good idea to split up tasks logically, but not a good idea to use separate playbooks:

You can group them in task files,.e.g.

&nbsp;&nbsp;&nbsp;tasks:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- import\_tasks: aggr.yml  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- import\_tasks: svm.yml

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![mahesh\_g\_o](https://avatars.discourse-cdn.com/v4/letter/m/e9bcb4/32.png) [@mahesh\_g\_o](https://forum.ansible.com/u/mahesh_g_o)\
**Post date:** [April 17, 2020, 11:18am UTC](https://forum.ansible.com/t/query-on-ansible/32710/7 "2020-04-17T11:18:06Z")

</div>

okay, so if i use them as tasks, will svm.yml takes aggr array from aggr.yml??
