summaryrefslogtreecommitdiffstats
path: root/test/integration/targets/parsing/roles/test_good_parsing/tasks/main.yml
blob: d225c0f9f90ce9545ba73b296000823d13d469c1 (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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# test code for the ping module
# (c) 2014, Michael DeHaan <michael@ansible.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/>.

# various tests of things that should not cause parsing problems

- set_fact:
    test_input: "a=1 a=2 a=3"

- set_fact:
    multi_line: |
      echo old
      echo mcdonald
      echo had
      echo a
      echo farm

- shell: echo "dog"
  register: result

- assert:
    that:
       result.cmd == 'echo "dog"'

- shell: echo 'dog'
  register: result

- assert:
    that:
       result.cmd == 'echo \'dog\''

- name: a quoted argument is not sent to the shell module as anything but a string parameter
  shell: echo 'dog' 'executable=/usr/bin/python'
  register: result

- debug: var=result.cmd

- assert:
    that:
       result.cmd == "echo 'dog' 'executable=/usr/bin/python'"

- name: it is valid to pass multiple key=value arguments because the shell doesn't check key=value arguments
  shell: echo quackquack=here quackquack=everywhere
  register: result

- assert:
    that:
      result.cmd == 'echo quackquack=here quackquack=everywhere'

- name: the same is true with quoting
  shell: echo "quackquack=here quackquack=everywhere"
  register: result

- assert:
    that:
      result.cmd == 'echo "quackquack=here quackquack=everywhere"'

- name: the same is true with quoting (B)
  shell: echo "quackquack=here" "quackquack=everywhere"
  register: result

- name: the same is true with quoting (C)
  shell: echo "quackquack=here" 'quackquack=everywhere'
  register: result

- name: the same is true with quoting (D)
  shell: echo "quackquack=here" 'quackquack=everywhere'
  register: result

- name: the same is true with quoting (E)
  shell: echo {{ test_input }}
  register: result

- assert:
     that:
        result.cmd == "echo a=1 a=2 a=3"

- name: more shell duplicates
  shell: echo foo=bar foo=bar
  register: result

- assert:
    that:
       result.cmd == "echo foo=bar foo=bar"

- name: raw duplicates, noop
  raw: env true foo=bar foo=bar

- name: multi-line inline shell commands (should use script module but hey) are a thing
  shell: "{{ multi_line }}"
  register: result

- debug: var=result

- assert:
    that:
       result.stdout_lines == [ 'old', 'mcdonald', 'had', 'a', 'farm' ]

- name: passing same arg to shell command is legit
  shell: echo foo --arg=a --arg=b
  failed_when: False # just catch the exit code, parse error is what I care about, but should register and compare result
  register: result

- assert:
    that:
       # command shouldn't end in spaces, amend test once fixed
       - result.cmd == "echo foo --arg=a --arg=b"

- name: test includes with params
  include: test_include.yml fact_name=include_params param="{{ test_input }}"

- name: assert the include set the correct fact for the param
  assert:
    that:
      - include_params == test_input

- name: test includes with quoted params
  include: test_include.yml fact_name=double_quoted_param param="this is a param with double quotes"

- name: assert the include set the correct fact for the double quoted param
  assert:
    that:
      - double_quoted_param == "this is a param with double quotes"

- name: test includes with single quoted params
  include: test_include.yml fact_name=single_quoted_param param='this is a param with single quotes'

- name: assert the include set the correct fact for the single quoted param
  assert:
    that:
      - single_quoted_param == "this is a param with single quotes"

- name: test includes with quoted params in complex args
  include: test_include.yml
  vars:
    fact_name: complex_param
    param: "this is a param in a complex arg with double quotes"

- name: assert the include set the correct fact for the params in complex args
  assert:
    that:
      - complex_param == "this is a param in a complex arg with double quotes"

- name: test variable module name
  action: "{{ variable_module_name }} msg='this should be debugged'"
  register: result

- name: assert the task with variable module name ran
  assert:
    that:
      - result.msg == "this should be debugged"

- name: test conditional includes
  include: test_include_conditional.yml
  when: false

- name: assert the nested include from test_include_conditional was not set
  assert:
    that:
      - nested_include_var is undefined

- name: test omit in complex args
  set_fact:
    foo: bar
    spam: "{{ omit }}"
    should_not_omit: "prefix{{ omit }}"

- assert:
    that:
      - foo == 'bar'
      - spam is undefined
      - should_not_omit is defined

- name: test omit in module args
  set_fact: >
    yo=whatsup
    eggs="{{ omit }}"
    default_omitted="{{ not_exists|default(omit) }}"
    should_not_omit_1="prefix{{ omit }}"
    should_not_omit_2="{{ omit }}suffix"
    should_not_omit_3="__omit_place_holder__afb6b9bc3d20bfeaa00a1b23a5930f89"

- assert:
    that:
      - yo == 'whatsup'
      - eggs is undefined
      - default_omitted is undefined
      - should_not_omit_1 is defined
      - should_not_omit_2 is defined
      - should_not_omit_3 == "__omit_place_holder__afb6b9bc3d20bfeaa00a1b23a5930f89"

- name: Ensure module names are stripped of extra spaces (local_action)
  local_action: set_fact     b="b"
  register: la_set_fact_b

- name: Ensure module names are stripped of extra spaces (action)
  action: set_fact     c="c"
  register: la_set_fact_c

- assert:
    that:
      - b == "b"
      - c == "c"