I have 3 variables named IPOctet, ServerIPRange and epcrange. If I perform the following operation in the terminal, it works fine
IPOctet=$(echo "$ServerIPRange/$epcrange+$IPOctet" | bc)
How can I do something like this inaccessible inside the task, for example,
--- - 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 Clients that you want to configure private: False default: "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)
What is the correct syntax for this command? Perhaps using shell echo ".......". I just need to save the contents of this command in the IPOctet variable, and the IPOctet will change with each iteration of the loop, and the results should be stored in my results registry
PS: how can I access the individual elements in the array separately?
Edit: something like this is possible, currently it just does the calculation once and saves it 4 times in the register ...
- name: bashless math set_fact: IPOctet: "{{ (ServerIPRange|int/epcrange|int)+IPOctet|int }}" register: IPOctet with_sequence: "start=1 end={{stop}} " register: my_ip_octet
source share