这是一个 ansible 脚本,我希望它能打印出相同的随机数 3 次。相反,它打印出三个随机数。如何将随机数分配给 ansible 中的变量,以便它在整个剧本中固定?
---
- name: Test random filter
hosts: localhost
gather_facts: False
vars:
random_number: "{{ 100 | random }}"
tasks:
- name: Print the random number
debug: var=random_number
- name: Print the random number
debug: var=random_number
- name: Print the random number
debug: var=random_number
只需使用set_fact
首先将模块作为任务:
- set_fact:
r: "{{ 100 | random }}"
run_once: yes
随后,debug: msg=...
具有以下价值r
fixed.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)