mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Helpers removed.
This commit is contained in:
parent
08a2f8e9a6
commit
45885da976
16 changed files with 0 additions and 854 deletions
|
@ -1,51 +0,0 @@
|
||||||
<!--
|
|
||||||
Copyright (c) Ansible Project
|
|
||||||
GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
||||||
SPDX-License-Identifier: GPL-3.0-or-later
|
|
||||||
-->
|
|
||||||
|
|
||||||
# Docs helper. Create RST file.
|
|
||||||
|
|
||||||
The playbook `playbook.yml` writes a RST file that can be used in
|
|
||||||
docs/docsite/rst. The usage of this helper is recommended but not
|
|
||||||
mandatory. You can stop reading here and update the RST file manually
|
|
||||||
if you don't want to use this helper.
|
|
||||||
|
|
||||||
## Run the playbook
|
|
||||||
|
|
||||||
If you want to generate the RST file by this helper fit the variables,
|
|
||||||
the playbook, and the template to your needs. Then, run the play
|
|
||||||
|
|
||||||
```sh
|
|
||||||
shell> ansible-playbook playbook.yml
|
|
||||||
```
|
|
||||||
|
|
||||||
## Copy RST to docs/docsite/rst
|
|
||||||
|
|
||||||
Copy the RST file to `docs/docsite/rst` and remove it from this
|
|
||||||
directory.
|
|
||||||
|
|
||||||
## Update the checksums
|
|
||||||
|
|
||||||
Substitute the variables and run the below command
|
|
||||||
|
|
||||||
```sh
|
|
||||||
shell> sha1sum {{ file_rst }} > {{ file_sha1 }}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Playbook explained
|
|
||||||
|
|
||||||
The playbook includes the variable *tests* and creates the RST file
|
|
||||||
from the template. The playbook will terminate if the RST file was
|
|
||||||
changed manually. Review the changes and update the template and
|
|
||||||
variable *tests* if needed. Update the checksum to pass the integrity
|
|
||||||
test. The playbook message provides you with the command. Make sure
|
|
||||||
that the updated template nd vars create identical RST file. Only then
|
|
||||||
apply your changes.
|
|
||||||
|
|
||||||
## Optionally create integration test tasks and plugin examples
|
|
||||||
|
|
||||||
```sh
|
|
||||||
shell> ansible-playbook playbook.yml -e enable_tasks=true
|
|
||||||
shell> ansible-playbook playbook.yml -e enable_examples=true
|
|
||||||
```
|
|
|
@ -1 +0,0 @@
|
||||||
6ca4b820eb61d71c2796046550b06ab9b8e444c5 ../../rst/test_guide-ansible_type.rst
|
|
|
@ -1,3 +0,0 @@
|
||||||
Copyright (c) Ansible Project
|
|
||||||
GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
||||||
SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
@ -1,74 +0,0 @@
|
||||||
---
|
|
||||||
# Copyright (c) Ansible Project
|
|
||||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
||||||
|
|
||||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
||||||
# Create docs REST files. Optionally create integration tasks and
|
|
||||||
# plugin examples.
|
|
||||||
#
|
|
||||||
# shell> ansible-playbook playbook.yml
|
|
||||||
#
|
|
||||||
# Proofread and copy created *.rst file into the directory
|
|
||||||
# docs/docsite/rst. Do not add *.rst in this directory to the version
|
|
||||||
# control.
|
|
||||||
#
|
|
||||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
||||||
# community.general/docs/docsite/helper/ansible_type/playbook.yml
|
|
||||||
|
|
||||||
- name: Create RST file for docs/docsite/rst
|
|
||||||
hosts: localhost
|
|
||||||
gather_facts: false
|
|
||||||
|
|
||||||
vars:
|
|
||||||
|
|
||||||
plugin: ansible_type
|
|
||||||
docs_path:
|
|
||||||
- test_guide
|
|
||||||
|
|
||||||
file_base: "{{ (docs_path + [plugin]) | join('-') }}"
|
|
||||||
file_rst: ../../rst/{{ file_base }}.rst
|
|
||||||
file_sha1: "{{ plugin }}.rst.sha1"
|
|
||||||
|
|
||||||
start: "{{ '{{' }}"
|
|
||||||
stop: "{{ '}}' }}"
|
|
||||||
|
|
||||||
tasks:
|
|
||||||
|
|
||||||
- name: Test integrity RST file
|
|
||||||
when:
|
|
||||||
- integrity | d(true) | bool
|
|
||||||
- lookup('file', file_sha1) != lookup('pipe', 'sha1sum ' ~ file_rst)
|
|
||||||
block:
|
|
||||||
|
|
||||||
- name: Changed RST file
|
|
||||||
ansible.builtin.debug:
|
|
||||||
msg: |
|
|
||||||
Changed {{ file_rst }}
|
|
||||||
Review the changes and update {{ file_sha1 }}
|
|
||||||
shell> sha1sum {{ file_rst }} > {{ file_sha1 }}
|
|
||||||
|
|
||||||
- name: Changed RST file end host
|
|
||||||
ansible.builtin.meta: end_play
|
|
||||||
|
|
||||||
- name: Include target vars
|
|
||||||
include_vars:
|
|
||||||
file: vars/main/tests.yml
|
|
||||||
|
|
||||||
- name: Create RST file
|
|
||||||
ansible.builtin.template:
|
|
||||||
src: "{{ file_base }}.rst.j2"
|
|
||||||
dest: "{{ file_base }}.rst"
|
|
||||||
when: enable_rst | d(true) | bool
|
|
||||||
|
|
||||||
- name: Create plugin examples
|
|
||||||
ansible.builtin.template:
|
|
||||||
src: examples.yml.j2
|
|
||||||
dest: examples.yml
|
|
||||||
when: enable_examples | d(false) | bool
|
|
||||||
|
|
||||||
- name: Create integration tasks
|
|
||||||
ansible.builtin.template:
|
|
||||||
src: tasks.yml.j2
|
|
||||||
dest: tasks.yml
|
|
||||||
when: enable_tasks | d(false) | bool
|
|
|
@ -1,67 +0,0 @@
|
||||||
# Copyright (c) Ansible Project
|
|
||||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
||||||
|
|
||||||
# Substitution converts str to AnsibleUnicode
|
|
||||||
# -------------------------------------------
|
|
||||||
{% for i in (0, 1, 2, 3) %}
|
|
||||||
|
|
||||||
# {{ tests[i].d }}
|
|
||||||
{% if tests[i].alias is defined %}
|
|
||||||
alias: {{ tests[i].alias | to_json }}
|
|
||||||
dtype: {{ tests[i].r }}
|
|
||||||
data: {{ tests[i].i | to_json }}
|
|
||||||
result: '{{ start }} data is community.general.ansible_type(dtype, alias) {{ stop }}'
|
|
||||||
# result => true
|
|
||||||
{% else %}
|
|
||||||
dtype: {{ tests[i].r }}
|
|
||||||
data: {{ tests[i].i | to_json }}
|
|
||||||
result: '{{ start }} data is community.general.ansible_type(dtype) {{ stop }}'
|
|
||||||
# result => true
|
|
||||||
{% endif %}
|
|
||||||
{% endfor %}
|
|
||||||
|
|
||||||
# No substitution and no alias. Type of strings is str
|
|
||||||
# ----------------------------------------------------
|
|
||||||
{% for test in tests.4.group %}
|
|
||||||
|
|
||||||
# {{ test.d }}
|
|
||||||
dtype: {{ test.r }}
|
|
||||||
result: '{{ start }} {{ test.i | to_json }} is community.general.ansible_type(dtype) {{ stop }}'
|
|
||||||
# result => true
|
|
||||||
{% endfor %}
|
|
||||||
|
|
||||||
# Type of strings is AnsibleUnicode or str
|
|
||||||
# ----------------------------------------
|
|
||||||
{% for test in tests.5.group %}
|
|
||||||
|
|
||||||
# {{ test.d }}
|
|
||||||
alias: {{ tests.5.alias | to_json }}
|
|
||||||
dtype: {{ test.r }}
|
|
||||||
data: {{ test.i }}
|
|
||||||
result: '{{ start }} data is community.general.ansible_type(dtype, alias) {{ stop }}'
|
|
||||||
# result => true
|
|
||||||
{% endfor %}
|
|
||||||
|
|
||||||
# Option dtype is list
|
|
||||||
# --------------------
|
|
||||||
{% for test in tests.6.group %}
|
|
||||||
|
|
||||||
# {{ test.d }}
|
|
||||||
dtype: {{ test.r }}
|
|
||||||
data: {{ test.i }}
|
|
||||||
result: '{{ start }} data is community.general.ansible_type(dtype) {{ stop }}'
|
|
||||||
# result => true
|
|
||||||
{% endfor %}
|
|
||||||
|
|
||||||
# Multiple alias
|
|
||||||
# --------------
|
|
||||||
{% for test in tests.7.group %}
|
|
||||||
|
|
||||||
# {{ test.d }}
|
|
||||||
alias: {{ tests.7.alias | to_json }}
|
|
||||||
dtype: {{ test.r }}
|
|
||||||
data: {{ test.i }}
|
|
||||||
result: '{{ start }} data is community.general.ansible_type(dtype, alias) {{ stop }}'
|
|
||||||
# result => true
|
|
||||||
{% endfor %}
|
|
|
@ -1,96 +0,0 @@
|
||||||
# Copyright (c) Ansible Project
|
|
||||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
||||||
|
|
||||||
# Substitution converts str to AnsibleUnicode
|
|
||||||
# -------------------------------------------
|
|
||||||
{% for i in (0, 1, 2, 3) %}
|
|
||||||
|
|
||||||
- name: {{ tests[i].d }}
|
|
||||||
assert:
|
|
||||||
{% if tests[i].alias is defined %}
|
|
||||||
that: data is community.general.ansible_type(dtype, alias)
|
|
||||||
success_msg: '{{ tests[i].i | to_json }} is {{ start }} dtype {{ stop }}'
|
|
||||||
fail_msg: '{{ tests[i].i | to_json }} is {{ start }} result {{ stop }}'
|
|
||||||
quiet: '{{ start }} quiet_test | d(true) | bool {{ stop }}'
|
|
||||||
vars:
|
|
||||||
alias: {{ tests[i].alias | to_json }}
|
|
||||||
data: {{ tests[i].i | to_json }}
|
|
||||||
result: '{{ start }} data | community.general.reveal_ansible_type(alias) {{ stop }}'
|
|
||||||
dtype: '{{ tests[i].r }}'
|
|
||||||
{% else %}
|
|
||||||
that: data is community.general.ansible_type(dtype)
|
|
||||||
success_msg: '{{ tests[i].i | to_json }} is {{ start }} dtype {{ stop }}'
|
|
||||||
fail_msg: '{{ tests[i].i | to_json }} is {{ start }} result {{ stop }}'
|
|
||||||
quiet: '{{ start }} quiet_test | d(true) | bool {{ stop }}'
|
|
||||||
vars:
|
|
||||||
data: {{ tests[i].i | to_json }}
|
|
||||||
result: '{{ start }} data | community.general.reveal_ansible_type {{ stop }}'
|
|
||||||
dtype: '{{ tests[i].r }}'
|
|
||||||
{% endif %}
|
|
||||||
{% endfor %}
|
|
||||||
|
|
||||||
# No substitution and no alias. Type of strings is str
|
|
||||||
# ----------------------------------------------------
|
|
||||||
{% for test in tests.4.group %}
|
|
||||||
|
|
||||||
- name: {{ test.d }}
|
|
||||||
assert:
|
|
||||||
that: '{{ test.i | to_json }} is community.general.ansible_type(dtype)'
|
|
||||||
success_msg: '{{ test.i | to_json }} is {{ start }} dtype {{ stop }}'
|
|
||||||
fail_msg: '{{ test.i | to_json }} is {{ start }} result {{ stop }}'
|
|
||||||
quiet: '{{ start }} quiet_test | d(true) | bool {{ stop }}'
|
|
||||||
vars:
|
|
||||||
result: '{{ start }} {{ test.i | to_json }} | community.general.reveal_ansible_type {{ stop }}'
|
|
||||||
dtype: {{ test.r }}
|
|
||||||
{% endfor %}
|
|
||||||
|
|
||||||
# Type of strings is AnsibleUnicode or str
|
|
||||||
# ----------------------------------------
|
|
||||||
{% for test in tests.5.group %}
|
|
||||||
|
|
||||||
- name: {{ test.d }}
|
|
||||||
assert:
|
|
||||||
that: data is community.general.ansible_type(dtype, alias)
|
|
||||||
success_msg: '{{ test.i | to_json }} is {{ start }} dtype {{ stop }}'
|
|
||||||
fail_msg: '{{ test.i | to_json }} is {{ start }} result {{ stop }}'
|
|
||||||
quiet: '{{ start }} quiet_test | d(true) | bool {{ stop }}'
|
|
||||||
vars:
|
|
||||||
alias: {{ tests.5.alias | to_json }}
|
|
||||||
data: {{ test.i }}
|
|
||||||
result: '{{ start }} data | community.general.reveal_ansible_type(alias) {{ stop }}'
|
|
||||||
dtype: {{ test.r }}
|
|
||||||
{% endfor %}
|
|
||||||
|
|
||||||
# Option dtype is list
|
|
||||||
# --------------------
|
|
||||||
{% for test in tests.6.group %}
|
|
||||||
|
|
||||||
- name: {{ test.d }}
|
|
||||||
assert:
|
|
||||||
that: data is community.general.ansible_type(dtype)
|
|
||||||
success_msg: '{{ test.i | to_json }} is {{ start }} dtype {{ stop }}'
|
|
||||||
fail_msg: '{{ test.i | to_json }} is {{ start }} result {{ stop }}'
|
|
||||||
quiet: '{{ start }} quiet_test | d(true) | bool {{ stop }}'
|
|
||||||
vars:
|
|
||||||
data: {{ test.i }}
|
|
||||||
result: '{{ start }} data | community.general.reveal_ansible_type {{ stop }}'
|
|
||||||
dtype: {{ test.r }}
|
|
||||||
{% endfor %}
|
|
||||||
|
|
||||||
# Multiple alias
|
|
||||||
# --------------
|
|
||||||
{% for test in tests.7.group %}
|
|
||||||
|
|
||||||
- name: {{ test.d }}
|
|
||||||
assert:
|
|
||||||
that: data is community.general.ansible_type(dtype, alias)
|
|
||||||
success_msg: '{{ test.i | to_json }} is {{ start }} dtype {{ stop }}'
|
|
||||||
fail_msg: '{{ test.i | to_json }} is {{ start }} result {{ stop }}'
|
|
||||||
quiet: '{{ start }} quiet_test | d(true) | bool {{ stop }}'
|
|
||||||
vars:
|
|
||||||
alias: {{ tests.7.alias | to_json }}
|
|
||||||
data: {{ test.i }}
|
|
||||||
result: '{{ start }} data | community.general.reveal_ansible_type(alias) {{ stop }}'
|
|
||||||
dtype: {{ test.r }}
|
|
||||||
{% endfor %}
|
|
|
@ -1,86 +0,0 @@
|
||||||
..
|
|
||||||
Copyright (c) Ansible Project
|
|
||||||
GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
||||||
SPDX-License-Identifier: GPL-3.0-or-later
|
|
||||||
|
|
||||||
Test ansible_type
|
|
||||||
-----------------
|
|
||||||
|
|
||||||
Use the test :ansplugin:`community.general.ansible_type#test` if you want to test the type of Ansible data.
|
|
||||||
|
|
||||||
.. note:: The output of the examples in this section use the YAML callback plugin. Quoting: "Ansible output that can be quite a bit easier to read than the default JSON formatting." See :ansplugin:`the documentation for the community.general.yaml callback plugin <community.general.yaml#callback>`.
|
|
||||||
|
|
||||||
.. versionadded:: 9.2.0
|
|
||||||
|
|
||||||
**Substitution converts str to AnsibleUnicode**
|
|
||||||
{% for i in (0, 1, 2, 3) %}
|
|
||||||
|
|
||||||
* {{ tests[i].d }}
|
|
||||||
|
|
||||||
.. code-block:: yaml+jinja
|
|
||||||
|
|
||||||
{% if tests[i].alias is defined %}
|
|
||||||
alias: {{ tests[i].alias | to_json }}
|
|
||||||
dtype: {{ tests[i].r }}
|
|
||||||
data: {{ tests[i].i | to_json }}
|
|
||||||
result: '{{ start }} data is community.general.ansible_type(dtype, alias) {{ stop }}'
|
|
||||||
{% else %}
|
|
||||||
dtype: {{ tests[i].r }}
|
|
||||||
data: {{ tests[i].i | to_json }}
|
|
||||||
result: '{{ start }} data is community.general.ansible_type(dtype) {{ stop }}'
|
|
||||||
{% endif %}
|
|
||||||
# result => true
|
|
||||||
{% endfor %}
|
|
||||||
|
|
||||||
**No substitution and no alias. Type of strings is str**
|
|
||||||
{% for test in tests.4.group %}
|
|
||||||
|
|
||||||
* {{ test.d }}
|
|
||||||
|
|
||||||
.. code-block:: yaml+jinja
|
|
||||||
|
|
||||||
dtype: {{ test.r }}
|
|
||||||
result: '{{ start }} {{ test.i | to_json }} is community.general.ansible_type {{ stop }}'
|
|
||||||
result => true
|
|
||||||
{% endfor %}
|
|
||||||
|
|
||||||
**Type of strings is AnsibleUnicode or str**
|
|
||||||
{% for test in tests.5.group %}
|
|
||||||
|
|
||||||
* {{ test.d }}
|
|
||||||
|
|
||||||
.. code-block:: yaml+jinja
|
|
||||||
|
|
||||||
alias: {{ tests.5.alias | to_json }}
|
|
||||||
dtype: {{ test.r }}
|
|
||||||
data: {{ test.i }}
|
|
||||||
result: '{{ start }} data is community.general.ansible_type(dtype, alias) {{ stop }}'
|
|
||||||
# result => true
|
|
||||||
{% endfor %}
|
|
||||||
|
|
||||||
**Option dtype is list**
|
|
||||||
{% for test in tests.6.group %}
|
|
||||||
|
|
||||||
* {{ test.d }}
|
|
||||||
|
|
||||||
.. code-block:: yaml+jinja
|
|
||||||
|
|
||||||
dtype: {{ test.r }}
|
|
||||||
data: {{ test.i }}
|
|
||||||
result: '{{ start }} data is community.general.ansible_type(dtype) {{ stop }}'
|
|
||||||
# result => true
|
|
||||||
{% endfor %}
|
|
||||||
|
|
||||||
**Multiple alias**
|
|
||||||
{% for test in tests.7.group %}
|
|
||||||
|
|
||||||
* {{ test.d }}
|
|
||||||
|
|
||||||
.. code-block:: yaml+jinja
|
|
||||||
|
|
||||||
alias: {{ tests.7.alias | to_json }}
|
|
||||||
dtype: {{ test.r }}
|
|
||||||
data: {{ test.i }}
|
|
||||||
result: '{{ start }} data is community.general.ansible_type(dtype, alias) {{ stop }}'
|
|
||||||
# result => true
|
|
||||||
{% endfor %}
|
|
|
@ -1,105 +0,0 @@
|
||||||
---
|
|
||||||
# Copyright (c) Ansible Project
|
|
||||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
||||||
|
|
||||||
# Note: Expansion in a loop will convert all AnsibleUnicode types to str.
|
|
||||||
|
|
||||||
tests:
|
|
||||||
- name: 0.Test AnsibleUnicode.
|
|
||||||
i: abc
|
|
||||||
r: AnsibleUnicode
|
|
||||||
d: String. AnsibleUnicode.
|
|
||||||
- name: 1.Test AnsibleUnicode alias str.
|
|
||||||
alias:
|
|
||||||
AnsibleUnicode: str
|
|
||||||
i: abc
|
|
||||||
r: str
|
|
||||||
d: String. AnsibleUnicode alias str.
|
|
||||||
- name: 2.Test list[AnsibleUnicode].
|
|
||||||
i: [a, b, c]
|
|
||||||
r: list[AnsibleUnicode]
|
|
||||||
d: List. All items are AnsibleUnicode.
|
|
||||||
- name: 3.Test dict[AnsibleUnicode, AnsibleUnicode].
|
|
||||||
i: {a: foo, b: bar, c: baz}
|
|
||||||
r: dict[AnsibleUnicode, AnsibleUnicode]
|
|
||||||
d: Dictionary. All keys are AnsibleUnicode. All values are AnsibleUnicode.
|
|
||||||
- name: 4.Test no substitution and no alias. Type of strings is str.
|
|
||||||
alias: {}
|
|
||||||
group:
|
|
||||||
- i: abc
|
|
||||||
r: str
|
|
||||||
d: String
|
|
||||||
- i: 123
|
|
||||||
r: int
|
|
||||||
d: Integer
|
|
||||||
- i: 123.45
|
|
||||||
r: float
|
|
||||||
d: Float
|
|
||||||
- i: True
|
|
||||||
r: bool
|
|
||||||
d: Boolean
|
|
||||||
- i: [a, b, c]
|
|
||||||
r: list[str]
|
|
||||||
d: List. All items are strings.
|
|
||||||
- i: [{a: 1}, {b: 2}]
|
|
||||||
r: list[dict]
|
|
||||||
d: List of dictionaries.
|
|
||||||
- i: {a: 1}
|
|
||||||
r: dict[str, int]
|
|
||||||
d: Dictionary. All keys are strings. All values are integers.
|
|
||||||
- i: {a: 1, b: 2}
|
|
||||||
r: dict[str, int]
|
|
||||||
d: Dictionary. All keys are strings. All values are integers.
|
|
||||||
- name: 5.Test no substitution and no alias. Type of strings is str.
|
|
||||||
alias:
|
|
||||||
AnsibleUnicode: str
|
|
||||||
group:
|
|
||||||
- i: {1: a, b: b}
|
|
||||||
r: dict[int|str, str]
|
|
||||||
d: Dictionary. The keys are integers or strings. All values are strings.
|
|
||||||
- i: {1: a, 2: b}
|
|
||||||
r: dict[int, str]
|
|
||||||
d: Dictionary. All keys are integers. All values are keys.
|
|
||||||
- i:
|
|
||||||
a: 1
|
|
||||||
b: 1.1
|
|
||||||
c: abc
|
|
||||||
d: true
|
|
||||||
e: [x, y, z]
|
|
||||||
f: {x: 1, y: 2}
|
|
||||||
r: dict[str, bool|dict|float|int|list|str]
|
|
||||||
d: Dictionary. All keys are strings. Multiple types values.
|
|
||||||
- i:
|
|
||||||
- 1
|
|
||||||
- 2
|
|
||||||
- 1.1
|
|
||||||
- abc
|
|
||||||
- true
|
|
||||||
- [x, y, z]
|
|
||||||
- {x: 1, y: 2}
|
|
||||||
r: list[bool|dict|float|int|list|str]
|
|
||||||
d: List. Multiple types items.
|
|
||||||
- name: 6.Test dtype list.
|
|
||||||
alias: {}
|
|
||||||
group:
|
|
||||||
- i: abc
|
|
||||||
r: [AnsibleUnicode, str]
|
|
||||||
d: AnsibleUnicode or str
|
|
||||||
- i: 123
|
|
||||||
r: [float, int]
|
|
||||||
d: float or int
|
|
||||||
- i: 123.45
|
|
||||||
r: [float, int]
|
|
||||||
d: float or int
|
|
||||||
- name: 7.Multiple alias.
|
|
||||||
alias:
|
|
||||||
int: number
|
|
||||||
float: number
|
|
||||||
group:
|
|
||||||
- i: 123
|
|
||||||
r: number
|
|
||||||
d: int alias number
|
|
||||||
- i: 123.45
|
|
||||||
r: number
|
|
||||||
d: float alias number
|
|
|
@ -1,51 +0,0 @@
|
||||||
<!--
|
|
||||||
Copyright (c) Ansible Project
|
|
||||||
GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
||||||
SPDX-License-Identifier: GPL-3.0-or-later
|
|
||||||
-->
|
|
||||||
|
|
||||||
# Docs helper. Create RST file.
|
|
||||||
|
|
||||||
The playbook `playbook.yml` writes a RST file that can be used in
|
|
||||||
docs/docsite/rst. The usage of this helper is recommended but not
|
|
||||||
mandatory. You can stop reading here and update the RST file manually
|
|
||||||
if you don't want to use this helper.
|
|
||||||
|
|
||||||
## Run the playbook
|
|
||||||
|
|
||||||
If you want to generate the RST file by this helper fit the variables,
|
|
||||||
the playbook, and the template to your needs. Then, run the play
|
|
||||||
|
|
||||||
```sh
|
|
||||||
shell> ansible-playbook playbook.yml
|
|
||||||
```
|
|
||||||
|
|
||||||
## Copy RST to docs/docsite/rst
|
|
||||||
|
|
||||||
Copy the RST file to `docs/docsite/rst` and remove it from this
|
|
||||||
directory.
|
|
||||||
|
|
||||||
## Update the checksums
|
|
||||||
|
|
||||||
Substitute the variables and run the below command
|
|
||||||
|
|
||||||
```sh
|
|
||||||
shell> sha1sum {{ file_rst }} > {{ file_sha1 }}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Playbook explained
|
|
||||||
|
|
||||||
The playbook includes the variable *tests* and creates the RST file
|
|
||||||
from the template. The playbook will terminate if the RST file was
|
|
||||||
changed manually. Review the changes and update the template and
|
|
||||||
variable *tests* if needed. Update the checksum to pass the integrity
|
|
||||||
test. The playbook message provides you with the command. Make sure
|
|
||||||
that the updated template nd vars create identical RST file. Only then
|
|
||||||
apply your changes.
|
|
||||||
|
|
||||||
## Optionally create integration test tasks and plugin examples
|
|
||||||
|
|
||||||
```sh
|
|
||||||
shell> ansible-playbook playbook.yml -e enable_tasks=true
|
|
||||||
shell> ansible-playbook playbook.yml -e enable_examples=true
|
|
||||||
```
|
|
|
@ -1,76 +0,0 @@
|
||||||
---
|
|
||||||
# Copyright (c) Ansible Project
|
|
||||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
||||||
|
|
||||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
||||||
# Create docs REST files. Optionally create integration tasks and
|
|
||||||
# plugin examples.
|
|
||||||
#
|
|
||||||
# shell> ansible-playbook playbook.yml
|
|
||||||
#
|
|
||||||
# Proofread and copy created *.rst file into the directory
|
|
||||||
# docs/docsite/rst. Do not add *.rst in this directory to the version
|
|
||||||
# control.
|
|
||||||
#
|
|
||||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
||||||
# community.general/docs/docsite/helper/reveal_ansible_type/playbook.yml
|
|
||||||
|
|
||||||
- name: Create RST file for docs/docsite/rst
|
|
||||||
hosts: localhost
|
|
||||||
gather_facts: false
|
|
||||||
|
|
||||||
vars:
|
|
||||||
|
|
||||||
plugin: reveal_ansible_type
|
|
||||||
docs_path:
|
|
||||||
- filter_guide
|
|
||||||
- abstract_informations
|
|
||||||
- types
|
|
||||||
|
|
||||||
file_base: "{{ (docs_path + [plugin]) | join('-') }}"
|
|
||||||
file_rst: ../../rst/{{ file_base }}.rst
|
|
||||||
file_sha1: "{{ plugin }}.rst.sha1"
|
|
||||||
|
|
||||||
start: "{{ '{{' }}"
|
|
||||||
stop: "{{ '}}' }}"
|
|
||||||
|
|
||||||
tasks:
|
|
||||||
|
|
||||||
- name: Test integrity RST file
|
|
||||||
when:
|
|
||||||
- integrity | d(true) | bool
|
|
||||||
- lookup('file', file_sha1) != lookup('pipe', 'sha1sum ' ~ file_rst)
|
|
||||||
block:
|
|
||||||
|
|
||||||
- name: Changed RST file
|
|
||||||
ansible.builtin.debug:
|
|
||||||
msg: |
|
|
||||||
Changed {{ file_rst }}
|
|
||||||
Review the changes and update {{ file_sha1 }}
|
|
||||||
shell> sha1sum {{ file_rst }} > {{ file_sha1 }}
|
|
||||||
|
|
||||||
- name: Changed RST file end host
|
|
||||||
ansible.builtin.meta: end_play
|
|
||||||
|
|
||||||
- name: Include target vars
|
|
||||||
include_vars:
|
|
||||||
file: vars/main/tests.yml
|
|
||||||
|
|
||||||
- name: Create RST file
|
|
||||||
ansible.builtin.template:
|
|
||||||
src: "{{ file_base }}.rst.j2"
|
|
||||||
dest: "{{ file_base }}.rst"
|
|
||||||
when: enable_rst | d(true) | bool
|
|
||||||
|
|
||||||
- name: Create plugin examples
|
|
||||||
ansible.builtin.template:
|
|
||||||
src: examples.yml.j2
|
|
||||||
dest: examples.yml
|
|
||||||
when: enable_examples | d(false) | bool
|
|
||||||
|
|
||||||
- name: Create integration tasks
|
|
||||||
ansible.builtin.template:
|
|
||||||
src: tasks.yml.j2
|
|
||||||
dest: tasks.yml
|
|
||||||
when: enable_tasks | d(false) | bool
|
|
|
@ -1 +0,0 @@
|
||||||
845a993148d2f66035cd5d89adf616020f66b3f8 ../../rst/filter_guide-abstract_informations-types-reveal_ansible_type.rst
|
|
|
@ -1,3 +0,0 @@
|
||||||
Copyright (c) Ansible Project
|
|
||||||
GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
||||||
SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
@ -1,40 +0,0 @@
|
||||||
# Copyright (c) Ansible Project
|
|
||||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
||||||
|
|
||||||
# Substitution converts str to AnsibleUnicode
|
|
||||||
# -------------------------------------------
|
|
||||||
{% for i in (0, 1, 2, 3) %}
|
|
||||||
|
|
||||||
# {{ tests[i].d }}
|
|
||||||
{% if tests[i].alias is defined %}
|
|
||||||
alias: {{ tests[i].alias | to_json }}
|
|
||||||
data: {{ tests[i].i | to_json }}
|
|
||||||
result: '{{ start }} data | community.general.reveal_ansible_type(alias) {{ stop }}'
|
|
||||||
# result => {{ tests[i].r }}
|
|
||||||
{% else %}
|
|
||||||
data: {{ tests[i].i | to_json }}
|
|
||||||
result: '{{ start }} data | community.general.reveal_ansible_type {{ stop }}'
|
|
||||||
# result => {{ tests[i].r }}
|
|
||||||
{% endif %}
|
|
||||||
{% endfor %}
|
|
||||||
|
|
||||||
# No substitution and no alias. Type of strings is str
|
|
||||||
# ----------------------------------------------------
|
|
||||||
{% for test in tests.4.group %}
|
|
||||||
|
|
||||||
# {{ test.d }}
|
|
||||||
result: '{{ start }} {{ test.i | to_json }} | community.general.reveal_ansible_type {{ stop }}'
|
|
||||||
# result => {{ test.r }}
|
|
||||||
{% endfor %}
|
|
||||||
|
|
||||||
# Type of strings is AnsibleUnicode or str
|
|
||||||
# ----------------------------------------
|
|
||||||
{% for test in tests.5.group %}
|
|
||||||
|
|
||||||
# {{ test.d }}
|
|
||||||
alias: {{ tests.5.alias | to_json }}
|
|
||||||
data: {{ test.i }}
|
|
||||||
result: '{{ start }} data | community.general.reveal_ansible_type(alias) {{ stop }}'
|
|
||||||
# result => {{ test.r }}
|
|
||||||
{% endfor %}
|
|
|
@ -1,55 +0,0 @@
|
||||||
..
|
|
||||||
Copyright (c) Ansible Project
|
|
||||||
GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
||||||
SPDX-License-Identifier: GPL-3.0-or-later
|
|
||||||
|
|
||||||
Filter reveal_ansible_type
|
|
||||||
""""""""""""""""""""""""""
|
|
||||||
|
|
||||||
Use the filter :ansplugin:`community.general.reveal_ansible_type#filter` if you want to get the type of Ansible data.
|
|
||||||
|
|
||||||
.. note:: The output of the examples in this section use the YAML callback plugin. Quoting: "Ansible output that can be quite a bit easier to read than the default JSON formatting." See :ansplugin:`the documentation for the community.general.yaml callback plugin <community.general.yaml#callback>`.
|
|
||||||
|
|
||||||
.. versionadded:: 9.2.0
|
|
||||||
|
|
||||||
**Substitution converts str to AnsibleUnicode**
|
|
||||||
{% for i in (0, 1, 2, 3) %}
|
|
||||||
|
|
||||||
* {{ tests[i].d }}
|
|
||||||
|
|
||||||
.. code-block:: yaml+jinja
|
|
||||||
|
|
||||||
{% if tests[i].alias is defined %}
|
|
||||||
alias: {{ tests[i].alias | to_json }}
|
|
||||||
data: {{ tests[i].i | to_json }}
|
|
||||||
result: '{{ start }} data | community.general.reveal_ansible_type(alias) {{ stop }}'
|
|
||||||
{% else %}
|
|
||||||
data: {{ tests[i].i | to_json }}
|
|
||||||
result: '{{ start }} data | community.general.reveal_ansible_type {{ stop }}'
|
|
||||||
{% endif %}
|
|
||||||
# result => {{ tests[i].r }}
|
|
||||||
{% endfor %}
|
|
||||||
|
|
||||||
**No substitution and no alias. Type of strings is str**
|
|
||||||
{% for test in tests.4.group %}
|
|
||||||
|
|
||||||
* {{ test.d }}
|
|
||||||
|
|
||||||
.. code-block:: yaml+jinja
|
|
||||||
|
|
||||||
result: '{{ start }} {{ test.i | to_json }} | community.general.reveal_ansible_type {{ stop }}'
|
|
||||||
# result => {{ test.r }}
|
|
||||||
{% endfor %}
|
|
||||||
|
|
||||||
**Type of strings is AnsibleUnicode or str**
|
|
||||||
{% for test in tests.5.group %}
|
|
||||||
|
|
||||||
* {{ test.d }}
|
|
||||||
|
|
||||||
.. code-block:: yaml+jinja
|
|
||||||
|
|
||||||
alias: {{ tests.5.alias | to_json }}
|
|
||||||
data: {{ test.i }}
|
|
||||||
result: '{{ start }} data | community.general.reveal_ansible_type(alias) {{ stop }}'
|
|
||||||
# result => {{ test.r }}
|
|
||||||
{% endfor %}
|
|
|
@ -1,63 +0,0 @@
|
||||||
# Copyright (c) Ansible Project
|
|
||||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
||||||
|
|
||||||
# Substitution converts str to AnsibleUnicode
|
|
||||||
# -------------------------------------------
|
|
||||||
{% for i in (0, 1, 2, 3) %}
|
|
||||||
|
|
||||||
- name: {{ tests[i].d }}
|
|
||||||
assert:
|
|
||||||
{% if tests[i].alias is defined %}
|
|
||||||
that: result == dtype
|
|
||||||
success_msg: '{{ tests[i].i | to_json }} is {{ start }} dtype {{ stop }}'
|
|
||||||
fail_msg: '{{ tests[i].i | to_json }} is {{ start }} result {{ stop }}'
|
|
||||||
quiet: '{{ start }} quiet_test | d(true) | bool {{ stop }}'
|
|
||||||
vars:
|
|
||||||
alias: {{ tests[i].alias | to_json }}
|
|
||||||
data: {{ tests[i].i | to_json }}
|
|
||||||
result: '{{ start }} data | community.general.reveal_ansible_type(alias) {{ stop }}'
|
|
||||||
dtype: '{{ tests[i].r }}'
|
|
||||||
{% else %}
|
|
||||||
that: result == dtype
|
|
||||||
success_msg: '{{ tests[i].i | to_json }} is {{ start }} dtype {{ stop }}'
|
|
||||||
fail_msg: '{{ tests[i].i | to_json }} is {{ start }} result {{ stop }}'
|
|
||||||
quiet: '{{ start }} quiet_test | d(true) | bool {{ stop }}'
|
|
||||||
vars:
|
|
||||||
data: {{ tests[i].i | to_json }}
|
|
||||||
result: '{{ start }} data | community.general.reveal_ansible_type {{ stop }}'
|
|
||||||
dtype: '{{ tests[i].r }}'
|
|
||||||
{% endif %}
|
|
||||||
{% endfor %}
|
|
||||||
|
|
||||||
# No substitution and no alias. Type of strings is str
|
|
||||||
# ----------------------------------------------------
|
|
||||||
{% for test in tests.4.group %}
|
|
||||||
|
|
||||||
- name: {{ test.d }}
|
|
||||||
assert:
|
|
||||||
that: result == dtype
|
|
||||||
success_msg: '{{ test.i | to_json }} is {{ start }} dtype {{ stop }}'
|
|
||||||
fail_msg: '{{ test.i | to_json }} is {{ start }} result {{ stop }}'
|
|
||||||
quiet: '{{ start }} quiet_test | d(true) | bool {{ stop }}'
|
|
||||||
vars:
|
|
||||||
result: '{{ start }} {{ test.i | to_json }} | community.general.reveal_ansible_type {{ stop }}'
|
|
||||||
dtype: {{ test.r }}
|
|
||||||
{% endfor %}
|
|
||||||
|
|
||||||
# Type of strings is AnsibleUnicode or str
|
|
||||||
# ----------------------------------------
|
|
||||||
{% for test in tests.5.group %}
|
|
||||||
|
|
||||||
- name: {{ test.d }}
|
|
||||||
assert:
|
|
||||||
that: result == dtype
|
|
||||||
success_msg: 'data is {{ start }} dtype {{ stop }}'
|
|
||||||
fail_msg: 'data is {{ start }} result {{ stop }}'
|
|
||||||
quiet: '{{ start }} quiet_test | d(true) | bool {{ stop }}'
|
|
||||||
vars:
|
|
||||||
alias: {{ tests.5.alias | to_json }}
|
|
||||||
data: {{ test.i }}
|
|
||||||
result: '{{ start }} data | community.general.reveal_ansible_type(alias) {{ stop }}'
|
|
||||||
dtype: {{ test.r }}
|
|
||||||
{% endfor %}
|
|
|
@ -1,82 +0,0 @@
|
||||||
---
|
|
||||||
# Copyright (c) Ansible Project
|
|
||||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
||||||
|
|
||||||
# Note: Expansion in a loop will convert all AnsibleUnicode types to str.
|
|
||||||
|
|
||||||
tests:
|
|
||||||
- name: 0.Test AnsibleUnicode.
|
|
||||||
i: abc
|
|
||||||
r: AnsibleUnicode
|
|
||||||
d: String. AnsibleUnicode.
|
|
||||||
- name: 1.Test AnsibleUnicode alias str.
|
|
||||||
alias:
|
|
||||||
AnsibleUnicode: str
|
|
||||||
i: abc
|
|
||||||
r: str
|
|
||||||
d: String. AnsibleUnicode alias str.
|
|
||||||
- name: 2.Test list[AnsibleUnicode].
|
|
||||||
i: [a, b, c]
|
|
||||||
r: list[AnsibleUnicode]
|
|
||||||
d: List. All items are AnsibleUnicode.
|
|
||||||
- name: 3.Test dict[AnsibleUnicode, AnsibleUnicode].
|
|
||||||
i: {a: foo, b: bar, c: baz}
|
|
||||||
r: dict[AnsibleUnicode, AnsibleUnicode]
|
|
||||||
d: Dictionary. All keys are AnsibleUnicode. All values are AnsibleUnicode.
|
|
||||||
- name: 4.Test no substitution and no alias. Type of strings is str.
|
|
||||||
alias: {}
|
|
||||||
group:
|
|
||||||
- i: abc
|
|
||||||
r: str
|
|
||||||
d: String
|
|
||||||
- i: 123
|
|
||||||
r: int
|
|
||||||
d: Integer
|
|
||||||
- i: 123.45
|
|
||||||
r: float
|
|
||||||
d: Float
|
|
||||||
- i: True
|
|
||||||
r: bool
|
|
||||||
d: Boolean
|
|
||||||
- i: [a, b, c]
|
|
||||||
r: list[str]
|
|
||||||
d: List. All items are strings.
|
|
||||||
- i: [{a: 1}, {b: 2}]
|
|
||||||
r: list[dict]
|
|
||||||
d: List of dictionaries.
|
|
||||||
- i: {a: 1}
|
|
||||||
r: dict[str, int]
|
|
||||||
d: Dictionary. All keys are strings. All values are integers.
|
|
||||||
- i: {a: 1, b: 2}
|
|
||||||
r: dict[str, int]
|
|
||||||
d: Dictionary. All keys are strings. All values are integers.
|
|
||||||
- name: 5.Test no substitution and no alias. Type of strings is str.
|
|
||||||
alias:
|
|
||||||
AnsibleUnicode: str
|
|
||||||
group:
|
|
||||||
- i: {1: a, b: b}
|
|
||||||
r: dict[int|str, str]
|
|
||||||
d: Dictionary. The keys are integers or strings. All values are strings.
|
|
||||||
- i: {1: a, 2: b}
|
|
||||||
r: dict[int, str]
|
|
||||||
d: Dictionary. All keys are integers. All values are keys.
|
|
||||||
- i:
|
|
||||||
a: 1
|
|
||||||
b: 1.1
|
|
||||||
c: abc
|
|
||||||
d: true
|
|
||||||
e: [x, y, z]
|
|
||||||
f: {x: 1, y: 2}
|
|
||||||
r: dict[str, bool|dict|float|int|list|str]
|
|
||||||
d: Dictionary. All keys are strings. Multiple types values.
|
|
||||||
- i:
|
|
||||||
- 1
|
|
||||||
- 2
|
|
||||||
- 1.1
|
|
||||||
- abc
|
|
||||||
- true
|
|
||||||
- [x, y, z]
|
|
||||||
- {x: 1, y: 2}
|
|
||||||
r: list[bool|dict|float|int|list|str]
|
|
||||||
d: List. Multiple types items.
|
|
Loading…
Reference in a new issue