-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add docs for the filter reveal_ansible_type and the test ansible_type. #8645
Open
vbotka
wants to merge
4
commits into
ansible-collections:main
Choose a base branch
from
vbotka:feature-ansible-type-docs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<!-- | ||
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
6ca4b820eb61d71c2796046550b06ab9b8e444c5 ../../rst/test_guide-ansible_type.rst |
3 changes: 3 additions & 0 deletions
3
docs/docsite/helper/ansible_type/ansible_type.rst.sha1.license
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
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 |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is out of place. There are scripts and processes that work with the documentation files that will not execute playbooks in this context. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
--- | ||
# 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 |
67 changes: 67 additions & 0 deletions
67
docs/docsite/helper/ansible_type/templates/examples.yml.j2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# 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 %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
# 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 %} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use underscores:
Same below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this needed?
The name of the file is a concatenation of three headings' levels:
The concatenation by dash "-" keeps this information. I've already created a couple of files this way. Should all of them be renamed?
You kept the first dash. Do you think this one should be replaced too?
For the record: This name is used in filter_guide_abstract_informations.rst
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't catch the dashes in the previous PR. Generally all filenames in docs/docsite/rst/ use underscores instead of dashes. It would be great to keep it that way.