| 1 |
# test code for the stat module |
| 2 |
# (c) 2014, James Tanner <[email protected]> |
| 3 |
|
| 4 |
# This file is part of Ansible |
| 5 |
# |
| 6 |
# Ansible is free software: you can redistribute it and/or modify |
| 7 |
# it under the terms of the GNU General Public License as published by |
| 8 |
# the Free Software Foundation, either version 3 of the License, or |
| 9 |
# (at your option) any later version. |
| 10 |
# |
| 11 |
# Ansible is distributed in the hope that it will be useful, |
| 12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
# GNU General Public License for more details. |
| 15 |
# |
| 16 |
# You should have received a copy of the GNU General Public License |
| 17 |
# along with Ansible. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
|
| 19 |
- name: make a new file |
| 20 |
copy: dest={{remote_tmp_dir}}/foo.txt mode=0644 content="hello world" |
| 21 |
|
| 22 |
- name: check stat of file |
| 23 |
stat: path={{remote_tmp_dir}}/foo.txt |
| 24 |
register: stat_result |
| 25 |
|
| 26 |
- debug: var=stat_result |
| 27 |
|
| 28 |
- assert: |
| 29 |
that: |
| 30 |
- "'changed' in stat_result" |
| 31 |
- "stat_result.changed == false" |
| 32 |
- "'stat' in stat_result" |
| 33 |
- "'atime' in stat_result.stat" |
| 34 |
- "'ctime' in stat_result.stat" |
| 35 |
- "'dev' in stat_result.stat" |
| 36 |
- "'exists' in stat_result.stat" |
| 37 |
- "'gid' in stat_result.stat" |
| 38 |
- "'inode' in stat_result.stat" |
| 39 |
- "'isblk' in stat_result.stat" |
| 40 |
- "'ischr' in stat_result.stat" |
| 41 |
- "'isdir' in stat_result.stat" |
| 42 |
- "'isfifo' in stat_result.stat" |
| 43 |
- "'isgid' in stat_result.stat" |
| 44 |
- "'isreg' in stat_result.stat" |
| 45 |
- "'issock' in stat_result.stat" |
| 46 |
- "'isuid' in stat_result.stat" |
| 47 |
- "'checksum' in stat_result.stat" |
| 48 |
- "stat_result.stat.checksum == '2aae6c35c94fcfb415dbe95f408b9ce91ee846ed'" |
| 49 |
- "'mode' in stat_result.stat" |
| 50 |
- "'mtime' in stat_result.stat" |
| 51 |
- "'nlink' in stat_result.stat" |
| 52 |
- "'pw_name' in stat_result.stat" |
| 53 |
- "'rgrp' in stat_result.stat" |
| 54 |
- "'roth' in stat_result.stat" |
| 55 |
- "'rusr' in stat_result.stat" |
| 56 |
- "'size' in stat_result.stat" |
| 57 |
- "'uid' in stat_result.stat" |
| 58 |
- "'wgrp' in stat_result.stat" |
| 59 |
- "'woth' in stat_result.stat" |
| 60 |
- "'wusr' in stat_result.stat" |
| 61 |
- "'xgrp' in stat_result.stat" |
| 62 |
- "'xoth' in stat_result.stat" |
| 63 |
- "'xusr' in stat_result.stat" |
| 64 |
- "'disk_usage_bytes' in stat_result.stat" |
| 65 |
|
| 66 |
- name: make a symlink |
| 67 |
file: |
| 68 |
src: "{{ remote_tmp_dir }}/foo.txt" |
| 69 |
path: "{{ remote_tmp_dir }}/foo-link" |
| 70 |
state: link |
| 71 |
|
| 72 |
- name: check stat of a symlink with follow off |
| 73 |
stat: |
| 74 |
path: "{{ remote_tmp_dir }}/foo-link" |
| 75 |
register: stat_result |
| 76 |
|
| 77 |
- debug: var=stat_result |
| 78 |
|
| 79 |
- assert: |
| 80 |
that: |
| 81 |
- "'changed' in stat_result" |
| 82 |
- "stat_result.changed == false" |
| 83 |
- "'stat' in stat_result" |
| 84 |
- "'atime' in stat_result.stat" |
| 85 |
- "'ctime' in stat_result.stat" |
| 86 |
- "'dev' in stat_result.stat" |
| 87 |
- "'exists' in stat_result.stat" |
| 88 |
- "'gid' in stat_result.stat" |
| 89 |
- "'inode' in stat_result.stat" |
| 90 |
- "'isblk' in stat_result.stat" |
| 91 |
- "'ischr' in stat_result.stat" |
| 92 |
- "'isdir' in stat_result.stat" |
| 93 |
- "'isfifo' in stat_result.stat" |
| 94 |
- "'isgid' in stat_result.stat" |
| 95 |
- "'isreg' in stat_result.stat" |
| 96 |
- "'issock' in stat_result.stat" |
| 97 |
- "'isuid' in stat_result.stat" |
| 98 |
- "'islnk' in stat_result.stat" |
| 99 |
- "'mode' in stat_result.stat" |
| 100 |
- "'mtime' in stat_result.stat" |
| 101 |
- "'nlink' in stat_result.stat" |
| 102 |
- "'pw_name' in stat_result.stat" |
| 103 |
- "'rgrp' in stat_result.stat" |
| 104 |
- "'roth' in stat_result.stat" |
| 105 |
- "'rusr' in stat_result.stat" |
| 106 |
- "'size' in stat_result.stat" |
| 107 |
- "'uid' in stat_result.stat" |
| 108 |
- "'wgrp' in stat_result.stat" |
| 109 |
- "'woth' in stat_result.stat" |
| 110 |
- "'wusr' in stat_result.stat" |
| 111 |
- "'xgrp' in stat_result.stat" |
| 112 |
- "'xoth' in stat_result.stat" |
| 113 |
- "'xusr' in stat_result.stat" |
| 114 |
|
| 115 |
- name: check stat of a symlink with follow on |
| 116 |
stat: |
| 117 |
path: "{{ remote_tmp_dir }}/foo-link" |
| 118 |
follow: True |
| 119 |
register: stat_result |
| 120 |
|
| 121 |
- debug: var=stat_result |
| 122 |
|
| 123 |
- assert: |
| 124 |
that: |
| 125 |
- "'changed' in stat_result" |
| 126 |
- "stat_result.changed == false" |
| 127 |
- "'stat' in stat_result" |
| 128 |
- "'atime' in stat_result.stat" |
| 129 |
- "'ctime' in stat_result.stat" |
| 130 |
- "'dev' in stat_result.stat" |
| 131 |
- "'exists' in stat_result.stat" |
| 132 |
- "'gid' in stat_result.stat" |
| 133 |
- "'inode' in stat_result.stat" |
| 134 |
- "'isblk' in stat_result.stat" |
| 135 |
- "'ischr' in stat_result.stat" |
| 136 |
- "'isdir' in stat_result.stat" |
| 137 |
- "'isfifo' in stat_result.stat" |
| 138 |
- "'isgid' in stat_result.stat" |
| 139 |
- "'isreg' in stat_result.stat" |
| 140 |
- "'issock' in stat_result.stat" |
| 141 |
- "'isuid' in stat_result.stat" |
| 142 |
- "'checksum' in stat_result.stat" |
| 143 |
- "stat_result.stat.checksum == '2aae6c35c94fcfb415dbe95f408b9ce91ee846ed'" |
| 144 |
- "'mode' in stat_result.stat" |
| 145 |
- "'mtime' in stat_result.stat" |
| 146 |
- "'nlink' in stat_result.stat" |
| 147 |
- "'pw_name' in stat_result.stat" |
| 148 |
- "'rgrp' in stat_result.stat" |
| 149 |
- "'roth' in stat_result.stat" |
| 150 |
- "'rusr' in stat_result.stat" |
| 151 |
- "'size' in stat_result.stat" |
| 152 |
- "'uid' in stat_result.stat" |
| 153 |
- "'wgrp' in stat_result.stat" |
| 154 |
- "'woth' in stat_result.stat" |
| 155 |
- "'wusr' in stat_result.stat" |
| 156 |
- "'xgrp' in stat_result.stat" |
| 157 |
- "'xoth' in stat_result.stat" |
| 158 |
- "'xusr' in stat_result.stat" |
| 159 |
|
| 160 |
- name: make a new file with colon in filename |
| 161 |
copy: |
| 162 |
dest: "{{ remote_tmp_dir }}/foo:bar.txt" |
| 163 |
mode: '0644' |
| 164 |
content: "hello world" |
| 165 |
|
| 166 |
- name: check stat of a file with colon in name |
| 167 |
stat: |
| 168 |
path: "{{ remote_tmp_dir }}/foo:bar.txt" |
| 169 |
follow: True |
| 170 |
register: stat_result |
| 171 |
|
| 172 |
- debug: |
| 173 |
var: stat_result |
| 174 |
|
| 175 |
- assert: |
| 176 |
that: |
| 177 |
- "'changed' in stat_result" |
| 178 |
- "stat_result.changed == false" |
| 179 |
- "stat_result.stat.mimetype == 'text/plain'" |
| 180 |
- "stat_result.stat.charset == 'us-ascii'" |
| 181 |
|
| 182 |
- name: check stat a file with get_selinux_context on |
| 183 |
stat: |
| 184 |
path: "{{ remote_tmp_dir }}/foo.txt" |
| 185 |
get_selinux_context: True |
| 186 |
register: stat_result |
| 187 |
|
| 188 |
- debug: var=stat_result |
| 189 |
|
| 190 |
- assert: |
| 191 |
that: |
| 192 |
- "'selinux_context' in stat_result.stat" |
| 193 |
|
| 194 |
- name: check stat a file with get_selinux_context off |
| 195 |
stat: |
| 196 |
path: "{{ remote_tmp_dir }}/foo.txt" |
| 197 |
get_selinux_context: False |
| 198 |
register: stat_result |
| 199 |
|
| 200 |
- debug: var=stat_result |
| 201 |
|
| 202 |
- assert: |
| 203 |
that: |
| 204 |
- "'selinux_context' not in stat_result.stat" |