Random var and lenguage reference

7 views
Skip to first unread message

Josu Vilda

unread,
Oct 25, 2017, 8:14:36 AM10/25/17
to Ansible Project
Hi,

I would like to get a 3 digit random number, for example 001.
I have come to get:

  tasks:
     - name: We assign a fixed random variable throughout the execution.
       set_fact:
          Random_Fix: "{{ 100 | random }}"
       run_once: yes

¿Which language uses "{{100 | random}}" or where can I find reference for this language?

I have been listening for a long time how easy it is to work with ansible, but at the moment it is not being.

Kai Stian Olstad

unread,
Oct 25, 2017, 2:25:54 PM10/25/17
to ansible...@googlegroups.com
On 25. okt. 2017 14:14, Josu Vilda wrote:
> I would like to get a 3 digit random number, for example 001.
> I have come to get:
>
> tasks:
> - name: We assign a fixed random variable throughout the execution.
> set_fact:
> Random_Fix: "{{ 100 | random }}"
> run_once: yes
>
> ¿Which language uses "{{100 | random}}" or where can I find reference for
> this language?

In Ansible {{ }} indicate templating, "language" is Jinja[1].
Ansible extend Jinja with some custom filters[2] and replaces some of the default filters in Jinja, random is such a filter.


[1] jinja.pocoo.org/docs/dev/templates/
[2] https://docs.ansible.com/ansible/latest/playbooks_filters.html

--
Kai Stian Olstad
Reply all
Reply to author
Forward
0 new messages