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?
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/66c32a8d-aa26-49bb-971e-3c435d2d5455%40googlegroups.com.
The shell command only does the calculation once and stores the same value in each loop iteration. I want it to run the command by using the last calculated value, which is supposedly not happening for me. Can the jinj2 sum or replace filters be of any help ?
--
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 ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/59afaa29-847a-4859-8084-b1075229792c%40googlegroups.com.
Well I just want a loop, that does the following:
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/fe7b19c1-b4d7-4c35-98ca-55ed6a6f76aa%40googlegroups.com.
On Aug 23, 2014 10:09 AM, "Imran Khan" <khan.im...@gmail.com> wrote:
>
> I posted that code piece of code for explanation purposes only, loop iteration i.e. the stop value is not fixed and will vary each time depending on user input (it is taken from the user at run time using vars_prompt)
>
> Please can you tell me how to do x=x+y with x=10(will change with each loop iteration) and y=5 (remains constant), inside a loop that runs ten any number of time
That decomposes the same way!
In any case, the yaml/jinja2 layer is generally the wrong layer to do logic in if your logic is going to get complicated. If you write a module, you can do anything python can do.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/fe7b19c1-b4d7-4c35-98ca-55ed6a6f76aa%40googlegroups.com.