Reputation: 11
Im try this one but always have problem with var my_list - i cant use path to file.
vars:
my_list: "{{ lookup('file', 'id.txt') }}"
tasks:
- name: run shell to get random number
shell: exit `shuf -i 1-500 -n 1`
register: shell_command
failed_when: shell_command.rc > 500
until: shell_command.rc not in my_list
retries: 1000
delay: 1
delegate_to: localhost
- name: print results
debug:
var: shell_command.rc
how to do this in ansible? the contents of the id.txt file are below
349
104
182
111
180
196
Upvotes: 1
Views: 188
Reputation: 68144
For example,
- debug:
msg: "{{ _range|difference(my_list)|random }}"
vars:
my_list: "{{ lookup('file', 'id.txt').splitlines()|map('int')|list }}"
_range: "{{ range(1, 501) }}"
Upvotes: 1