Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/teramako/playbook2uml
Create a PlantUML/Mermaid.js State Diagram from Ansible-Playbook
https://github.com/teramako/playbook2uml
Last synced: 6 days ago
JSON representation
Create a PlantUML/Mermaid.js State Diagram from Ansible-Playbook
- Host: GitHub
- URL: https://github.com/teramako/playbook2uml
- Owner: teramako
- License: mit
- Created: 2022-02-18T11:52:58.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-03-12T13:58:33.000Z (over 1 year ago)
- Last Synced: 2024-11-05T08:37:04.715Z (9 days ago)
- Language: Python
- Homepage:
- Size: 85.9 KB
- Stars: 19
- Watchers: 2
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# playbook2uml
Ansible-playbook/role to PlantUML or Mermaid.js diagram⚠️: Mermaid.js feature is *experimental* now.
## Usage
```
usage:
playbook2uml [options] PLAYBOOK
playbook2uml [options] -R ROLE_NAME [BASE_DIR]Ansible playbook/role to PlantUML or Mermaid.js diagram
optional arguments:
-h, --help show this help message and exit
-t {plantuml,mermaid}, --type {plantuml,mermaid}
The diagram type.[default=plantuml]
-T TITLE, --title TITLE
The title of the playbook/role
--theme THEME PlantUML theme
--left-to-right left to right direction
-v, --verbose Show information to STDERR. -v => INFO -vv => DEBUGPlaybook:
Generate a graph of the playbookPLAYBOOK playbook file
Role:
Generate a graph of the role only-R ROLE, --role ROLE The role name
--tasks-from TASKS_FROM
File to load from a role's tasks/ directory.
BASE_DIR The base directory.[default=current directory]
```### PlantUML
The PlantUML code is out to stdout.
```console
$ playbook2uml path/to/playbook.yml --title "hello_world.yml"
@startuml
title hello_world.yml
state "= Play: Hello playbook2uml" as play_1 {
play_1 : | hosts | localhost |
play_1 : | gather_facts | False |
state "== Hello playbook2uml" as task_1
task_1 : Action **debug**
task_1 : | msg | Hello ansible playbook to UML |
}
[*] --> task_1
task_1 --> [*]
@enduml
```You maybe pipe to a PlantUML server with `curl`.
```sh
playbook2uml path/to/playbook.yml --title "Sample 1" | \
curl --data-binary @- http://plantuml-server.example.com/svg/ -o - > path/to/foo.svg
```#### Output (PlantUML)
![plantuml svg](docs/img/sample_1.svg)
### Mermaid.js
```console
$ playbook2uml path/to/playbook.yml -t mermaid
stateDiagram-v2
state "Play: Sample 1" as play_1 {
state "Create directory
action: file" as task_1
block_1 : Execute python script
state block_1 {
state "Get python script from web
action: get_url" as task_2
block_1_always : Always
state block_1_always {
state "execute
action: command" as task_3
state task_4_when <>
note right of task_4_when
when
- exec_result.rc != 0
end note
state "debug
action: debug" as task_4
}
block_1_rescue : Rescue
state block_1_rescue {
state "Use local file
action: copy" as task_5
}
}
state "End Message
action: debug" as task_6
}
[*] --> task_1
task_1 --> task_2
task_2 --> task_3
task_3 --> task_4_when
task_4_when --> task_4
task_4 --> task_6
task_4_when --> task_6 : skip
task_5 --> task_3
task_6 --> [*]
```#### Output (Mermaid.js)
```mermaid
stateDiagram-v2
state "Play: Sample 1" as play_1 {
state "Create directory
action: file" as task_1
block_1 : Execute python script
state block_1 {
state "Get python script from web
action: get_url" as task_2
block_1_always : Always
state block_1_always {
state "execute
action: command" as task_3
state task_4_when <>
note right of task_4_when
when
- exec_result.rc != 0
end note
state "debug
action: debug" as task_4
}
block_1_rescue : Rescue
state block_1_rescue {
state "Use local file
action: copy" as task_5
}
}
state "End Message
action: debug" as task_6
}
[*] --> task_1
task_1 --> task_2
task_2 --> task_3
task_3 --> task_4_when
task_4_when --> task_4
task_4 --> task_6
task_4_when --> task_6 : skip
task_5 --> task_3
task_6 --> [*]
```## Requirements
- `ansible` >= 2.9
## Install
```sh
pip install git+https://github.com/teramako/playbook2uml
```