ans2dev.general.charts module – Generate charts 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, pie and donut and 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

string / required

Filename for the saved chart image.

fontcolor

string

Font color for chart text.

Default: "#333333"

fontsize

integer

Font size for labels and text.

Default: 20

format

string

Image format for saving the chart.

Choices:

  • "png" ← (default)

  • "jpeg"

  • "webp"

  • "svg"

  • "pdf"

  • "eps"

imgheight

integer

Height of the generated chart image (in pixels).

Default: 1080

imgwidth

integer

Width of the generated chart image (in pixels).

Default: 1920

path

string / required

Path where the chart image will be saved.

shape_line

string

Line shape for line charts.

Choices:

  • "spline"

  • "linear"

sizehole

float

Size of the hole in a donut chart (0 for a full pie chart).

Default: 0.5

slicecolor

list / elements=string

Colors for pie or donut chart slices.

Default: []

slicedata

list / elements=float

Data values for pie or donut chart slices.

Default: []

slicelabel

list / elements=string

Labels for pie or donut chart slices.

Default: []

titlechart

string

Title of the chart.

titlelegend

string

Title for the legend.

type

string / required

Type of chart to generate.

Choices:

  • "line"

  • "bar"

  • "pie"

  • "donut"

xaxis

list / elements=string

X-axis data values for line and bar charts.

Default: []

xaxisname

string

Label for the X-axis for line and bar charts.

yaxis

list / elements=list

List of Y-axis data series for line and bar charts.

Default: []

yaxiscolor

list / elements=string

Colors for the Y-axis data series for line and bar charts.

Default: []

yaxisname

list / elements=string

Labels for the Y-axis data series for line and bar charts.

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

changed

boolean

Indicates whether the chart image was successfully generated.

Returned: always

Sample: true

Authors

  • Marco Noce (@NomakCooper)