json[l] callback: add parameter to set JSON prettyprint indent level
SUMMARY
Add ANSIBLE_JSON_INDENT parameter to both the json and jsonl callback plugins. The default values are different between the two modules to maintain their existing behavior:
json: indent==4, causing a prettyprint output
jsonl: indent==0, causing a 1-line output
ISSUE TYPE
Feature Pull Request
COMPONENT NAME
ansible.posix.json
ansible.posix.jsonl
ADDITIONAL INFORMATION
One specific use-case that is enabled by this feature: if a user chooses to use the jsonl plugin so that they still get output at the end of each task (vs. only at the end of the play), they may also want human-readable output so that they can monitor the status of their play. For example, setting the jsonl indent level to 4 gives a) output at the end of each task, and b) making that output be both machine readable and human readable.
Using this trivial playbook shows the change:
- hosts: localhost
gather_facts: false
tasks:
- name: hello, world
debug:
msg: hello, world
When using the jsonl callback, here's what one JSON emit looks like before the change:
{"_event":"v2_playbook_on_play_start","_timestamp":"2023-04-08T12:11:48.001806Z","play":{"duration":{"start":"2023-04-08T12:11:48.001383Z"},"id":"acde4800-1122-f32c-94c3-000000000001","name":"localhost"},"tasks":[]}
After the change, setting ANSIBLE_JSON_INDENT to 4, the same output looks like this:
{
"_event":"v2_playbook_on_play_start",
"_timestamp":"2023-04-08T12:12:47.787516Z",
"play":{
"duration":{
"start":"2023-04-08T12:12:47.787164Z"
},
"id":"acde4800-1122-2946-e3e4-000000000001",
"name":"localhost"
},
"tasks":[]
}
Both outputs are suitable for automated processes to parse the machine readable output. The second output has the benefit of being human readable.
Reviewed-by: Adam Miller <admiller@redhat.com>
Reviewed-by: Jeff Squyres
|
||
|---|---|---|
| .azure-pipelines | ||
| .github | ||
| changelogs | ||
| docs | ||
| hacking | ||
| meta | ||
| plugins | ||
| tests | ||
| .gitignore | ||
| bindep.txt | ||
| CHANGELOG.rst | ||
| codecov.yml | ||
| COPYING | ||
| galaxy.yml | ||
| PSF-license.txt | ||
| README.md | ||
| requirements.txt | ||
| shippable.yml | ||
| test-requirements.txt | ||
ansible.posix
An Ansible Collection of modules and plugins that target POSIX UNIX/Linux and derivative Operating Systems.
Supported Versions of Ansible
Ansible version compatibility
This collection has been tested against following Ansible versions: >=2.9.
For collections that support Ansible 2.9, please ensure you update your network_os to use the
fully qualified collection name (for example, cisco.ios.ios).
Plugins and modules within a collection may be tested with only specific Ansible versions.
A collection may contain metadata that identifies these versions.
PEP440 is the schema used to describe the versions of Ansible.
Included content
Modules
| Name | Description |
|---|---|
| ansible.posix.acl | Set and retrieve file ACL information. |
| ansible.posix.at | Schedule the execution of a command or script file via the at command |
| ansible.posix.authorized_key | Adds or removes an SSH authorized key |
| ansible.posix.firewalld | Manage arbitrary ports/services with firewalld |
| ansible.posix.firewalld_info | Gather information about firewalld |
| ansible.posix.mount | Control active and configured mount points |
| ansible.posix.patch | Apply patch files using the GNU patch tool |
| ansible.posix.rhel_facts | Facts module to set or override RHEL specific facts. |
| ansible.posix.rhel_rpm_ostree | Ensure packages exist in a RHEL for Edge rpm-ostree based system |
| ansible.posix.rpm_ostree_upgrade | Manage rpm-ostree upgrade transactions |
| ansible.posix.seboolean | Toggles SELinux booleans |
| ansible.posix.selinux | Change policy and state of SELinux |
| ansible.posix.synchronize | A wrapper around rsync to make common tasks in your playbooks quick and easy |
| ansible.posix.sysctl | Manage entries in sysctl.conf. |
Installing this collection
You can install the ansible.posix collection with the Ansible Galaxy CLI:
ansible-galaxy collection install ansible.posix
You can also include it in a requirements.yml file and install it with ansible-galaxy collection install -r requirements.yml, using the format:
---
collections:
- name: ansible.posix
Using this collection
See Ansible Using collections for more details.
NOTE: For Ansible 2.9, you may not see deprecation warnings when you run your playbooks with this collection. Use this documentation to track when a module is deprecated.
Contributing to this collection
We welcome community contributions to this collection. See Contributing to Ansible-maintained collections for complete details.
Code of Conduct
This collection follows the Ansible project's Code of Conduct. Please read and familiarize yourself with this document.
Release notes
See changelog for more details.
External requirements
None
Tested with Ansible
- ansible-core 2.14 (devel)
- ansible-core 2.13 (stable)
- ansible-core 2.12 (stable)
- ansible-core 2.11 (stable)
- ansible-base 2.10 (stable)
- ansible 2.9 (stable)
Roadmap
More information
- Ansible Collection overview
- Ansible User guide
- Ansible Developer guide
- Ansible Community code of conduct
Licensing
GNU General Public License v3.0 or later.
See COPYING to see the full text.