Phil, the link doesn't work for me.

On Thursday, May 1, 2014 2:32:23 AM UTC-5, Philippe Eveque wrote:
>
> In similar case A workaround I used  is to add 1 to your sequence count 
> see 
> https://mail.google.com/mail/#search/label%3Aansible+with_sequence/1435e13b34e3a0e1
>
> Phil
>
>
> 2014-04-30 23:51 GMT+02:00 kesten broughton 
> <[email protected]<javascript:>
> >:
>
>> The error is
>> fatal: [localhost] => can't count backwards
>>
>> This occurs whenever count=0 or start=M end=M
>>
>> If with_sequence is used for the purpose of bringing a system to a state 
>> = HAS N of something
>> then there should be a way of running the playbook twice and not having 
>> anything new created.
>> That's what i meant by idempotent.
>>
>>  "with sequence can't traverse a zero length list" accurately describes 
>> my concern
>>
>> kesten
>>
>> On Wednesday, April 30, 2014 3:03:56 PM UTC-5, Michael DeHaan wrote:
>>
>>> You are throwing two words together that have nothing to do with each 
>>> other.
>>>
>>> with_sequence is a loop.
>>>
>>> Idempotency is a mathematical statement that says "F(X) = F(F(X))" for 
>>> how many times X is applied.   
>>>
>>> "This will work if M is strictly less than N, but if M=N (the 
>>> idempotent case) then ansible gives an error."
>>>
>>> What you have here is Ansible giving an error.  It has nothing to do 
>>> with idempotency.
>>>
>>> It may imply "with sequence can't traverse a zero length list", which 
>>> more accurately describes the problem.
>>>
>>> So, the best thing to do here is to share what the error is and we can 
>>> go from there.
>>>
>>>
>>>
>>>
>>>
>>>
>>> On Wed, Apr 30, 2014 at 9:34 AM, Kesten Broughton <
>>> [email protected]> wrote:
>>>
>>>>
>>>> I recently had a need for with_sequence, but it doesn't seem possible 
>>>> to do a zero count of actions.
>>>>
>>>> Suppose i have a local action to create N things, perhaps vms or 
>>>> floating ips.  Some number M < N may already be present.
>>>>
>>>> I'd like to do
>>>>  
>>>> hosts: localhost
>>>> vars:
>>>>    expected_foo_count: 10
>>>>
>>>>  - name: Get the number of foos
>>>>    shell: echo M
>>>>    register: foo_count
>>>>
>>>>  - name: Create the missing number of foos
>>>>    shell: make_new_foos
>>>>    with_sequence: start=0 end="{{expected_foo_count -foo_count.stdout 
>>>> }}"
>>>>
>>>> or  with_sequence: count="{{expected_foo_count - foo_count.stdout}}"
>>>>  
>>>> This will work if M is strictly less than N, but if M=N (the idempotent 
>>>> case) then ansible gives an error.
>>>>
>>>> fatal: [localhost] => can't count backwards
>>>> I tried putting a "when" guard such as
>>>>  when: "{{ expected_foo_count - foo_count.stdout > 0 }}"
>>>>
>>>> But it appears "when" gets evaluated after the with_sequence 
>>>> conditional.  That in itself poses problems, since in branching code the 
>>>> register variables may not be defined and you have to litter code with 
>>>> when: "{{ (register_var or '') | conditional }}".
>>>>
>>>> The problem with the with_sequence is in the lib/ansible/runner/lookup_
>>>> plugins/sequence.py
>>>>
>>>>     def generate_sequence(self):
>>>>         numbers = xrange(self.start, self.end+1, self.stride)
>>>>
>>>> which means that contrary to conventional python such as
>>>> range(a,b) which gives a sequence starting at 'a' and ending at 'b-1', 
>>>> ie. [a,b)  
>>>>
>>>> with_sequence: start=n end=m
>>>>
>>>> runs over the sequence [n,m].  If n=m with_sequence still executes 
>>>> once, so there is no possible way to have a with_sequence that runs zero 
>>>> times.
>>>>
>>>> changing the generate_sequence code to
>>>>    
>>>>     def generate_sequence(self):
>>>>         numbers = xrange(self.start, self.end, self.stride)
>>>>
>>>> Fixes the problem.
>>>>
>>>> Is there a design reason behind not allowing for zero count sequences? 
>>>>  If so, how can a playbook including with_sequence be made idempotent?
>>>>  
>>>> kesten
>>>>  
>>>> -- 
>>>> 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 post to this group, send email to [email protected].
>>>>
>>>> To view this discussion on the web visit https://groups.google.com/d/
>>>> msgid/ansible-project/CAO2fFsVLwC6qoVKReu--
>>>> zjyfOwUA1KUJQWy2cG36nmHRietk0g%40mail.gmail.com<https://groups.google.com/d/msgid/ansible-project/CAO2fFsVLwC6qoVKReu--zjyfOwUA1KUJQWy2cG36nmHRietk0g%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>>> .
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>>
>>>  -- 
>> 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] <javascript:>.
>> To post to this group, send email to [email protected]<javascript:>
>> .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/ansible-project/263df645-0b20-419b-ae3f-2cdff75280f5%40googlegroups.com<https://groups.google.com/d/msgid/ansible-project/263df645-0b20-419b-ae3f-2cdff75280f5%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/361bfbdc-5ba1-4bcc-bde5-603c633cf4fa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to