summaryrefslogtreecommitdiffstats
path: root/test/integration/targets/tempfile/tasks/main.yml
blob: 2d783e6f9a9e61f3de22c68610ae2853887d0b52 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
- name: Create a temporary file with defaults
  tempfile:
  register: temp_file_default

- name: Create a temporary directory with defaults
  tempfile:
    state: directory
  register: temp_dir_default

- name: Create a temporary file with optional parameters
  tempfile:
    path: "{{ remote_tmp_dir }}"
    prefix: hello.
    suffix: .goodbye
  register: temp_file_options

- name: Create a temporary directory with optional parameters
  tempfile:
    state: directory
    path: "{{ remote_tmp_dir }}"
    prefix: hello.
    suffix: .goodbye
  register: temp_dir_options

- name: Create a temporary file in a non-existent directory
  tempfile:
    path: "{{ remote_tmp_dir }}/does_not_exist"
  register: temp_file_non_existent_path
  ignore_errors: yes

- name: Create a temporary directory in a non-existent directory
  tempfile:
    state: directory
    path: "{{ remote_tmp_dir }}/does_not_exist"
  register: temp_dir_non_existent_path
  ignore_errors: yes

- name: Check results
  assert:
    that:
      - temp_file_default is changed
      - temp_file_default.state == 'file'
      - temp_file_default.path | basename | split('.') | first == 'ansible'

      - temp_dir_default is changed
      - temp_dir_default.state == 'directory'
      - temp_dir_default.path | basename | split('.') | first == 'ansible'

      - temp_file_options is changed
      - temp_file_options.state == 'file'
      - temp_file_options.path.startswith(remote_tmp_dir)
      - temp_file_options.path | basename | split('.') | first == 'hello'
      - temp_file_options.path | basename | split('.') | last == 'goodbye'

      - temp_dir_options is changed
      - temp_dir_options.state == 'directory'
      - temp_dir_options.path.startswith(remote_tmp_dir)
      - temp_dir_options.path | basename | split('.') | first == 'hello'
      - temp_dir_options.path | basename | split('.') | last == 'goodbye'

      - temp_file_non_existent_path is failed

      - temp_dir_non_existent_path is failed