summaryrefslogtreecommitdiffstats
path: root/test/integration/targets/raw/tasks/main.yml
blob: ce03c72aefd693cc24cd11fbaf945f3322fada26 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# Test code for the raw module.
# (c) 2017, James Tanner <tanner.jc@gmail.com>

# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible.  If not, see <http://www.gnu.org/licenses/>.

- set_fact: remote_tmp_dir_test={{remote_tmp_dir}}/test_command_raw

- name: make sure our testing sub-directory does not exist
  file: path="{{ remote_tmp_dir_test }}" state=absent

- name: create our testing sub-directory
  file: path="{{ remote_tmp_dir_test }}" state=directory

##
## raw
##

- name: touch a file
  raw: "touch {{remote_tmp_dir_test | expanduser}}/test.txt"
  register: raw_result0
- debug: var=raw_result0
- stat:
    path: "{{remote_tmp_dir_test | expanduser}}/test.txt"
  register: raw_result0_stat
- debug: var=raw_result0_stat
- name: ensure proper results
  assert:
      that:
          - 'raw_result0.changed is defined'
          - 'raw_result0.rc is defined'
          - 'raw_result0.stderr is defined'
          - 'raw_result0.stdout is defined'
          - 'raw_result0.stdout_lines is defined'
          - 'raw_result0.rc == 0'
          - 'raw_result0_stat.stat.size == 0'

- name: run a piped command
  raw: "echo 'foo,bar,baz' | cut -d\\, -f2 | tr 'b' 'c'"
  register: raw_result1
- debug: var=raw_result1
- name: ensure proper results
  assert:
      that:
          - 'raw_result1.changed is defined'
          - 'raw_result1.rc is defined'
          - 'raw_result1.stderr is defined'
          - 'raw_result1.stdout is defined'
          - 'raw_result1.stdout_lines is defined'
          - 'raw_result1.rc == 0'
          - 'raw_result1.stdout_lines == ["car"]'

- name: get the path to bash
  shell: which bash
  register: bash_path
- name: run exmample non-posix command with bash
  raw: "echo 'foobar' > {{remote_tmp_dir_test | expanduser}}/test.txt ; cat < {{remote_tmp_dir_test | expanduser}}/test.txt"
  args:
      executable: "{{ bash_path.stdout }}"
  register: raw_result2
- debug: var=raw_result2
- name: ensure proper results
  assert:
      that:
          - 'raw_result2.changed is defined'
          - 'raw_result2.rc is defined'
          - 'raw_result2.stderr is defined'
          - 'raw_result2.stdout is defined'
          - 'raw_result2.stdout_lines is defined'
          - 'raw_result2.rc == 0'
          - 'raw_result2.stdout_lines == ["foobar"]'
# the following five tests added to test https://github.com/ansible/ansible/pull/68315
- name: get the path to sh
  shell: which sh
  register: sh_path
- name: use sh
  raw: echo $0
  args:
    executable: "{{ sh_path.stdout }}"
  become: true
  become_method: su
  register: sh_output
- name: assert sh
  assert:
    that: "(sh_output.stdout | trim) == sh_path.stdout"
- name: use bash
  raw: echo $0
  args:
    executable: "{{ bash_path.stdout }}"
  become: true
  become_method: su
  register: bash_output
- name: assert bash
  assert:
    that: "(bash_output.stdout | trim) == bash_path.stdout"