On Thu, Aug 21, 2014 at 11:17 PM, Imran Khan <[email protected]> wrote:
> Thank you for your quick reply:
> But this works, but not in a loop!
>
>     - name: bashless math
>       set_fact:
>         IPOctet: "{{ (ServerIPRange|int/epcrange|int)+IPOctet|int }}"
>       with_sequence: start=1 end=4
>       register: IPOctet

You may have missed a crucial bit of what I wrote- your algorithm
doesn't actually require any iteration. It decomposes into

IPrange/epcrange + (IPrange/epcrange + (IPrange/epcrange +
(IPrange/epcrange + LastIPOctet) ) )

which is the same thing as

4 * (IPrange/epcrange) + LastIPOctet

>
> this wont work either:
>
>     - name: bashless math
>       set_fact:
>         IPOctet: "{{ (ServerIPRange|int/epcrange|int)+IPOctet|int }}"
>       register: IPOctet
>       with_sequence: start=1 end=4
>       register: my_ip_octet
>
> I need to save the value in IPOctet repetitively
>
>
> On Thursday, August 21, 2014 10:40:56 PM UTC-7, Henry Finucane wrote:
>>
>> As an aside, you can do math in Jinja2-
>>
>> - name: bashless math
>>   set_fact:
>>     IPOctet: "{{ 4*(ServerIPRange/epcrange)+IPOctet }}"
>>
>> will do something approaching what you want.
>>
>> If you want to get the actual shell-out working, something like this
>> is going to be enlightening:
>>
>>   - name: local action math
>>     local_action: shell echo "{{ServerIPRange}}/{{epcrange}}+{{IPOctet}}"
>> | bc
>>     with_sequence: start=1 end=4
>>     register: result
>>   - debug: var=result
>>
>> "debug: var=result" will dump a pretty-printed JSON structure, so
>> you'll know what's available, and what you can use. You should try it
>> with & without the with_sequence.
>>
>>
>>
>> On Thu, Aug 21, 2014 at 9:47 PM, Imran Khan <[email protected]> wrote:
>> > I have 3 variables named IPOctet, ServerIPRange and epcrange. If I
>> > perform
>> > the following operation in my terminal, it works perfectly
>> >
>> > IPOctet=$(echo "$ServerIPRange/$epcrange+$IPOctet" | bc)
>> >
>> > How to I do something similar in a ansible inside a task, for e.g
>> >
>> > ---
>> > - hosts: localhost
>> >   gather_facts: False
>> >
>> >   vars_prompt:
>> >     - name: epcrange
>> >       prompt: Enter the number of EPCs that you want to configure
>> >       private: False
>> >       default: "1"
>> >     - name: serverrange
>> >       prompt: Enter the number of Cleints that you want to configure
>> >       private: False
>> >       defualt: "1"
>> >     - name: ServerIPRange
>> >       prompt: Enter the ServerIP range
>> >       private: False
>> >       default: '128'
>> >     - name: LastIPOctet
>> >       prompt: Enter The last Octet of the IP you just entered
>> >       private: False
>> >       default: '10'
>> >
>> >   pre_tasks:
>> >
>> >
>> >     - name: Set some facts
>> >       set_fact:
>> >         ServerIP1: "{{ServerIP}}"
>> >         ServerIPRange1: "{{ServerIPRange}}"
>> >         IPOctet: "{{LastIPOctet}}"
>> >
>> >     - name: local action math
>> >       local_action: shell {{IPOctet}}=$(echo
>> > "${{ServerIPRange}}/${{epcrange}}+${{IPOctet}}" | bc)  # Proper Syntax?
>> >       with_sequence: start=1 end=4
>> >       register: result
>> >       ignore_errors: yes
>> >
>> > What is the proper syntax for this command? Maybe using shell echo
>> > "......."
>> > . I just need to save the contents of this command into the IPOctet
>> > variable
>> > and IPOctet will change with each loop iteration and the results should
>> > be
>> > stored in my result register
>> >
>> > P.S: how can I access the individual items in the array sepearately?
>> >
>> > --
>> > 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/0b34e611-ab2c-45b6-88a9-2caf26ed5504%40googlegroups.com.
>> > For more options, visit https://groups.google.com/d/optout.
>>
>>
>>
>> --
>> -----------------------
>> | Henry Finucane
>> | "I hear aphorisms are popular"
>> -----------------------
>
> --
> 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/54de8cec-df98-4cf0-8f0f-fb8545fef391%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.



-- 
-----------------------
| Henry Finucane
| "I hear aphorisms are popular"
-----------------------

-- 
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/CAGYSzJ82n-G6EAtmc--0T0i-nM95kdCmEGGNj8G264X7q1zJ1g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to