PageRenderTime 50ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/test/integration/roles/test_win_file/tasks/main.yml

https://gitlab.com/18runt88/ansible
YAML | 421 lines | 82 code | 56 blank | 283 comment | 0 complexity | 5295ea8d0b2a78fbd1eedabf6f00ba4b MD5 | raw file
  1. # Test code for the file module.
  2. # (c) 2014, Richard Isaacson <richard.c.isaacson@gmail.com>
  3. # This file is part of Ansible
  4. #
  5. # Ansible is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # Ansible is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with Ansible. If not, see <http://www.gnu.org/licenses/>.
  17. - set_fact: output_file={{win_output_dir}}\\foo.txt
  18. - name: prep with a basic win copy
  19. win_copy: src=foo.txt dest={{output_file}}
  20. - name: verify that we are checking a file and it is present
  21. win_file: path={{output_file}} state=file
  22. register: file_result
  23. - name: verify that the file was marked as changed
  24. assert:
  25. that:
  26. - "file_result.changed == false"
  27. # - "file_result.state == 'file'"
  28. - name: verify that we are checking an absent file
  29. win_file: path={{win_output_dir}}\bar.txt state=absent
  30. register: file2_result
  31. - name: verify that the file was marked as changed
  32. assert:
  33. that:
  34. - "file2_result.changed == false"
  35. # - "file2_result.state == 'absent'"
  36. - name: verify we can touch a file
  37. win_file: path={{win_output_dir}}\baz.txt state=touch
  38. register: file3_result
  39. - name: verify that the file was marked as changed
  40. assert:
  41. that:
  42. - "file3_result.changed == true"
  43. # - "file3_result.state == 'file'"
  44. # - "file3_result.mode == '0644'"
  45. #- name: change file mode
  46. # win_file: path={{win_output_dir}}/baz.txt mode=0600
  47. # register: file4_result
  48. #- name: verify that the file was marked as changed
  49. # assert:
  50. # that:
  51. # - "file4_result.changed == true"
  52. # - "file4_result.mode == '0600'"
  53. #
  54. #- name: change ownership and group
  55. # win_file: path={{win_output_dir}}/baz.txt owner=1234 group=1234
  56. #
  57. #- name: setup a tmp-like directory for ownership test
  58. # win_file: path=/tmp/worldwritable mode=1777 state=directory
  59. #- name: Ask to create a file without enough perms to change ownership
  60. # win_file: path=/tmp/worldwritable/baz.txt state=touch owner=root
  61. # sudo: yes
  62. # sudo_user: nobody
  63. # register: chown_result
  64. # ignore_errors: True
  65. #- name: Ask whether the new file exists
  66. # win_stat: path=/tmp/worldwritable/baz.txt
  67. # register: file_exists_result
  68. #- name: Verify that the file doesn't exist on failure
  69. # assert:
  70. # that:
  71. # - "chown_result.failed == True"
  72. # - "file_exists_result.stat.exists == False"
  73. #
  74. - name: clean up
  75. win_file: path=/tmp/worldwritable state=absent
  76. #- name: create soft link to file
  77. # win_file: src={{output_file}} dest={{win_output_dir}}/soft.txt state=link
  78. # register: file5_result
  79. #- name: verify that the file was marked as changed
  80. # assert:
  81. # that:
  82. # - "file5_result.changed == true"
  83. #
  84. #- name: create hard link to file
  85. # win_file: src={{output_file}} dest={{win_output_dir}}/hard.txt state=hard
  86. # register: file6_result
  87. #
  88. #- name: verify that the file was marked as changed
  89. # assert:
  90. # that:
  91. # - "file6_result.changed == true"
  92. #
  93. - name: create a directory
  94. win_file: path={{win_output_dir}}\foobar state=directory
  95. register: file7_result
  96. - debug: var=file7_result
  97. - name: verify that the file was marked as changed
  98. assert:
  99. that:
  100. - "file7_result.changed == true"
  101. # - "file7_result.state == 'directory'"
  102. # windows and selinux unlikely to ever mix, removing these tests:
  103. #- name: determine if selinux is installed
  104. # shell: which getenforce || exit 0
  105. # register: selinux_installed
  106. #- name: determine if selinux is enabled
  107. # shell: getenforce
  108. # register: selinux_enabled
  109. # when: selinux_installed.stdout != ""
  110. # ignore_errors: true
  111. #- name: decide to include or not include selinux tests
  112. # include: selinux_tests.yml
  113. # when: selinux_installed.stdout != "" and selinux_enabled.stdout != "Disabled"
  114. - name: remote directory foobar
  115. win_file: path={{win_output_dir}}\foobar state=absent
  116. - name: remove file foo.txt
  117. win_file: path={{win_output_dir}}\foo.txt state=absent
  118. - name: remove file bar.txt
  119. win_file: path={{win_output_dir}}\foo.txt state=absent
  120. - name: remove file baz.txt
  121. win_file: path={{win_output_dir}}\foo.txt state=absent
  122. - name: win copy directory structure over
  123. win_copy: src=foobar dest={{win_output_dir}}
  124. - name: remove directory foobar
  125. win_file: path={{win_output_dir}}\foobar state=absent
  126. register: file14_result
  127. - debug: var=file14_result
  128. - name: verify that the directory was removed
  129. assert:
  130. that:
  131. - 'file14_result.changed == true'
  132. # - 'file14_result.state == "absent"'
  133. - name: create a test sub-directory
  134. win_file: dest={{win_output_dir}}/sub1 state=directory
  135. register: file15_result
  136. - name: verify that the new directory was created
  137. assert:
  138. that:
  139. - 'file15_result.changed == true'
  140. # - 'file15_result.state == "directory"'
  141. - name: create test files in the sub-directory
  142. win_file: dest={{win_output_dir}}/sub1/{{item}} state=touch
  143. with_items:
  144. - file1
  145. - file2
  146. - file3
  147. register: file16_result
  148. - name: verify the files were created
  149. assert:
  150. that:
  151. - 'item.changed == true'
  152. # - 'item.state == "file"'
  153. with_items: file16_result.results
  154. #- name: try to force the sub-directory to a link
  155. # win_file: src={{win_output_dir}}/testing dest={{win_output_dir}}/sub1 state=link force=yes
  156. # register: file17_result
  157. # ignore_errors: true
  158. #- name: verify the directory was not replaced with a link
  159. # assert:
  160. # that:
  161. # - 'file17_result.failed == true'
  162. # - 'file17_result.state == "directory"'
  163. #- name: create soft link to directory using absolute path
  164. # win_file: src=/ dest={{win_output_dir}}/root state=link
  165. # register: file18_result
  166. #
  167. #- name: verify that the result was marked as changed
  168. # assert:
  169. # that:
  170. # - "file18_result.changed == true"
  171. #
  172. - name: create another test sub-directory
  173. win_file: dest={{win_output_dir}}/sub2 state=directory
  174. register: file19_result
  175. - name: verify that the new directory was created
  176. assert:
  177. that:
  178. - 'file19_result.changed == true'
  179. # - 'file19_result.state == "directory"'
  180. #- name: create soft link to relative file
  181. # win_file: src=../sub1/file1 dest={{win_output_dir}}/sub2/link1 state=link
  182. # register: file20_result
  183. #
  184. #- name: verify that the result was marked as changed
  185. # assert:
  186. # that:
  187. # - "file20_result.changed == true"
  188. #- name: create soft link to relative directory
  189. # win_file: src=sub1 dest={{win_output_dir}}/sub1-link state=link
  190. # register: file21_result
  191. #
  192. #- name: verify that the result was marked as changed
  193. # assert:
  194. # that:
  195. # - "file21_result.changed == true"
  196. #
  197. #- name: test file creation with symbolic mode
  198. # win_file: dest={{win_output_dir}}/test_symbolic state=touch mode=u=rwx,g=rwx,o=rwx
  199. # register: result
  200. #
  201. #- name: assert file mode
  202. # assert:
  203. # that:
  204. # - result.mode == '0777'
  205. #- name: modify symbolic mode for all
  206. # win_file: dest={{win_output_dir}}/test_symbolic state=touch mode=a=r
  207. # register: result
  208. #
  209. #- name: assert file mode
  210. # assert:
  211. # that:
  212. # - result.mode == '0444'
  213. #- name: modify symbolic mode for owner
  214. # win_file: dest={{win_output_dir}}/test_symbolic state=touch mode=u+w
  215. # register: result
  216. #
  217. #- name: assert file mode
  218. # assert:
  219. # that:
  220. # - result.mode == '0644'
  221. #- name: modify symbolic mode for group
  222. # win_file: dest={{win_output_dir}}/test_symbolic state=touch mode=g+w
  223. # register: result
  224. #
  225. #- name: assert file mode
  226. # assert:
  227. # that:
  228. # - result.mode == '0664'
  229. #
  230. #- name: modify symbolic mode for world
  231. # win_file: dest={{win_output_dir}}/test_symbolic state=touch mode=o+w
  232. # register: result
  233. #
  234. #- name: assert file mode
  235. # assert:
  236. # that:
  237. # - result.mode == '0666'
  238. #
  239. #- name: modify symbolic mode for owner
  240. # win_file: dest={{win_output_dir}}/test_symbolic state=touch mode=u+x
  241. # register: result
  242. #
  243. #- name: assert file mode
  244. # assert:
  245. # that:
  246. # - result.mode == '0766'
  247. ##
  248. #- name: modify symbolic mode for group
  249. # win_file: dest={{win_output_dir}}/test_symbolic state=touch mode=g+x
  250. # register: result
  251. #
  252. #- name: assert file mode
  253. # assert:
  254. # that:
  255. # - result.mode == '0776'
  256. #
  257. #- name: modify symbolic mode for world
  258. # win_file: dest={{win_output_dir}}/test_symbolic state=touch mode=o+x
  259. # register: result
  260. #
  261. #- name: assert file mode
  262. # assert:
  263. # that:
  264. # - result.mode == '0777'
  265. #- name: remove symbolic mode for world
  266. # win_file: dest={{win_output_dir}}/test_symbolic state=touch mode=o-wx
  267. # register: result
  268. #
  269. #- name: assert file mode
  270. # assert:
  271. # that:
  272. # - result.mode == '0774'
  273. #
  274. #- name: remove symbolic mode for group
  275. # win_file: dest={{win_output_dir}}/test_symbolic state=touch mode=g-wx
  276. # register: result
  277. #
  278. #- name: assert file mode
  279. ### assert:
  280. # that:
  281. # - result.mode == '0744'
  282. #- name: remove symbolic mode for owner
  283. # win_file: dest={{win_output_dir}}/test_symbolic state=touch mode=u-wx
  284. # register: result
  285. #- name: assert file mode
  286. # assert:
  287. # that:
  288. # - result.mode == '0444'
  289. #
  290. #- name: set sticky bit with symbolic mode
  291. # win_file: dest={{win_output_dir}}/test_symbolic state=touch mode=o+t
  292. # register: result
  293. #- name: assert file mode
  294. # assert:
  295. # that:
  296. # - result.mode == '01444'
  297. #
  298. #- name: remove sticky bit with symbolic mode
  299. # win_file: dest={{win_output_dir}}/test_symbolic state=touch mode=o-t
  300. # register: result
  301. #
  302. #- name: assert file mode
  303. # assert:
  304. # that:
  305. # - result.mode == '0444'
  306. #- name: add setgid with symbolic mode
  307. # win_file: dest={{win_output_dir}}/test_symbolic state=touch mode=g+s
  308. # register: result
  309. #
  310. #- name: assert file mode
  311. # assert:
  312. # that:
  313. # - result.mode == '02444'
  314. #
  315. #- name: remove setgid with symbolic mode
  316. # win_file: dest={{win_output_dir}}/test_symbolic state=touch mode=g-s
  317. # register: result
  318. #
  319. #- name: assert file mode
  320. # assert:
  321. # that:
  322. # - result.mode == '0444'
  323. #- name: add setuid with symbolic mode
  324. # win_file: dest={{win_output_dir}}/test_symbolic state=touch mode=u+s
  325. # register: result
  326. #
  327. #- name: assert file mode
  328. # assert:
  329. # that:
  330. # - result.mode == '04444'
  331. #- name: remove setuid with symbolic mode
  332. # win_file: dest={{win_output_dir}}/test_symbolic state=touch mode=u-s
  333. # register: result
  334. #
  335. #- name: assert file mode
  336. # assert:
  337. # that:
  338. # - result.mode == '0444'
  339. # test the file module using follow=yes, so that the target of a
  340. # symlink is modified, rather than the link itself
  341. #- name: create a test file
  342. # win_copy: dest={{win_output_dir}}\test_follow content="this is a test file\n" mode=0666
  343. #- name: create a symlink to the test file
  344. # win_file: path={{win_output_dir}}\test_follow_link src="./test_follow" state=link
  345. #
  346. #- name: modify the permissions on the link using follow=yes
  347. # win_file: path={{win_output_dir}}\test_follow_link mode=0644 follow=yes
  348. # register: result
  349. #- name: assert that the chmod worked
  350. # assert:
  351. # that:
  352. # - result.changed
  353. #
  354. #- name: stat the link target
  355. # win_stat: path={{win_output_dir}}/test_follow
  356. # register: result
  357. #
  358. #- name: assert that the link target was modified correctly
  359. # assert:
  360. # that:
  361. ## - result.stat.mode == '0644'
  362. - name: clean up sub1
  363. win_file: path={{win_output_dir}}/sub1 state=absent
  364. - name: clean up sub2
  365. win_file: path={{win_output_dir}}/sub2 state=absent