haidaraM / ansible-playbook-grapher

A command line tool to create a graph representing your Ansible playbook tasks and roles
GNU General Public License v3.0
622 stars 53 forks source link

Docs express the use of --include-role-tasks - But option produces [WARNING] #198

Open shaneholloman opened 1 week ago

shaneholloman commented 1 week ago

Is this a temporary version issue?

example:

ansible-playbook-grapher --renderer mermaid-flowchart --include-role-tasks '/home/shadmin/cello
/ansible/playbooks/families/debian/server_rad.yml'

Produces:

Parsing playbook /home/shadmin/Dropbox/cello/ansible/playbooks/families/debian/server_rad.yml
[WARNING]: Looping on tasks or roles are not supported for the moment. Only the task having the loop argument will be added to the
graph.
Traceback (most recent call last):
  File "/home/shadmin/.local/bin/ansible-playbook-grapher", line 8, in <module>
    sys.exit(main())
  File "/home/shadmin/.local/lib/python3.10/site-packages/ansibleplaybookgrapher/cli.py", line 302, in main
    cli.run()
  File "/home/shadmin/.local/lib/python3.10/site-packages/ansibleplaybookgrapher/cli.py", line 61, in run
    playbook_nodes, roles_usage = grapher.parse(
  File "/home/shadmin/.local/lib/python3.10/site-packages/ansibleplaybookgrapher/grapher.py", line 61, in parse
    playbook_node = playbook_parser.parse()
  File "/home/shadmin/.local/lib/python3.10/site-packages/ansibleplaybookgrapher/parser.py", line 257, in parse
    self._include_tasks_in_blocks(
  File "/home/shadmin/.local/lib/python3.10/site-packages/ansibleplaybookgrapher/parser.py", line 491, in _include_tasks_in_blocks
    self._add_task(
  File "/home/shadmin/.local/lib/python3.10/site-packages/ansibleplaybookgrapher/parser.py", line 118, in _add_task
    node=TaskNode(
  File "/home/shadmin/.local/lib/python3.10/site-packages/ansibleplaybookgrapher/graph_model.py", line 468, in __init__
    super().__init__(
  File "/home/shadmin/.local/lib/python3.10/site-packages/ansibleplaybookgrapher/graph_model.py", line 69, in __init__
    self.set_position()
  File "/home/shadmin/.local/lib/python3.10/site-packages/ansibleplaybookgrapher/graph_model.py", line 80, in set_position
    self.path, self.line, self.column = self.raw_object.get_ds().ansible_pos
AttributeError: 'dict' object has no attribute 'ansible_pos'

Whereas this is fine:

ansible-playbook-grapher --renderer mermaid-flowchart  '/home/shadmin/cello
/ansible/playbooks/families/debian/server_rad.yml'

otherwise the app appears to work as expected...

Mermaid Testing

---
title: Ansible Playbook Grapher
---
%%{ init: { "flowchart": { "curve": "bumpX" } } }%%
flowchart LR
 %% Start of the playbook '/home/shadmin/Dropbox/cello/ansible/playbooks/families/debian/server_rad.yml'
 playbook_0ad1ad49("/home/shadmin/Dropbox/cello/ansible/playbooks/families/debian/server_rad.yml")
  %% Start of the play 'Play: Cello Ubuntu Base (16)'
  play_a7ebce7c["Play: Cello Ubuntu Base (16)"]
  style play_a7ebce7c fill:#13be0e,color:#ffffff
  playbook_0ad1ad49 --> |"1"| play_a7ebce7c
  linkStyle 0 stroke:#13be0e,color:#13be0e
   pre_task_aa0c5f4c["[pre_task]  Pre Tasks | On this Control node - SSH Remove old key"]
   style pre_task_aa0c5f4c stroke:#13be0e,fill:#ffffff
   play_a7ebce7c --> |"1"| pre_task_aa0c5f4c
   linkStyle 1 stroke:#13be0e,color:#13be0e
   pre_task_2bfa7c71["[pre_task]  Pre Tasks | Include vars from falcon.vault"]
   style pre_task_2bfa7c71 stroke:#13be0e,fill:#ffffff
   play_a7ebce7c --> |"2"| pre_task_2bfa7c71
   linkStyle 2 stroke:#13be0e,color:#13be0e
   pre_task_de08b090["[pre_task]  Pre Tasks | Include vars from qualys.vault"]
   style pre_task_de08b090 stroke:#13be0e,fill:#ffffff
   play_a7ebce7c --> |"3"| pre_task_de08b090
   linkStyle 3 stroke:#13be0e,color:#13be0e
   pre_task_03531290["[pre_task]  Pre Tasks | Include vars from ops.vault"]
   style pre_task_03531290 stroke:#13be0e,fill:#ffffff
   play_a7ebce7c --> |"4"| pre_task_03531290
   linkStyle 4 stroke:#13be0e,color:#13be0e
   pre_task_c894fedc["[pre_task]  Pre Tasks | Include vars from sssd.vault"]
   style pre_task_c894fedc stroke:#13be0e,fill:#ffffff
   play_a7ebce7c --> |"5"| pre_task_c894fedc
   linkStyle 5 stroke:#13be0e,color:#13be0e
   pre_task_282bcd1d["[pre_task]  Pre Tasks | Check if reboot is required (Debian)"]
   style pre_task_282bcd1d stroke:#13be0e,fill:#ffffff
   play_a7ebce7c --> |"6"| pre_task_282bcd1d
   linkStyle 6 stroke:#13be0e,color:#13be0e
   pre_task_3d4ea681["[pre_task]  Pre Tasks | Set ansible_reboot_pending fact"]
   style pre_task_3d4ea681 stroke:#13be0e,fill:#ffffff
   play_a7ebce7c --> |"7 [when: ansible_os_family == 'Debian']"| pre_task_3d4ea681
   linkStyle 7 stroke:#13be0e,color:#13be0e
   pre_task_29e5948c["[pre_task]  Pre Tasks | Ensure a good state and reboot if required"]
   style pre_task_29e5948c stroke:#13be0e,fill:#ffffff
   play_a7ebce7c --> |"8 [when: ansible_reboot_pending | bool]"| pre_task_29e5948c
   linkStyle 8 stroke:#13be0e,color:#13be0e
   pre_task_5a544743["[pre_task]  Pre Tasks | Gather facts again after reboot"]
   style pre_task_5a544743 stroke:#13be0e,fill:#ffffff
   play_a7ebce7c --> |"9 [when: reboot_result.reboot_required | default(false)]"| pre_task_5a544743
   linkStyle 9 stroke:#13be0e,color:#13be0e
   pre_task_60a55c7f["[pre_task]  Pre Tasks | Check for Python3 on remote host"]
   style pre_task_60a55c7f stroke:#13be0e,fill:#ffffff
   play_a7ebce7c --> |"10"| pre_task_60a55c7f
   linkStyle 10 stroke:#13be0e,color:#13be0e
   pre_task_b76517c0["[pre_task]  Pre Tasks | Create 'ops' group"]
   style pre_task_b76517c0 stroke:#13be0e,fill:#ffffff
   play_a7ebce7c --> |"11"| pre_task_b76517c0
   linkStyle 11 stroke:#13be0e,color:#13be0e
   pre_task_625462cb["[pre_task]  Pre Tasks | Create 'ops' user with sudo privileges"]
   style pre_task_625462cb stroke:#13be0e,fill:#ffffff
   play_a7ebce7c --> |"12"| pre_task_625462cb
   linkStyle 12 stroke:#13be0e,color:#13be0e
   pre_task_b20e1b04["[pre_task]  Pre Tasks | Ensure 'ops' user and group have sudo privileges"]
   style pre_task_b20e1b04 stroke:#13be0e,fill:#ffffff
   play_a7ebce7c --> |"13"| pre_task_b20e1b04
   linkStyle 13 stroke:#13be0e,color:#13be0e
   pre_task_14b4a63b["[pre_task]  Pre Tasks | Copy SSH keys from pubkeys text list from vars to 'ops' user"]
   style pre_task_14b4a63b stroke:#13be0e,fill:#ffffff
   play_a7ebce7c --> |"14"| pre_task_14b4a63b
   linkStyle 14 stroke:#13be0e,color:#13be0e
   pre_task_02823ef3["[pre_task]  Pre Tasks | Copy Control Node SSH key from pubkey file"]
   style pre_task_02823ef3 stroke:#13be0e,fill:#ffffff
   play_a7ebce7c --> |"15"| pre_task_02823ef3
   linkStyle 15 stroke:#13be0e,color:#13be0e
   pre_task_db555244["[pre_task]  Pre Tasks | Find primary network interface"]
   style pre_task_db555244 stroke:#13be0e,fill:#ffffff
   play_a7ebce7c --> |"16"| pre_task_db555244
   linkStyle 16 stroke:#13be0e,color:#13be0e
   pre_task_9331957b["[pre_task]  Pre Tasks | Ensure cloud.cfg.d directory exists"]
   style pre_task_9331957b stroke:#13be0e,fill:#ffffff
   play_a7ebce7c --> |"17"| pre_task_9331957b
   linkStyle 17 stroke:#13be0e,color:#13be0e
   pre_task_c7c0ad4c["[pre_task]  Pre Tasks | Disable cloud-init's bootstrap network configuration"]
   style pre_task_c7c0ad4c stroke:#13be0e,fill:#ffffff
   play_a7ebce7c --> |"18"| pre_task_c7c0ad4c
   linkStyle 18 stroke:#13be0e,color:#13be0e
   pre_task_9a1995c2["[pre_task]  Pre Tasks | Netplan Replace 50-cloud-init configuration"]
   style pre_task_9a1995c2 stroke:#13be0e,fill:#ffffff
   play_a7ebce7c --> |"19 [when: redefine_networking | default(false) | bool]"| pre_task_9a1995c2
   linkStyle 19 stroke:#13be0e,color:#13be0e
   pre_task_a022aeab["[pre_task]  Pre Tasks | Netplan Ensure 50-cloud-init configuration is absent"]
   style pre_task_a022aeab stroke:#13be0e,fill:#ffffff
   play_a7ebce7c --> |"20 [when: not (redefine_networking | default(false) | bool)]"| pre_task_a022aeab
   linkStyle 20 stroke:#13be0e,color:#13be0e
   pre_task_c398b183["[pre_task]  Pre Tasks | Netplan Set file permissions to 600 on /etc/netplan/*"]
   style pre_task_c398b183 stroke:#13be0e,fill:#ffffff
   play_a7ebce7c --> |"21"| pre_task_c398b183
   linkStyle 21 stroke:#13be0e,color:#13be0e
   pre_task_94131b8f["[pre_task]  Pre Tasks | Netplan Set file permissions and ownership"]
   style pre_task_94131b8f stroke:#13be0e,fill:#ffffff
   play_a7ebce7c --> |"22"| pre_task_94131b8f
   linkStyle 22 stroke:#13be0e,color:#13be0e
   pre_task_51592284["[pre_task]  Pre Tasks | Netplan Apply configuration"]
   style pre_task_51592284 stroke:#13be0e,fill:#ffffff
   play_a7ebce7c --> |"23"| pre_task_51592284
   linkStyle 23 stroke:#13be0e,color:#13be0e
   pre_task_031ec242["[pre_task]  Pre Tasks | Netplan Apply configuration"]
   style pre_task_031ec242 stroke:#13be0e,fill:#ffffff
   play_a7ebce7c --> |"24"| pre_task_031ec242
   linkStyle 24 stroke:#13be0e,color:#13be0e
   pre_task_c328227b["[pre_task]  Pre Tasks | Blacklist i2c_piix4"]
   style pre_task_c328227b stroke:#13be0e,fill:#ffffff
   play_a7ebce7c --> |"25 [when: ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu' or ansible_distribution == 'RedHat']"| pre_task_c328227b
   linkStyle 25 stroke:#13be0e,color:#13be0e
   %% Start of the role 'shaneholloman.bootstrap'
   play_a7ebce7c --> |"26"| role_9763c196
   linkStyle 26 stroke:#13be0e,color:#13be0e
   role_9763c196("[role] shaneholloman.bootstrap")
   style role_9763c196 fill:#13be0e,color:#ffffff,stroke:#13be0e
   %% End of the role 'shaneholloman.bootstrap'
   %% Start of the role 'sh.core'
   play_a7ebce7c --> |"27"| role_192d0270
   linkStyle 27 stroke:#13be0e,color:#13be0e
   role_192d0270("[role] sh.core")
   style role_192d0270 fill:#13be0e,color:#ffffff,stroke:#13be0e
   %% End of the role 'sh.core'
   %% Start of the role 'sh.update'
   play_a7ebce7c --> |"28"| role_206d2709
   linkStyle 28 stroke:#13be0e,color:#13be0e
   role_206d2709("[role] sh.update")
   style role_206d2709 fill:#13be0e,color:#ffffff,stroke:#13be0e
   %% End of the role 'sh.update'
   %% Start of the role 'sh.hostname'
   play_a7ebce7c --> |"29"| role_69e36d2e
   linkStyle 29 stroke:#13be0e,color:#13be0e
   role_69e36d2e("[role] sh.hostname")
   style role_69e36d2e fill:#13be0e,color:#ffffff,stroke:#13be0e
   %% End of the role 'sh.hostname'
   %% Start of the role 'shaneholloman.ntpsec'
   play_a7ebce7c --> |"30"| role_0dedd114
   linkStyle 30 stroke:#13be0e,color:#13be0e
   role_0dedd114("[role] shaneholloman.ntpsec")
   style role_0dedd114 fill:#13be0e,color:#ffffff,stroke:#13be0e
   %% End of the role 'shaneholloman.ntpsec'
   %% Start of the role 'sh.certs'
   play_a7ebce7c --> |"31"| role_5d48d57f
   linkStyle 31 stroke:#13be0e,color:#13be0e
   role_5d48d57f("[role] sh.certs")
   style role_5d48d57f fill:#13be0e,color:#ffffff,stroke:#13be0e
   %% End of the role 'sh.certs'
   %% Start of the role 'sh.sssd'
   play_a7ebce7c --> |"32"| role_28b78659
   linkStyle 32 stroke:#13be0e,color:#13be0e
   role_28b78659("[role] sh.sssd")
   style role_28b78659 fill:#13be0e,color:#ffffff,stroke:#13be0e
   %% End of the role 'sh.sssd'
   %% Start of the role 'sh.qualys'
   play_a7ebce7c --> |"33"| role_dd954eb5
   linkStyle 33 stroke:#13be0e,color:#13be0e
   role_dd954eb5("[role] sh.qualys")
   style role_dd954eb5 fill:#13be0e,color:#ffffff,stroke:#13be0e
   %% End of the role 'sh.qualys'
   %% Start of the role 'crowdstrike.falcon.falcon_install'
   play_a7ebce7c --> |"34"| role_876c066b
   linkStyle 34 stroke:#13be0e,color:#13be0e
   role_876c066b("[role] crowdstrike.falcon.falcon_install")
   style role_876c066b fill:#13be0e,color:#ffffff,stroke:#13be0e
   %% End of the role 'crowdstrike.falcon.falcon_install'
   %% Start of the role 'crowdstrike.falcon.falcon_configure'
   play_a7ebce7c --> |"35"| role_8cc1387d
   linkStyle 35 stroke:#13be0e,color:#13be0e
   role_8cc1387d("[role] crowdstrike.falcon.falcon_configure")
   style role_8cc1387d fill:#13be0e,color:#ffffff,stroke:#13be0e
   %% End of the role 'crowdstrike.falcon.falcon_configure'
   %% Start of the role 'sh.cron'
   play_a7ebce7c --> |"36"| role_b482e119
   linkStyle 36 stroke:#13be0e,color:#13be0e
   role_b482e119("[role] sh.cron")
   style role_b482e119 fill:#13be0e,color:#ffffff,stroke:#13be0e
   %% End of the role 'sh.cron'
   post_task_7e3839ed["[post_task]  Post Tasks | Get the contents of the sudoers file"]
   style post_task_7e3839ed stroke:#13be0e,fill:#ffffff
   play_a7ebce7c --> |"37"| post_task_7e3839ed
   linkStyle 37 stroke:#13be0e,color:#13be0e
   post_task_c216372b["[post_task]  Post Tasks | Print the contents of the sudoers file"]
   style post_task_c216372b stroke:#13be0e,fill:#ffffff
   play_a7ebce7c --> |"38"| post_task_c216372b
   linkStyle 38 stroke:#13be0e,color:#13be0e
   post_task_9fb5ba14["[post_task]  Install cockpit"]
   style post_task_9fb5ba14 stroke:#13be0e,fill:#ffffff
   play_a7ebce7c --> |"39 [when: ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu' or ansible_distribution == 'RedHat']"| post_task_9fb5ba14
   linkStyle 39 stroke:#13be0e,color:#13be0e
   post_task_877776bb["[post_task]  Enable cockpit"]
   style post_task_877776bb stroke:#13be0e,fill:#ffffff
   play_a7ebce7c --> |"40 [when: ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu' or ansible_distribution == 'RedHat']"| post_task_877776bb
   linkStyle 40 stroke:#13be0e,color:#13be0e
   post_task_babe5f70["[post_task]  Show cockpit url"]
   style post_task_babe5f70 stroke:#13be0e,fill:#ffffff
   play_a7ebce7c --> |"41 [when: ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu' or ansible_distribution == 'RedHat']"| post_task_babe5f70
   linkStyle 41 stroke:#13be0e,color:#13be0e
   post_task_97d7ae2e["[post_task]  Check if reboot is required (Debian)"]
   style post_task_97d7ae2e stroke:#13be0e,fill:#ffffff
   play_a7ebce7c --> |"42"| post_task_97d7ae2e
   linkStyle 42 stroke:#13be0e,color:#13be0e
   post_task_a3c9dc34["[post_task]  Set ansible_reboot_pending fact"]
   style post_task_a3c9dc34 stroke:#13be0e,fill:#ffffff
   play_a7ebce7c --> |"43 [when: ansible_os_family == 'Debian']"| post_task_a3c9dc34
   linkStyle 43 stroke:#13be0e,color:#13be0e
   post_task_bdfed6b6["[post_task]  Ensure a good state and reboot if required"]
   style post_task_bdfed6b6 stroke:#13be0e,fill:#ffffff
   play_a7ebce7c --> |"44 [when: ansible_reboot_pending | bool]"| post_task_bdfed6b6
   linkStyle 44 stroke:#13be0e,color:#13be0e
   post_task_2d964a6b["[post_task]  Show message if playbook completed with out issue"]
   style post_task_2d964a6b stroke:#13be0e,fill:#ffffff
   play_a7ebce7c --> |"45 [when: reboot_result.reboot_required | default(false)]"| post_task_2d964a6b
   linkStyle 45 stroke:#13be0e,color:#13be0e
  %% End of the play 'Play: Cello Ubuntu Base (16)'
  %% Start of the play 'Play: Create VM Snapshot (16)'
  play_358a88f9["Play: Create VM Snapshot (16)"]
  style play_358a88f9 fill:#3c2d9f,color:#ffffff
  playbook_0ad1ad49 --> |"2"| play_358a88f9
  linkStyle 46 stroke:#3c2d9f,color:#3c2d9f
   task_324521f8["[task]  Take snapshot of the VM"]
   style task_324521f8 stroke:#3c2d9f,fill:#ffffff
   play_358a88f9 --> |"1"| task_324521f8
   linkStyle 47 stroke:#3c2d9f,color:#3c2d9f
  %% End of the play 'Play: Create VM Snapshot (16)'
  %% Start of the play 'Play: Install Radiator Server Stack (16)'
  play_f8f4a94d["Play: Install Radiator Server Stack (16)"]
  style play_f8f4a94d fill:#c4080a,color:#ffffff
  playbook_0ad1ad49 --> |"3"| play_f8f4a94d
  linkStyle 48 stroke:#c4080a,color:#c4080a
   pre_task_fbf58250["[pre_task]  Pre Tasks | Gather Facts"]
   style pre_task_fbf58250 stroke:#c4080a,fill:#ffffff
   play_f8f4a94d --> |"1"| pre_task_fbf58250
   linkStyle 49 stroke:#c4080a,color:#c4080a
   pre_task_d1e74d15["[pre_task]  Pre Tasks | Include vars from ops.vault"]
   style pre_task_d1e74d15 stroke:#c4080a,fill:#ffffff
   play_f8f4a94d --> |"2"| pre_task_d1e74d15
   linkStyle 50 stroke:#c4080a,color:#c4080a
   pre_task_4a869188["[pre_task]  Pre Tasks | Include vars from ops.vault"]
   style pre_task_4a869188 stroke:#c4080a,fill:#ffffff
   play_f8f4a94d --> |"3"| pre_task_4a869188
   linkStyle 51 stroke:#c4080a,color:#c4080a
   %% Start of the role 'sh.radiator'
   play_f8f4a94d --> |"4"| role_2bba884f
   linkStyle 52 stroke:#c4080a,color:#c4080a
   role_2bba884f("[role] sh.radiator")
   style role_2bba884f fill:#c4080a,color:#ffffff,stroke:#c4080a
   %% End of the role 'sh.radiator'
  %% End of the play 'Play: Install Radiator Server Stack (16)'
 %% End of the playbook '/home/shadmin/Dropbox/cello/ansible/playbooks/families/debian/server_rad.yml'
haidaraM commented 1 week ago

Likely a versioning issue. Can you show the output of ansible-playbook-grapher --version?

shaneholloman commented 1 week ago

ansible-playbook-grapher --version

shadmin @ kea ❯ radiator-maintenance ❯ main ❯ ansible-playbook-grapher --version
ansible-playbook-grapher 2.2.1 (with ansible 2.17.0)
shadmin @ kea ❯ radiator-maintenance ❯ main ❯ 

I installed using:

# Install the version from the main branch
pip install "ansible-playbook-grapher @ git+https://github.com/haidaraM/ansible-playbook-grapher"
haidaraM commented 1 week ago

Cannot reproduce this locally.

Can you provide the smallest playbook that is giving you the error?