1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00
community.general/test/integration/targets/loops/tasks/main.yml

149 lines
4.1 KiB
YAML
Raw Normal View History

- name: Measure time before
shell: date +%s
register: before
- debug:
var: i
with_sequence: count=3
loop_control:
loop_var: i
pause: 2
- name: Measure time after
shell: date +%s
register: after
# since there is 3 rounds, and 2 seconds between, it should last 4 seconds
# we do not test the upper bound, since CI can lag significantly
- assert:
that:
- '(after.stdout |int) - (before.stdout|int) >= 4'
#
# Tests of loop syntax with args
#
- name: Test that with_list works with a list
ping:
data: '{{ item }}'
with_list:
- 'Hello World'
- 'Olá Mundo'
register: results
- name: Assert that we ran the module twice with the correct strings
assert:
that:
- 'results["results"][0]["ping"] == "Hello World"'
- 'results["results"][1]["ping"] == "Olá Mundo"'
- name: Test that with_list works with a list inside a variable
ping:
data: '{{ item }}'
with_list: '{{ phrases }}'
register: results2
- name: Assert that we ran the module twice with the correct strings
assert:
that:
- 'results2["results"][0]["ping"] == "Hello World"'
- 'results2["results"][1]["ping"] == "Olá Mundo"'
- name: Test that loop works with a manual list
ping:
data: '{{ item }}'
loop:
- 'Hello World'
- 'Olá Mundo'
register: results3
- name: Assert that we ran the module twice with the correct strings
assert:
that:
- 'results3["results"][0]["ping"] == "Hello World"'
- 'results3["results"][1]["ping"] == "Olá Mundo"'
- name: Test that loop works with a list in a variable
ping:
data: '{{ item }}'
loop: '{{ phrases }}'
register: results4
- name: Assert that we ran the module twice with the correct strings
assert:
that:
- 'results4["results"][0]["ping"] == "Hello World"'
- 'results4["results"][1]["ping"] == "Olá Mundo"'
- name: Test that loop works with a list via the list lookup
ping:
data: '{{ item }}'
loop: '{{ lookup("list", "Hello World", "Olá Mundo", wantlist=True) }}'
register: results5
- name: Assert that we ran the module twice with the correct strings
assert:
that:
- 'results5["results"][0]["ping"] == "Hello World"'
- 'results5["results"][1]["ping"] == "Olá Mundo"'
- name: Test that loop works with a list in a variable via the list lookup
ping:
data: '{{ item }}'
loop: '{{ lookup("list", wantlist=True, *phrases) }}'
register: results6
- name: Assert that we ran the module twice with the correct strings
assert:
that:
- 'results6["results"][0]["ping"] == "Hello World"'
- 'results6["results"][1]["ping"] == "Olá Mundo"'
- name: Test that loop works with a list via the query lookup
ping:
data: '{{ item }}'
loop: '{{ query("list", "Hello World", "Olá Mundo") }}'
register: results7
- name: Assert that we ran the module twice with the correct strings
assert:
that:
- 'results7["results"][0]["ping"] == "Hello World"'
- 'results7["results"][1]["ping"] == "Olá Mundo"'
- name: Test that loop works with a list in a variable via the query lookup
ping:
data: '{{ item }}'
loop: '{{ q("list", *phrases) }}'
register: results8
- name: Assert that we ran the module twice with the correct strings
assert:
that:
- 'results8["results"][0]["ping"] == "Hello World"'
- 'results8["results"][1]["ping"] == "Olá Mundo"'
- name: Test that loop works with a list and keyword args
ping:
data: '{{ item }}'
loop: '{{ q("file", "data1.txt", "data2.txt", lstrip=True) }}'
register: results9
- name: Assert that we ran the module twice with the correct strings
assert:
that:
- 'results9["results"][0]["ping"] == "Hello World"'
- 'results9["results"][1]["ping"] == "Olá Mundo"'
- name: Test that loop works with a list in variable and keyword args
ping:
data: '{{ item }}'
loop: '{{ q("file", lstrip=True, *filenames) }}'
register: results10
- name: Assert that we ran the module twice with the correct strings
assert:
that:
- 'results10["results"][0]["ping"] == "Hello World"'
- 'results10["results"][1]["ping"] == "Olá Mundo"'