diff options
Diffstat (limited to 'test/using-bare-variables-success.yml')
-rw-r--r-- | test/using-bare-variables-success.yml | 200 |
1 files changed, 200 insertions, 0 deletions
diff --git a/test/using-bare-variables-success.yml b/test/using-bare-variables-success.yml new file mode 100644 index 0000000..c8f0f3f --- /dev/null +++ b/test/using-bare-variables-success.yml @@ -0,0 +1,200 @@ +--- +- hosts: localhost + become: no + vars: + my_list: + - foo + - bar + + my_list2: + - 1 + - 2 + + my_list_of_dicts: + - foo: 1 + bar: 2 + - foo: 3 + bar: 4 + + my_list_of_lists: + - "{{ my_list }}" + - "{{ my_list2 }}" + + my_filenames: + - foo.txt + - bar.txt + + my_dict: + foo: bar + + tasks: + ### Testing with_items loops + - name: with_items loop using static list + debug: + msg: "{{ item }}" + with_items: + - foo + - bar + + - name: with_items using a static hash + debug: + msg: "{{ item.key }} - {{ item.value }}" + with_items: + - { key: foo, value: 1 } + - { key: bar, value: 2 } + + - name: with_items loop using variable + debug: + msg: "{{ item }}" + with_items: "{{ my_list }}" + + ### Testing with_nested loops + - name: with_nested loop using static lists + debug: + msg: "{{ item[0] }} - {{ item[1] }}" + with_nested: + - [ 'foo', 'bar' ] + - [ '1', '2', '3' ] + + - name: with_nested loop using variable list and static + debug: + msg: "{{ item[0] }} - {{ item[1] }}" + with_nested: + - "{{ my_list }}" + - [ '1', '2', '3' ] + + ### Testing with_dict + - name: with_dict loop using variable + debug: + msg: "{{ item.key }} - {{ item.value }}" + with_dict: "{{ my_dict }}" + + ### Testing with_dict with a default empty dictionary + - name: with_dict loop using variable and default + debug: + msg: "{{ item.key }} - {{ item.value }}" + with_dict: "{{ uwsgi_ini | default({}) }}" + + ### Testing with_file + - name: with_file loop using static files list + debug: + msg: "{{ item }}" + with_file: + - foo.txt + - bar.txt + + - name: with_file loop using list of filenames + debug: + msg: "{{ item }}" + with_file: "{{ my_filenames }}" + + ### Testing with_fileglob + - name: with_fileglob loop using list of *.txt + debug: + msg: "{{ item }}" + with_fileglob: + - '*.txt' + + ### Testing non-list form of with_fileglob + - name: with_fileglob loop using single value *.txt + debug: + msg: "{{ item }}" + with_fileglob: '*.txt' + + ### Testing non-list form of with_fileglob with trailing templated pattern + - name: with_fileglob loop using templated pattern + debug: + msg: "{{ item }}" + with_fileglob: 'foo{{glob}}' + + ### Testing with_filetree + - name: with_filetree loop using list of path + debug: + msg: "{{ item }}" + with_filetree: + - path/to/dir1/ + - path/to/dir2/ + + ### Testing non-list form of with_filetree + - name: with_filetree loop using single path + debug: + msg: "{{ item }}" + with_filetree: path/to/dir/ + + ### Testing non-list form of with_filetree with trailing templated pattern + - name: with_filetree loop using templated pattern + debug: + msg: "{{ item }}" + with_filetree: 'path/to/{{ directory }}' + + ### Testing with_together + - name: with_together loop using variable lists + debug: + msg: "{{ item.0 }} - {{ item.1 }}" + with_together: + - "{{ my_list }}" + - "{{ my_list2 }}" + + - name: with_subelements loop + debug: + msg: "{{ item }}" + with_subelements: + - "{{ my_list_of_dicts }}" + - bar + + - name: with_sequence loop + debug: + msg: "{{ item }}" + with_sequence: count=2 + + - name: with_random_choice loop + debug: + msg: "{{ item }}" + with_random_choice: "{{ my_list }}" + + - name: with_first_found loop with static files list + debug: + msg: "{{ item }}" + with_first_found: + - foo.txt + - bar.txt + + - name: with_first_found loop with list of filenames + debug: + msg: "{{ item }}" + with_first_found: "{{ my_filenames }}" + + - name: with_indexed_items loop + debug: + msg: "{{ item.0 }} {{ item.1 }}" + with_indexed_items: "{{ my_list }}" + + - name: with_ini loop + debug: + msg: "{{ item }}" + with_ini: value[1-2] section=section1 file=foo.ini re=true + + - name: with_flattened loop + debug: + msg: "{{ item }}" + with_flattened: + - "{{ my_list }}" + - "{{ my_list2 }}" + + - name: with_flattened loop with a variable + debug: + msg: "{{ item }}" + with_flattened: "{{ my_list_of_lists }}" + + - name: with_flattened loop with a multiline template + debug: + msg: "{{ item }}" + with_flattened: > + {{ my_list + | union(my_list2) + | list }} + + - name: with_inventory_hostnames loop + debug: + msg: "{{ item }}" + with_inventory_hostnames: all |