summaryrefslogtreecommitdiffstats
path: root/test/integration/targets/unarchive/tasks/test_symlink.yml
blob: 5b3b7ceec398c0c121ba1da99121c9bd65a3958f (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
- name: Create a destination dir
  file:
    path: "{{ remote_tmp_dir }}/test-unarchive-tar-gz"
    state: directory

- name: Create a symlink to the destination dir
  file:
    path: "{{ remote_tmp_dir }}/link-to-unarchive-dir"
    src: "{{ remote_tmp_dir }}/test-unarchive-tar-gz"
    state: "link"

- name: test that unarchive works when dest is a symlink to a dir
  unarchive:
    src: "{{ remote_tmp_dir }}/test-unarchive.tar.gz"
    dest: "{{ remote_tmp_dir }}/link-to-unarchive-dir"
    mode: "u+rwX,go+rX"
    remote_src: yes
  register: unarchive_11

- name: Check that file is really there
  stat:
    path: "{{ remote_tmp_dir }}/test-unarchive-tar-gz/foo-unarchive.txt"
  register: unarchive11_stat0

- name: Assert that unarchive when dest is a symlink to a dir worked
  assert:
    that:
      - "unarchive_11.changed == true"
      - "unarchive11_stat0.stat.exists == true"

- name: remove our tar.gz unarchive destination
  file:
    path: '{{ remote_tmp_dir }}/test-unarchive-tar-gz'
    state: absent

- name: Create a file
  file:
    path: "{{ remote_tmp_dir }}/test-unarchive-tar-gz"
    state: touch

- name: Create a symlink to the file
  file:
    src: "{{ remote_tmp_dir }}/test-unarchive-tar-gz"
    path: "{{ remote_tmp_dir }}/link-to-unarchive-file"
    state: "link"

- name: test that unarchive fails when dest is a link to a file
  unarchive:
    src: "{{ remote_tmp_dir }}/test-unarchive.tar.gz"
    dest: "{{ remote_tmp_dir }}/link-to-unarchive-file"
    mode: "u+rwX,go+rX"
    remote_src: yes
  ignore_errors: True
  register: unarchive_12

- name: Assert that unarchive when dest is a file failed
  assert:
    that:
      - "unarchive_12.failed == true"

- name: remove our tar.gz unarchive destination
  file:
    path: '{{ remote_tmp_dir }}/test-unarchive-tar-gz'
    state: absent

- name: Create a destination dir
  file:
    path: "{{ remote_tmp_dir }}/test-symlink"
    state: directory

- name: Create files
  file:
    path: "{{ remote_tmp_dir }}/test-symlink/{{ item }}"
    state: touch
  loop:
    - file1
    - file2

- name: Create a symlink to the file
  file:
    path: "{{ remote_tmp_dir }}/test-symlink/link1"
    src: "{{ remote_tmp_dir }}/test-symlink/file1"
    state: link

- name: Create archive of symlink
  shell: tar czvf {{ remote_tmp_dir }}/link1.tar.gz link1 chdir={{ remote_tmp_dir }}/test-symlink

- name: Change target of symlink
  file:
    path: "{{ remote_tmp_dir }}/test-symlink/link1"
    src: "{{ remote_tmp_dir }}/test-symlink/file2"
    state: link

- name: Unarchive when symlink differs
  unarchive:
    src: "{{ remote_tmp_dir }}/link1.tar.gz"
    dest: "{{ remote_tmp_dir }}/test-symlink"
    remote_src: yes
  register: unarchive_13

- name: Assert that unarchive was performed
  assert:
    that:
      - unarchive_13.changed == true

- name: Unarchive when symlink is the same
  unarchive:
    src: "{{ remote_tmp_dir }}/link1.tar.gz"
    dest: "{{ remote_tmp_dir }}/test-symlink"
    remote_src: yes
  register: unarchive_13

- name: Assert that unarchive was not performed
  assert:
    that:
      - "unarchive_13.changed == false"

- name: Remove files
  file:
    path: "{{ remote_tmp_dir }}/test-symlink/{{ item }}"
    state: absent
  with_items:
    - file1
    - file2
    - link1
    - link1.tar.gz