| 1 |
- hosts: localhost |
| 2 |
gather_facts: no |
| 3 |
environment: |
| 4 |
ANSIBLE_LIBRARY: "{{ playbook_dir }}/library" |
| 5 |
ANSIBLE_NOCOLOR: 1 |
| 6 |
ANSIBLE_DEPRECATION_WARNINGS: 1 |
| 7 |
ANSIBLE_DOC_FRAGMENT_PLUGINS: "{{ playbook_dir }}/doc_fragments" |
| 8 |
vars: |
| 9 |
# avoid header that has full path and won't work across random paths for tests |
| 10 |
actual_output_clean: '{{ actual_output.splitlines()[1:] }}' |
| 11 |
expected_output_clean: '{{ expected_output.splitlines()[1:] }}' |
| 12 |
tasks: |
| 13 |
- name: module with missing description return docs |
| 14 |
command: ansible-doc test_docs_missing_description |
| 15 |
register: result |
| 16 |
ignore_errors: true |
| 17 |
|
| 18 |
- assert: |
| 19 |
that: |
| 20 |
- result is failed |
| 21 |
- | |
| 22 |
"Unable to retrieve documentation from 'test_docs_missing_description': All (sub-)options and return values must have a 'description' field" |
| 23 |
in result.stderr |
| 24 |
|
| 25 |
- name: module with suboptions (avoid first line as it has full path) |
| 26 |
shell: ansible-doc test_docs_suboptions| tail -n +3 |
| 27 |
register: result |
| 28 |
ignore_errors: true |
| 29 |
|
| 30 |
- assert: |
| 31 |
that: |
| 32 |
- result is succeeded |
| 33 |
- actual_output_clean == expected_output_clean |
| 34 |
vars: |
| 35 |
actual_output: "{{ result.stdout }}" |
| 36 |
expected_output: "{{ lookup('file', 'test_docs_suboptions.output') }}" |
| 37 |
|
| 38 |
- name: module with return docs |
| 39 |
shell: ansible-doc test_docs_returns| tail -n +3 |
| 40 |
register: result |
| 41 |
ignore_errors: true |
| 42 |
|
| 43 |
- assert: |
| 44 |
that: |
| 45 |
- result is succeeded |
| 46 |
- actual_output_clean == expected_output_clean |
| 47 |
vars: |
| 48 |
actual_output: "{{ result.stdout }}" |
| 49 |
expected_output: "{{ lookup('file', 'test_docs_returns.output') }}" |
| 50 |
|
| 51 |
- name: module with broken return docs |
| 52 |
command: ansible-doc test_docs_returns_broken |
| 53 |
register: result |
| 54 |
ignore_errors: true |
| 55 |
|
| 56 |
- assert: |
| 57 |
that: |
| 58 |
- result is failed |
| 59 |
- '"module test_docs_returns_broken Missing documentation (or could not parse documentation)" in result.stderr' |
| 60 |
|
| 61 |
- name: module with return docs with fragments |
| 62 |
command: ansible-doc test_docs_return_fragments |
| 63 |
register: result |
| 64 |
ignore_errors: true |
| 65 |
|
| 66 |
- name: test fragments work |
| 67 |
assert: |
| 68 |
that: |
| 69 |
- result is success |
| 70 |
- "'z_last' in actual_output" |
| 71 |
- "'y_notlast' in actual_output" |
| 72 |
- actual_output_clean == expected_output_clean |
| 73 |
vars: |
| 74 |
actual_output: "{{ result.stdout }}" |
| 75 |
expected_output: "{{ lookup('file', 'test_docs_return_fragments.output') }}" |
| 76 |
|
| 77 |
- name: non-existent module |
| 78 |
command: ansible-doc test_does_not_exist |
| 79 |
register: result |
| 80 |
- assert: |
| 81 |
that: |
| 82 |
- '"test_does_not_exist was not found" in result.stderr' |
| 83 |
|
| 84 |
- name: documented module |
| 85 |
command: ansible-doc test_docs |
| 86 |
register: result |
| 87 |
- assert: |
| 88 |
that: |
| 89 |
- '"WARNING" not in result.stderr' |
| 90 |
- '"test_docs" in result.stdout' |
| 91 |
- '"AUTHOR: Ansible Core Team" in result.stdout' |
| 92 |
|
| 93 |
- name: documented module without metadata |
| 94 |
command: ansible-doc test_docs_no_metadata |
| 95 |
register: result |
| 96 |
- assert: |
| 97 |
that: |
| 98 |
- '"WARNING" not in result.stderr' |
| 99 |
- '"test_docs_no_metadata " in result.stdout' |
| 100 |
- '"AUTHOR: Ansible Core Team" in result.stdout' |
| 101 |
|
| 102 |
- name: documented module with no status in metadata |
| 103 |
command: ansible-doc test_docs_no_status |
| 104 |
register: result |
| 105 |
- assert: |
| 106 |
that: |
| 107 |
- '"WARNING" not in result.stderr' |
| 108 |
- '"test_docs_no_status " in result.stdout' |
| 109 |
- '"AUTHOR: Ansible Core Team" in result.stdout' |
| 110 |
|
| 111 |
- name: documented module with non-iterable status in metadata |
| 112 |
command: ansible-doc test_docs_non_iterable_status |
| 113 |
register: result |
| 114 |
- assert: |
| 115 |
that: |
| 116 |
- '"WARNING" not in result.stderr' |
| 117 |
- '"test_docs_non_iterable_status " in result.stdout' |
| 118 |
- '"AUTHOR: Ansible Core Team" in result.stdout' |
| 119 |
|
| 120 |
- name: documented module with removed status |
| 121 |
command: ansible-doc test_docs_removed_status |
| 122 |
register: result |
| 123 |
|
| 124 |
- assert: |
| 125 |
that: |
| 126 |
- '"WARNING" not in result.stderr' |
| 127 |
- '"test_docs_removed_status " in result.stdout' |
| 128 |
- '"AUTHOR: Ansible Core Team" in result.stdout' |
| 129 |
|
| 130 |
- name: empty module |
| 131 |
command: ansible-doc test_empty |
| 132 |
register: result |
| 133 |
ignore_errors: true |
| 134 |
|
| 135 |
- assert: |
| 136 |
that: |
| 137 |
- result is failed |
| 138 |
|
| 139 |
- name: module with no documentation |
| 140 |
command: ansible-doc test_no_docs |
| 141 |
register: result |
| 142 |
ignore_errors: true |
| 143 |
|
| 144 |
- assert: |
| 145 |
that: |
| 146 |
- result is failed |
| 147 |
|
| 148 |
- name: deprecated module with both removed date and version (date should get precedence) |
| 149 |
command: ansible-doc test_docs_removed_precedence |
| 150 |
register: result |
| 151 |
|
| 152 |
- assert: |
| 153 |
that: |
| 154 |
- '"DEPRECATED" in result.stdout' |
| 155 |
- '"Reason: Updated module released with more functionality" in result.stdout' |
| 156 |
- '"Will be removed in a release after 2022-06-01" in result.stdout' |
| 157 |
- '"Alternatives: new_module" in result.stdout' |
| 158 |
|
| 159 |
- name: documented module with YAML anchors |
| 160 |
shell: ansible-doc test_docs_yaml_anchors |tail -n +3 |
| 161 |
register: result |
| 162 |
|
| 163 |
- set_fact: |
| 164 |
actual_output: >- |
| 165 |
{{ result.stdout | regex_replace('^(> [A-Z_]+ +\().+library/([a-z_]+.py)\)$', '\1library/\2)', multiline=true) }} |
| 166 |
expected_output: "{{ lookup('file', 'test_docs_yaml_anchors.output') }}" |
| 167 |
|
| 168 |
- assert: |
| 169 |
that: |
| 170 |
- actual_output == expected_output |
| 171 |
- actual_output_clean == expected_output_clean |
| 172 |
|
| 173 |
- name: ensure 'donothing' adjacent filter is loaded |
| 174 |
assert: |
| 175 |
that: |
| 176 |
- "'x' == ('x'|donothing)" |
| 177 |
|
| 178 |
- name: docs for deprecated plugin |
| 179 |
command: ansible-doc deprecated_with_docs -t lookup --playbook-dir ./ |
| 180 |
register: result |
| 181 |
|
| 182 |
- assert: |
| 183 |
that: |
| 184 |
- '"[WARNING]" in result.stderr' |
| 185 |
- '"[DEPRECATION WARNING]" in result.stderr' |
| 186 |
- '"deprecated_with_docs " in result.stdout' |
| 187 |
- '"AUTHOR: Ansible Core Team" in result.stdout' |
| 188 |
|
| 189 |
- name: adjacent docs for deprecated plugin |
| 190 |
command: ansible-doc deprecated_with_adj_docs -t lookup --playbook-dir ./ |
| 191 |
register: result |
| 192 |
|
| 193 |
- assert: |
| 194 |
that: |
| 195 |
- '"[WARNING]" in result.stderr' |
| 196 |
- '"[DEPRECATION WARNING]" in result.stderr' |
| 197 |
- '"deprecated_with_adj_docs " in result.stdout' |
| 198 |
- '"AUTHOR: Ansible Core Team" in result.stdout' |
| 199 |
|
| 200 |
- name: Handle plugin docs |
| 201 |
debug: |
| 202 |
msg: "{{ lookup('broken_docs') }}" |
| 203 |
register: r |
| 204 |
ignore_errors: yes |
| 205 |
|
| 206 |
- assert: |
| 207 |
that: |
| 208 |
- "'plugin broken_docs has malformed documentation' in r.msg" |
| 209 |
|
| 210 |
- name: check ansible._protomatter excluded from output by default |
| 211 |
command: ansible-doc -t filter --list |
| 212 |
register: result |
| 213 |
|
| 214 |
- assert: |
| 215 |
that: |
| 216 |
- result.stdout_lines | select("match", "^ansible\\._protomatter\\.") | length == 0 |
| 217 |
|
| 218 |
- name: check ansible._protomatter is shown when requested |
| 219 |
command: ansible-doc ansible._protomatter -t filter --list |
| 220 |
register: result |
| 221 |
|
| 222 |
- assert: |
| 223 |
that: |
| 224 |
- result.stdout_lines | select("match", "^ansible\\._protomatter\\.") | length == result.stdout_lines | length |
| 225 |
|
| 226 |
- name: List all filter plugins without any filter |
| 227 |
command: ansible-doc -t filter --list --json |
| 228 |
register: filter_list_all_raw |
| 229 |
|
| 230 |
- set_fact: |
| 231 |
filter_list_all: "{{ filter_list_all_raw.stdout | from_json }}" |
| 232 |
|
| 233 |
- name: Check Jinja2 filters have a short description on list without any filter |
| 234 |
assert: |
| 235 |
that: |
| 236 |
- filter_list_all['ansible.builtin.default'] is contains("the passed default value") |
| 237 |
- filter_list_all['ansible.builtin.sum'] is contains("sum of a sequence") |
| 238 |
|
| 239 |
- name: List only ansible.builtin filter plugins |
| 240 |
command: ansible-doc ansible.builtin -t filter --list --json |
| 241 |
register: filter_list_builtin_raw |
| 242 |
|
| 243 |
- set_fact: |
| 244 |
filter_list_builtin: "{{ filter_list_builtin_raw.stdout | from_json }}" |
| 245 |
|
| 246 |
- name: Check Jinja2 filters have a short description on list with builtin filter |
| 247 |
assert: |
| 248 |
that: |
| 249 |
- filter_list_builtin['ansible.builtin.default'] is contains("the passed default value") |
| 250 |
- filter_list_builtin['ansible.builtin.sum'] is contains("sum of a sequence") |
| 251 |
|
| 252 |
- name: List only ansible.builtin filter plugin files |
| 253 |
command: ansible-doc ansible.builtin -t filter --list_files |
| 254 |
register: filter_list_builtin_files |
| 255 |
|
| 256 |
- name: Verify files for Jinja2 filters |
| 257 |
assert: |
| 258 |
that: |
| 259 |
- filter_list_builtin_files.stdout_lines | select("match", "^ansible\\.builtin\\.default\\s+.*/core\\.py") | length == 1 |
| 260 |
- filter_list_builtin_files.stdout_lines | select("match", "^ansible\\.builtin\\.sum\\s+None") | length == 1 |
| 261 |
|
| 262 |
- name: Get jinja2 filter docs shadowed by Ansible |
| 263 |
command: ansible-doc ansible.builtin.default -t filter |
| 264 |
register: filter_jinja2_default |
| 265 |
|
| 266 |
- name: Assert jinja2 filter docs shadowed by Ansible |
| 267 |
assert: |
| 268 |
that: |
| 269 |
- filter_jinja2_default.stdout is search("\\s+FILTER ansible.builtin.default\\s+") |
| 270 |
- filter_jinja2_default.stdout is search("the Jinja builtin filter plugin 'default'") |
| 271 |
- filter_jinja2_default.stdout is search("the passed default value") |
| 272 |
- filter_jinja2_default.stdout is search("https://jinja\\.palletsprojects\\.com/.*") |
| 273 |
|
| 274 |
- name: Get jinja2 filter docs not shadowed by Ansible |
| 275 |
command: ansible-doc ansible.builtin.sum -t filter |
| 276 |
register: filter_jinja2_sum |
| 277 |
|
| 278 |
- name: Assert jinja2 filter docs not shadowed by Ansible |
| 279 |
assert: |
| 280 |
that: |
| 281 |
- filter_jinja2_sum.stdout is search("\\s+FILTER ansible.builtin.sum\\s+") |
| 282 |
- filter_jinja2_sum.stdout is search("the Jinja builtin filter plugin 'sum'") |
| 283 |
- filter_jinja2_sum.stdout is search("sum of a sequence") |
| 284 |
- filter_jinja2_sum.stdout is search("https://jinja\\.palletsprojects\\.com/.*") |
| 285 |
|
| 286 |
- name: List all test plugins without any filter |
| 287 |
command: ansible-doc -t test --list --json |
| 288 |
register: test_list_all_raw |
| 289 |
|
| 290 |
- set_fact: |
| 291 |
test_list_all: "{{ test_list_all_raw.stdout | from_json }}" |
| 292 |
|
| 293 |
- name: Check Jinja2 tests have a short description on list without any filter |
| 294 |
assert: |
| 295 |
that: |
| 296 |
- test_list_all['ansible.builtin.number'] is contains("is a number") |
| 297 |
|
| 298 |
- name: List only ansible.builtin test plugins |
| 299 |
command: ansible-doc ansible.builtin -t test --list --json |
| 300 |
register: test_list_builtin_raw |
| 301 |
|
| 302 |
- set_fact: |
| 303 |
test_list_builtin: "{{ test_list_builtin_raw.stdout | from_json }}" |
| 304 |
|
| 305 |
- name: Check Jinja2 tests have a short description on list with builtin tests |
| 306 |
assert: |
| 307 |
that: |
| 308 |
- test_list_builtin['ansible.builtin.number'] is contains("is a number") |
| 309 |
|
| 310 |
- name: List only ansible.builtin test plugin files |
| 311 |
command: ansible-doc ansible.builtin -t test --list_files |
| 312 |
register: test_list_builtin_files |
| 313 |
|
| 314 |
- name: Verify files for Jinja2 filters |
| 315 |
assert: |
| 316 |
that: |
| 317 |
- test_list_builtin_files.stdout_lines | select("match", "^ansible\\.builtin\\.number\\s+None") | length == 1 |
| 318 |
|
| 319 |
- name: Get jinja2 test docs |
| 320 |
command: ansible-doc ansible.builtin.number -t test |
| 321 |
register: test_jinja2_number |
| 322 |
|
| 323 |
- name: Assert jinja2 test docs |
| 324 |
assert: |
| 325 |
that: |
| 326 |
- test_jinja2_number.stdout is search("\\s+TEST ansible.builtin.number\\s+") |
| 327 |
- test_jinja2_number.stdout is search("the Jinja builtin test plugin 'number'") |
| 328 |
- test_jinja2_number.stdout is contains("is a number") |
| 329 |
- test_jinja2_number.stdout is search("https://jinja\\.palletsprojects\\.com/.*") |
| 330 |
|
| 331 |
- name: Get jinja2 test docs for an unqualified builtin |
| 332 |
command: ansible-doc number -t test |
| 333 |
register: test_jinja2_number_short |
| 334 |
|
| 335 |
- name: Assert jinja2 test docs |
| 336 |
assert: |
| 337 |
that: |
| 338 |
- test_jinja2_number_short.stdout is search("\\s+TEST ansible.builtin.number\\s+") |
| 339 |
- test_jinja2_number_short.stdout is search("the Jinja builtin test plugin 'number'") |
| 340 |
- test_jinja2_number_short.stdout is contains("is a number") |
| 341 |
- test_jinja2_number_short.stdout is search("https://jinja\\.palletsprojects\\.com/.*") |