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

https://github.com/ajanthanm/ansible · YAML · 170 lines · 77 code · 41 blank · 52 comment · 0 complexity · 1b310d6d4ea935a9558e072e2a10f15f MD5 · raw file

  1. # Test code for the command and shell modules.
  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_dir_test={{output_dir}}/test_command_shell
  18. - name: make sure our testing sub-directory does not exist
  19. file: path="{{ output_dir_test }}" state=absent
  20. - name: create our testing sub-directory
  21. file: path="{{ output_dir_test }}" state=directory
  22. - name: prep our test script
  23. copy: src=test.sh dest="{{ output_dir_test }}" mode=0755
  24. - name: prep our test script
  25. copy: src=create_afile.sh dest="{{ output_dir_test }}" mode=0755
  26. - name: prep our test script
  27. copy: src=remove_afile.sh dest="{{ output_dir_test }}" mode=0755
  28. ##
  29. ## command
  30. ##
  31. - name: execute the test.sh script via command
  32. command: "{{output_dir_test | expanduser}}/test.sh"
  33. register: command_result0
  34. - name: assert that the script executed correctly
  35. assert:
  36. that:
  37. - "command_result0.rc == 0"
  38. - "command_result0.stderr == ''"
  39. - "command_result0.stdout == 'win'"
  40. # executable
  41. # FIXME doesn't have the expected stdout.
  42. #- name: execute the test.sh script with executable via command
  43. # command: "{{output_dir_test | expanduser}}/test.sh executable=/bin/bash"
  44. # register: command_result1
  45. #
  46. #- name: assert that the script executed correctly with command
  47. # assert:
  48. # that:
  49. # - "command_result1.rc == 0"
  50. # - "command_result1.stderr == ''"
  51. # - "command_result1.stdout == 'win'"
  52. # chdir
  53. - name: execute the test.sh script with chdir via command
  54. command: ./test.sh chdir="{{output_dir_test | expanduser}}"
  55. register: command_result2
  56. - name: assert that the script executed correctly with chdir
  57. assert:
  58. that:
  59. - "command_result2.rc == 0"
  60. - "command_result2.stderr == ''"
  61. - "command_result2.stdout == 'win'"
  62. # creates
  63. - name: verify that afile.txt is absent
  64. file: path={{output_dir_test}}/afile.txt state=absent
  65. - name: create afile.txt with create_afile.sh via command
  66. shell: "{{output_dir_test | expanduser}}/create_afile.sh {{output_dir_test | expanduser}}/afile.txt creates={{output_dir_test | expanduser}}/afile.txt"
  67. - name: verify that afile.txt is present
  68. file: path={{output_dir_test}}/afile.txt state=file
  69. # removes
  70. - name: remove afile.txt with remote_afile.sh via command
  71. shell: "{{output_dir_test | expanduser}}/remove_afile.sh {{output_dir_test | expanduser}}/afile.txt removes={{output_dir_test | expanduser}}/afile.txt"
  72. - name: verify that afile.txt is absent
  73. file: path={{output_dir_test}}/afile.txt state=absent
  74. register: command_result3
  75. - name: assert that the file was removed by the script
  76. assert:
  77. that:
  78. - "command_result3.changed != True"
  79. ##
  80. ## shell
  81. ##
  82. - name: execute the test.sh script
  83. shell: "{{output_dir_test | expanduser}}/test.sh"
  84. register: shell_result0
  85. - name: assert that the script executed correctly
  86. assert:
  87. that:
  88. - "shell_result0.rc == 0"
  89. - "shell_result0.stderr == ''"
  90. - "shell_result0.stdout == 'win'"
  91. # executable
  92. # FIXME doesn't pass the expected stdout
  93. #- name: execute the test.sh script
  94. # shell: "{{output_dir_test | expanduser}}/test.sh executable=/bin/bash"
  95. # register: shell_result1
  96. #
  97. #- name: assert that the shell executed correctly
  98. # assert:
  99. # that:
  100. # - "shell_result1.rc == 0"
  101. # - "shell_result1.stderr == ''"
  102. # - "shell_result1.stdout == 'win'"
  103. # chdir
  104. - name: execute the test.sh script with chdir
  105. shell: ./test.sh chdir="{{output_dir_test | expanduser}}"
  106. register: shell_result2
  107. - name: assert that the shell executed correctly with chdir
  108. assert:
  109. that:
  110. - "shell_result2.rc == 0"
  111. - "shell_result2.stderr == ''"
  112. - "shell_result2.stdout == 'win'"
  113. # creates
  114. - name: verify that afile.txt is absent
  115. file: path={{output_dir_test}}/afile.txt state=absent
  116. - name: execute the test.sh script with chdir
  117. shell: "{{output_dir_test | expanduser}}/test.sh > {{output_dir_test | expanduser}}/afile.txt creates={{output_dir_test | expanduser}}/afile.txt"
  118. - name: verify that afile.txt is present
  119. file: path={{output_dir_test}}/afile.txt state=file
  120. # removes
  121. - name: execute the test.sh script with chdir
  122. shell: rm {{output_dir_test | expanduser}}/afile.txt removes={{output_dir_test | expanduser}}/afile.txt
  123. - name: verify that afile.txt is absent
  124. file: path={{output_dir_test}}/afile.txt state=absent
  125. register: shell_result4
  126. - name: assert that the file was removed by the shell
  127. assert:
  128. that:
  129. - "shell_result4.changed == False"