PageRenderTime 26ms CodeModel.GetById 14ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

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