ans2dev.general.charts module – Generate high-quality charts using Plotly and save them as images.
Note
This module is part of the ans2dev.general collection (version 0.2.0).
It is not included in ansible-core.
To check whether it is installed, run ansible-galaxy collection list.
To install it, use: ansible-galaxy collection install ans2dev.general.
You need further requirements to be able to use this module,
see Requirements for details.
To use it in a playbook, specify: ans2dev.general.charts.
New in ans2dev.general 0.1.0
Synopsis
This module generates various types of charts like
line,bar,pieanddonutand saves them as images.It provides customization options for titles, axis labels, colors, sizes, fonts, and legends.
Uses Plotly and Kaleido for image generation.
Requirements
The below requirements are needed on the host that executes this module.
requests
plotly
kaleido
Parameters
Parameter |
Comments |
|---|---|
Filename for the saved chart image. |
|
Font color for chart text. Default: |
|
Font size for labels and text. Default: |
|
Image format for saving the chart. Choices:
|
|
Height of the generated chart image (in pixels). Default: |
|
Width of the generated chart image (in pixels). Default: |
|
Path where the chart image will be saved. |
|
Line shape for line charts. Choices:
|
|
Size of the hole in a donut chart (0 for a full pie chart). Default: |
|
Colors for pie or donut chart slices. Default: |
|
Data values for pie or donut chart slices. Default: |
|
Labels for pie or donut chart slices. Default: |
|
Title of the chart. |
|
Title for the legend. |
|
Type of chart to generate. Choices:
|
|
X-axis data values. Default: |
|
Label for the X-axis. |
|
List of Y-axis data series (each series is a list of numeric values). Default: |
|
Colors for the Y-axis data series. Default: |
|
Labels for the Y-axis data series. Default: |
Examples
- name: Generate a line chart for CPU Usage Over Time
ans2dev.general.charts:
type: "line"
titlechart: "CPU Usage Over Time"
xaxis: ['00:00', '02:00', '04:00', '06:00', '08:00']
xaxisname: "Time"
yaxis: [[20, 30, 40, 50, 60]]
yaxisname: ["CPU Usage %"]
yaxiscolor: ["red"]
shape_line: "spline"
imgwidth: 1920
imgheight: 1080
path: "/charts"
filename: "cpu_usage"
format: "png"
titlelegend: "Usage"
delegate_to: localhost
- name: Generate a pie chart for Resource Distribution
ans2dev.general.charts:
type: "pie"
titlechart: "Resource Distribution"
slicedata: [10, 20, 30, 40]
slicelabel: ["A", "B", "C", "D"]
slicecolor: ["#ff0000", "#00ff00", "#0000ff", "#ffff00"]
imgwidth: 800
imgheight: 600
path: "/charts"
filename: "resource_distribution"
format: "png"
delegate_to: localhost
Return Values
Common return values are documented here, the following are the fields unique to this module:
Key |
Description |
|---|---|
Indicates whether the chart image was successfully generated. Returned: always Sample: |