{"id":15089135,"url":"https://github.com/NomakCooper/charts","last_synced_at":"2025-10-08T06:32:18.967Z","repository":{"id":251965333,"uuid":"838555868","full_name":"NomakCooper/write_charts","owner":"NomakCooper","description":"Ansible Custom Module write_charts. Generate charts in image format on the ansible control node.","archived":false,"fork":false,"pushed_at":"2024-08-06T19:04:40.000Z","size":464,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-26T09:42:25.020Z","etag":null,"topics":["ansible-modules","chart","charts","plotly","python","yaml"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/NomakCooper.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-05T22:21:12.000Z","updated_at":"2024-08-06T19:04:44.000Z","dependencies_parsed_at":"2024-08-06T22:15:50.638Z","dependency_job_id":"95541809-9f32-4a50-a91b-7313a157e3d7","html_url":"https://github.com/NomakCooper/write_charts","commit_stats":null,"previous_names":["nomakcooper/write_charts"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NomakCooper%2Fwrite_charts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NomakCooper%2Fwrite_charts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NomakCooper%2Fwrite_charts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NomakCooper%2Fwrite_charts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NomakCooper","download_url":"https://codeload.github.com/NomakCooper/write_charts/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235688647,"owners_count":19029912,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ansible-modules","chart","charts","plotly","python","yaml"],"created_at":"2024-09-25T08:41:00.974Z","updated_at":"2025-10-08T06:32:18.960Z","avatar_url":"https://github.com/NomakCooper.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cmeta name=\"author\" content=\"Marco Noce\"\u003e\n\u003cmeta name=\"description\" content=\"Ansible write_charts generate charts in image format on the ansible control node.\"\u003e\n\u003cmeta name=\"copyright\" content=\"Marco Noce 2024\"\u003e\n\u003cmeta name=\"keywords\" content=\"ansible, module, write, charts, image\"\u003e\n\n\u003cdiv align=\"center\"\u003e\n\n![Ansible Custom Module][ansible-shield]\n![ansible charts][charts shield]\n![python][python-shield]\n![license][license-shield]\n\n\u003c/div\u003e\n\n---\n\n\u003e [!warning]\n\u003e **This repository has been archived. The module is available via Ansible galaxy collection [nomakcooper.collection](https://galaxy.ansible.com/ui/repo/published/nomakcooper/collection/).**\n---\n### charts ansible custom module\n\n#### Description : :information_source:\n\n\u003cb\u003echarts\u003c/b\u003e is a custom module for ansible that generate charts in image format on the ansible control node.\n\n#### Purpose : :eyes:\n\nThe purpose of this project is to use ansible's control node to generate charts in image format. \nTo do this, some of the functions of the Python Plotly library are used.\u003cbr\u003e\nThis module is very basic and uses only a few functions in comparison with the vast number of possibilities offered by the Plotly library.\n\n* [Official link Plotly Python]\n* [Official link Plotly Python GitHub]\n\nIt is currently possible to generate charts of this type:\n*  line\n*  bar\n*  pie\n*  donut\n\nIn images of these formats:\n*  png\n*  jpeg\n*  webp\n*  svg\n*  pdf\n*  eps\n\n#### Repo files: :open_file_folder:\n\n```\n├── /library                \n│   └── write_charts.py     ##\u003c-- python custom module\n```\n\n#### Requirements : :heavy_check_mark:\n\nFirst of all, in order to use this module you \u003cb\u003eMUST\u003c/b\u003e have installed the necessary library on your control node and/or in your environment.\u003cbr\u003e\n\nPython lib:\n*  Plotly\n*  Kaleido\n\nYou can install these libraries directly from \u003ccode\u003epip\u003c/code\u003e\u003cbr\u003e\nIf you have no way of modifying your control node or environment, you can install the libraries by the [pip module] directly via the playbook that will use this module.\n\nSAMPLE: :arrow_forward:\n```yaml\n  - name: Install plotly\n    become: false\n    ansible.builtin.pip:\n      name: plotly=6.0.0\n    delegate_to: localhost\n```\nYou can also install the libraries via \u003cb\u003e.whl\u003c/b\u003e files\n```yaml\n  - name: Install plotly\n    become: false\n    ansible.builtin.pip:\n      name: /tmp/plotly-6.0.0-py3-none-any.whl\n    delegate_to: localhost\n```\n\n#### Parameters : :clipboard:\n\n| Parameter      | Type      | Required | Sample                                      | Comment |\n|--------------|----------|----------|--------------------------------|----------------------------------------------------------------------------------------------------------------|\n| **titlechart**   | `str`    | ❌ No    | `\"CPU Usage Over Time\"`         | Title displayed at the top of the chart. |\n| **type**        | `str`    | ✅ Yes   | `\"line\"`                        | Type of chart. Options: `\"line\"`, `\"bar\"`, `\"pie\"`, `\"donut\"`. |\n| **xaxis**       | `list`   | ❌ No    | `[\"2025-02-06T12:10\", \"2025-02-06T12:20\"]` | X-axis data values (time or categories). |\n| **xaxisname**   | `str`    | ❌ No    | `\"Timestamp\"`                   | Label for the X-axis. |\n| **yaxis**       | `list`   | ❌ No    | `[[12.3, 14.5, 13.1], [5.2, 6.3, 5.8]]`  | List of Y-axis data series. |\n| **yaxisname**   | `list`   | ❌ No    | `[\"User %\", \"System %\"]`        | List of labels for Y-axis data series. |\n| **yaxiscolor**  | `list`   | ❌ No    | `[\"red\", \"blue\"]`               | Colors for each Y-axis series. |\n| **imgwidth**    | `int`    | ❌ No    | `1920`                           | Width of the output image (pixels). |\n| **imgheight**   | `int`    | ❌ No    | `1080`                           | Height of the output image (pixels). |\n| **shape_line**  | `str`    | ❌ No    | `\"spline\"`                       | Shape of lines in `line` charts. Options: `\"spline\"`, `\"linear\"`. |\n| **format**      | `str`    | ❌ No    | `\"png\"`                          | Output format. Options: `\"png\"`, `\"jpeg\"`, `\"webp\"`, `\"svg\"`, `\"pdf\"`, `\"eps\"`. |\n| **path**        | `str`    | ✅ Yes   | `\"/charts\"`                      | Directory where the chart image is saved. |\n| **filename**    | `str`    | ✅ Yes   | `\"cpu_usage\"`                    | Name of the saved image file (without extension). |\n| **fontsize**    | `int`    | ❌ No    | `20`                             | Font size for text elements. |\n| **fontcolor**   | `str`    | ❌ No    | `\"#333333\"`                      | Font color for all chart text. |\n| **titlelegend** | `str`    | ❌ No    | `\"CPU Breakdown\"`                | Title displayed for the legend. |\n| **slicedata**   | `list`   | ❌ No    | `[50, 30, 20]`                   | Values for `pie` or `donut` charts. |\n| **slicelabel**  | `list`   | ❌ No    | `[\"Cache\", \"Swap\", \"RAM\"]`       | Labels for `pie` or `donut` chart slices. |\n| **slicecolor**  | `list`   | ❌ No    | `[\"orange\", \"blue\", \"green\"]`    | Colors assigned to each slice in `pie` or `donut` charts. |\n| **sizehole**    | `float`  | ❌ No    | `0.5`                            | Size of the hole in a `donut` chart (`0` for `pie`). |\n\n#### Attributes : :clipboard:\n\n|Attribute |Support|Description                                                                         |\n|----------|-------|------------------------------------------------------------------------------------|\n|check_mode|full   |Can run in check_mode and return changed status prediction without modifying target.|\n\n#### EXAMPLES : :bar_chart:\n\n![line-chart][cpu-file]\nThis portion of code converts the load average data collected by sar using my other module sar_facts.\n```yaml\n    - name: Collect CPU Usage Data\n      sar_facts:\n        type: \"cpu\"\n        date_start: \"2025-02-06\"\n        date_end: \"2025-02-07\"\n\n    - name: Generate CPU Usage Line Chart\n      charts:\n        titlechart: \"CPU Usage Over Time (Multi-Day)\"\n        type: \"line\"\n        xaxis: \"{{ ansible_facts.sar_cpu | map(attribute='date') | zip(ansible_facts.sar_cpu | map(attribute='time')) | map('join', 'T') | list }}\"\n        xaxisname: \"Timestamp\"\n        yaxis:\n          - \"{{ ansible_facts.sar_cpu | selectattr('%user', 'defined') | map(attribute='%user') | map('float') | list }}\"\n          - \"{{ ansible_facts.sar_cpu | selectattr('%system', 'defined') | map(attribute='%system') | map('float') | list }}\"\n          - \"{{ ansible_facts.sar_cpu | selectattr('%idle', 'defined') | map(attribute='%idle') | map('float') | list }}\"\n        yaxisname: [\"User %\", \"System %\", \"Idle %\"]\n        yaxiscolor: [\"#FF5733\", \"#33A1FF\", \"#28A745\"]\n        imgwidth: 1920\n        imgheight: 1080\n        shape_line: \"spline\"\n        format: \"png\"\n        path: \"/tmp\"\n        filename: \"cpu_usage_chart_multi_day\"\n        titlelegend: \"CPU Breakdown\"\n      delegate_to: localhost\n```\n\n#### Return :\n\n*  This module return \u003ccode\u003e'changed': True\u003c/code\u003e\n\n|Key              |Type     |Sample |\n|-----------------|---------|-------|\n|changed          |boolean  |True   |                                                                               |\n\n## Integration\n\n1. Assuming you are in the root folder of your ansible project.\n\nSpecify a module path in your ansible configuration file.\n\n```shell\n$ vim ansible.cfg\n```\n```ini\n[defaults]\n...\nlibrary = ./library\n...\n```\n\nCreate the directory and copy the python modules into that directory\n\n```shell\n$ mkdir library\n$ cp path/to/module library\n```\n\n2. If you use Ansible AWX and have no way to edit the control node, you can add the /library directory to the same directory as the playbook .yml file\n\n```\n├── root repository\n│   ├── playbooks\n│   │    ├── /library                \n│   │    │   └── write_charts.py        ##\u003c-- python custom module\n│   │    └── your_playbook.yml          ##\u003c-- you playbook\n```   \n\n[ansible-shield]: https://img.shields.io/badge/Ansible-custom%20module-blue?style=for-the-badge\u0026logo=ansible\u0026logoColor=lightgrey\n[charts shield]: https://img.shields.io/badge/ansible-write_charts-blue?style=for-the-badge\u0026logo=ansible\u0026logoColor=white\n[python-shield]: https://img.shields.io/badge/python-blue?style=for-the-badge\u0026logo=python\u0026logoColor=yellow\n[license-shield]: https://img.shields.io/github/license/nomakcooper/svcs_attr_facts?style=for-the-badge\u0026label=LICENSE\n\n[Official link Plotly Python]: https://plotly.com/python/\n[Official link Plotly Python GitHub]: https://github.com/plotly/plotly.py\n\n[pip module]: https://docs.ansible.com/ansible/latest/collections/ansible/builtin/pip_module.html\n[sar]: https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/4/html/introduction_to_system_administration/s3-resource-tools-sar-sar#s3-resource-tools-sar-sar\n\n[cpu-file]: cpu_usage_chart_multi_day.png\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNomakCooper%2Fcharts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FNomakCooper%2Fcharts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNomakCooper%2Fcharts/lists"}