Debian Codegraph @

test/integration/targets/raw/tasks/main.yml

raw
1 # Test code for the raw module.
2 # (c) 2017, 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 - set_fact: remote_tmp_dir_test={{remote_tmp_dir}}/test_command_raw
20
21 - name: make sure our testing sub-directory does not exist
22 file: path="{{ remote_tmp_dir_test }}" state=absent
23
24 - name: create our testing sub-directory
25 file: path="{{ remote_tmp_dir_test }}" state=directory
26
27 ##
28 ## raw
29 ##
30
31 - name: touch a file
32 raw: "touch {{remote_tmp_dir_test | expanduser}}/test.txt"
33 register: raw_result0
34 - debug: var=raw_result0
35 - stat:
36 path: "{{remote_tmp_dir_test | expanduser}}/test.txt"
37 register: raw_result0_stat
38 - debug: var=raw_result0_stat
39 - name: ensure proper results
40 assert:
41 that:
42 - 'raw_result0.changed is defined'
43 - 'raw_result0.rc is defined'
44 - 'raw_result0.stderr is defined'
45 - 'raw_result0.stdout is defined'
46 - 'raw_result0.stdout_lines is defined'
47 - 'raw_result0.rc == 0'
48 - 'raw_result0_stat.stat.size == 0'
49
50 - name: run a piped command
51 raw: "echo 'foo,bar,baz' | cut -d\\, -f2 | tr 'b' 'c'"
52 register: raw_result1
53 - debug: var=raw_result1
54 - name: ensure proper results
55 assert:
56 that:
57 - 'raw_result1.changed is defined'
58 - 'raw_result1.rc is defined'
59 - 'raw_result1.stderr is defined'
60 - 'raw_result1.stdout is defined'
61 - 'raw_result1.stdout_lines is defined'
62 - 'raw_result1.rc == 0'
63 - 'raw_result1.stdout_lines == ["car"]'
64
65 - name: get the path to bash
66 shell: which bash
67 register: bash_path
68 - name: run exmample non-posix command with bash
69 raw: "echo 'foobar' > {{remote_tmp_dir_test | expanduser}}/test.txt ; cat < {{remote_tmp_dir_test | expanduser}}/test.txt"
70 args:
71 executable: "{{ bash_path.stdout }}"
72 register: raw_result2
73 - debug: var=raw_result2
74 - name: ensure proper results
75 assert:
76 that:
77 - 'raw_result2.changed is defined'
78 - 'raw_result2.rc is defined'
79 - 'raw_result2.stderr is defined'
80 - 'raw_result2.stdout is defined'
81 - 'raw_result2.stdout_lines is defined'
82 - 'raw_result2.rc == 0'
83 - 'raw_result2.stdout_lines == ["foobar"]'
84 # the following five tests added to test https://github.com/ansible/ansible/pull/68315
85 - name: get the path to sh
86 shell: which sh
87 register: sh_path
88 - name: use sh
89 raw: echo $0
90 args:
91 executable: "{{ sh_path.stdout }}"
92 become: true
93 become_method: su
94 register: sh_output
95 - name: assert sh
96 assert:
97 that: "(sh_output.stdout | trim) == sh_path.stdout"
98 - name: use bash
99 raw: echo $0
100 args:
101 executable: "{{ bash_path.stdout }}"
102 become: true
103 become_method: su
104 register: bash_output
105 - name: assert bash
106 assert:
107 that: "(bash_output.stdout | trim) == bash_path.stdout"