I'm trying to add a number to a parameter inside a puppet template as below
"https://localhost:<%= 9443 + @offset %>/service/"
This gives me the following error.
Detail: String can't be coerced into Fixnum
'offset' is a numeric value. Is it possible to do this kind of arithmetic operations in puppet?
The arithmetic operators perform addition, subtraction, multiplication, division, exponentiation, and modulus operations.
These operators are + (addition), - (subtraction), * (multiplication), / (division), and % (modulo).
Addition (Finding the Sum; '+') Subtraction (Finding the difference; '-') Multiplication (Finding the product; '×' ) Division (Finding the quotient; '÷')
We are used to performing the four basic arithmetic operations with integers and polynomials, i.e., addition, subtraction, multiplication, and division.
It is possible to conduct the arithmetic operation in a way that generates output that is appropriate for floating-point values by using the ‘awk’ command as well. It has been demonstrated in this example that the arithmetic operations may be performed using the ‘awk’ command both without and with formating.
What are arithmetic operations? Arithmetic operations is a branch of mathematics, that involves the study of numbers, operation of numbers that are useful in all the other branches of mathematics. It basically comprises operations such as Addition, Subtraction, Multiplication and Division.
Examples include converting a unit of data you are dealing with, rounding a divided value to the closest integer, incrementing a counter in a basic loop, and so forth. Almost every programming language includes built-in support for fundamental arithmetic operations against a wide range of data types.
Arithmetic operations is a branch of mathematics, that involves the study of numbers, operation of numbers that are useful in all the other branches of mathematics. It basically comprises operations such as Addition, Subtraction, Multiplication and Division. How do you evaluate an arithmetic expression in a shell script? 2. Variables in bash 2.1.
Everything in puppet is parsed as a string. Give the following a try:
"https://localhost:<%= 9443 + @offset.to_i %>/service/"
or
"https://localhost:<%= 9443 + Integer(@offset) %>/service/"
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With