# with\_sequence run a line only once

**URL:** <https://forum.ansible.com/t/with-sequence-run-a-line-only-once/29377>\
**Category:** Ansible Project\
**Created:** [January 5, 2019, 1:08pm UTC](https://forum.ansible.com/t/with-sequence-run-a-line-only-once/29377 "2019-01-05T13:08:11Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Piyush\_Bansal](https://avatars.discourse-cdn.com/v4/letter/p/50afbb/32.png) [@Piyush\_Bansal](https://forum.ansible.com/u/Piyush_Bansal)\
**Post date:** [January 5, 2019, 1:08pm UTC](https://forum.ansible.com/t/with-sequence-run-a-line-only-once/29377/1 "2019-01-05T13:08:11Z")

</div>

Hello,

I am trying to loop over a task using “with\_sequence” and I need to make it work such that it run one specific line only once but rest of the lines it executes as normal times.  
It not succeeding or I am not able to figure out how to do it.  
Please advise

Ansible 2.7.5  
Python: 3.6.6  
CentOS  
Target Host: HP3PAR storage

Activity: I need to create 800 LUNs with different capacity

Thanks,  
Piyush

---

<div class="post-metadata">

**Author:** ![Karl\_Auer](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@Karl\_Auer](https://forum.ansible.com/u/Karl_Auer)\
**Post date:** [January 5, 2019, 2:32pm UTC](https://forum.ansible.com/t/with-sequence-run-a-line-only-once/29377/2 "2019-01-05T14:32:52Z")

</div>

Please provide sample code, or pseudocode…

---

<div class="post-metadata">

**Author:** ![Piyush\_Bansal](https://avatars.discourse-cdn.com/v4/letter/p/50afbb/32.png) [@Piyush\_Bansal](https://forum.ansible.com/u/Piyush_Bansal)\
**Post date:** [January 5, 2019, 2:44pm UTC](https://forum.ansible.com/t/with-sequence-run-a-line-only-once/29377/3 "2019-01-05T14:44:19Z")

</div>

Hello Karl,

Here is the task which I want to loop over but need to run “size: XX” line only once.

- name: Create Virtual Volume  
hpe3par\_volume:  
volume\_name: “vv\_3par\_{{item}}”  
cpg: “XXXX”  
state: “present”  
size: “1000”  
size\_unit: “GiB”  
with\_sequence: start=1 end={{item10}}  
ignore\_errors: True

---

<div class="post-metadata">

**Author:** ![Karl\_Auer](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@Karl\_Auer](https://forum.ansible.com/u/Karl_Auer)\
**Post date:** [January 5, 2019, 3:04pm UTC](https://forum.ansible.com/t/with-sequence-run-a-line-only-once/29377/4 "2019-01-05T15:04:28Z")

</div>

When in the sequence do you want to specify the size, and what size(s) should the other volumes be if no size is specified?

I.e., what are you trying to achieve?

Regards, K.

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [January 5, 2019, 5:11pm UTC](https://forum.ansible.com/t/with-sequence-run-a-line-only-once/29377/5 "2019-01-05T17:11:56Z")

</div>

According to the documentation the size is mandatory/required when using state: present, so why would you wanna leave that out?

---

<div class="post-metadata">

**Author:** ![Piyush\_Bansal](https://avatars.discourse-cdn.com/v4/letter/p/50afbb/32.png) [@Piyush\_Bansal](https://forum.ansible.com/u/Piyush_Bansal)\
**Post date:** [January 5, 2019, 6:09pm UTC](https://forum.ansible.com/t/with-sequence-run-a-line-only-once/29377/6 "2019-01-05T18:09:27Z")

</div>

Hello Kai,

I need to create multiple volumes of different sizes  
example:  
10 Volumes of 50GB  
50 Volumes of 500GB  
100 Volumes of 5000GB

I usually get such requests so, I thought of creating one playbook which could give me following result:

1. Create Volume on hp3par storage box
2. Map this newly created volume to the existing host entry in hp3par storage.

And thats why I thought of looping over volume creation task, same number of times the requester requested to create same size volume. like a loop of 10 times for 50GB volume. And I created some vars\_prompt to ask for like:

- host names
- volume size
- number of volumes to create etc

The volume creation task module & its parameters are as follows:

- name: Create Virtual Volume  
hpe3par\_volume:  
volume\_name: “vv\_3par\_{{item}}”  
cpg: “XXXX”  
state: “present”  
size: “1000”  
size\_unit: “GiB”  
with\_sequence: start=1 end={{item10}}  
ignore\_errors: True

This loop runs over all the parameter and hence prompt for size as same number of times the loop run even for the same size of volumes.  
Whereas I want it to ask for size only for once and create this same size of volume 10 times or whatever requested times.

Hoping, I have explained it efficient manner this time 🙂

So, I do not want to leave that out rather just want to take the input only once and size being required parameter of the module, it will be asked every time the loop iterates.

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [January 5, 2019, 6:33pm UTC](https://forum.ansible.com/t/with-sequence-run-a-line-only-once/29377/7 "2019-01-05T18:33:22Z")

</div>

> Hello Kai,
> 
> I need to create multiple volumes of different sizes  
> example:  
> 10 Volumes of 50GB  
> 50 Volumes of 500GB  
> 100 Volumes of 5000GB
> 
> I usually get such requests so, I thought of creating one playbook which  
> could give me following result:
> 
> 1. Create Volume on hp3par storage box  
> 2. Map this newly created volume to the existing host entry in hp3par  
> storage.
> 
> And thats why I thought of looping over volume creation task, same number  
> of times the requester requested to create same size volume. like a loop of  
> 10 times for 50GB volume. And I created some vars\_prompt to ask for like:  
> - host names  
> - volume size  
> - number of volumes to create etc
> 
> The volume creation task module & its parameters are as follows:
> 
> - name: Create Virtual Volume  
> &nbsp;&nbsp;&nbsp;hpe3par\_volume:  
> &nbsp;&nbsp;&nbsp;&nbsp;volume\_name: "vv\_3par\_{{item}}"  
> &nbsp;&nbsp;&nbsp;&nbsp;cpg: "XXXX"  
> &nbsp;&nbsp;&nbsp;&nbsp;state: "present"  
> &nbsp;&nbsp;&nbsp;&nbsp;size: "1000"  
> &nbsp;&nbsp;&nbsp;&nbsp;size\_unit: "GiB"  
> &nbsp;&nbsp;&nbsp;with\_sequence: start=1 end={{item10}}  
> &nbsp;&nbsp;&nbsp;ignore\_errors: True
> 
> This loop runs over all the parameter and hence prompt for size as same  
> number of times the loop run even for the same size of volumes.  
> Whereas I want it to ask for size only for once and create this same size  
> of volume 10 times or whatever requested times.  
> Hoping, I have explained it efficient manner this time 🙂

It seams you have left out a lot of the code you are actually running so this it's impossible to understand what you are having trouble with.

> So, I do not want to leave that out rather just want to take the input only  
> once and size being required parameter of the module, it will be asked  
> every time the loop iterates.

I'm not sure i understand the problem you have ref the above, but if you create an vars\_promt with name size and one with name count then this task would work

- name: Create Virtual Volume  
&nbsp;&nbsp;hpe3par\_volume:  
&nbsp;&nbsp;&nbsp;&nbsp;volume\_name: "vv\_3par\_{{item}}"  
&nbsp;&nbsp;&nbsp;&nbsp;cpg: "XXXX"  
&nbsp;&nbsp;&nbsp;&nbsp;state: "present"  
&nbsp;&nbsp;&nbsp;&nbsp;size: "{{ size }}"  
&nbsp;&nbsp;&nbsp;&nbsp;size\_unit: "GiB"  
&nbsp;&nbsp;with\_sequence: start=1 end={{ count | int }}  
&nbsp;&nbsp;ignore\_errors: True
