Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Arithmetic operations inside templates

Tags:

erb

puppet

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?

like image 670
Anuruddha Avatar asked Oct 31 '14 14:10

Anuruddha


People also ask

What are the 5 basic arithmetic operations?

The arithmetic operators perform addition, subtraction, multiplication, division, exponentiation, and modulus operations.

What are the 4 types of arithmetic operators?

These operators are + (addition), - (subtraction), * (multiplication), / (division), and % (modulo).

What is an example of an arithmetic operation?

Addition (Finding the Sum; '+') Subtraction (Finding the difference; '-') Multiplication (Finding the product; '×' ) Division (Finding the quotient; '÷')

What are the 4 arithmetic operations of functions?

We are used to performing the four basic arithmetic operations with integers and polynomials, i.e., addition, subtraction, multiplication, and division.

Is it possible to perform arithmetic operations without formating?

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 in math?

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.

What is an example of arithmetic in programming?

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.

What is arithmetic operations in shell script?

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.


1 Answers

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.

like image 109
ptierno Avatar answered Sep 17 '22 07:09

ptierno