OneFuse Example SPS Groups with Jinja2

Overview

In this article we will go over some examples of jinja2 language inside of a Static Property Set (SPS) Group

Considerations

We will assume you already have OneFuse configured and are modifying/updating a current Static Property Set (SPS) group with template logic

Jinja2 Language

IF Statement
Note: Code was broken out from one line so it’s easier to read

{% if OS == "OS_CentOS7" %}Linux
{% elif OS == "OS_Windows2019" %}Windows
{% else %}Other
{% endif %}

SPS Group

{
  "OperatingSystem": "{% if OS == "OS_CentOS7" %}Linux{% elif OS == "OS_Windows2019" %}Windows{% else %}Other{% endif %}"
}

Result

  • "OperatingSystem": "Linux"

 

Random Number/Letter

{{ range(1, 51) | random }}

{{ ['a', 'b', 'c'] | random }}

SPS Group

{
  "RandomNumber": "{{ range(1, 51) | random }}"
  "RandomLetter": "{{ ['a', 'b', 'c'] | random }}",
}

Result

  • "RandomNumber": "34"

  • "RandomLetter": "b"



Substring

{{ OperatingSystem[0:1] }}

SPS Group

{
  "OSL": "{{ OperatingSystem[0:1] }}"
}

Result 

  • "OSL": "L"

Upper
Note: OperatingSystem is “Linux” in this example

{{ OperatingSystem | upper }}

SPS Group

{
  "OSL": "{{ OperatingSystem | upper }}"
}

Result 

  • "OSL": "LINUX"

Lower

Note: OperatingSystem is “Linux” in this example

{{ OperatingSystem | lower }}

SPS Group

{
  "OSL": "{{ OperatingSystem | lower }}"
}

Result 

  • "OSL": "linux"



Additional information

Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.