Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run Ansible Playbook Grapher against Meza #63

Open
freephile opened this issue Mar 17, 2024 · 7 comments
Open

Run Ansible Playbook Grapher against Meza #63

freephile opened this issue Mar 17, 2024 · 7 comments
Labels
ansible RedHat Ansible DevOps Work on the GitHub system or Deployments documentation Improvements or additions to documentation enhancement New feature or request

Comments

@freephile
Copy link
Owner

https://github.com/haidaraM/ansible-playbook-grapher

Run this and output either Graphiz png or possibly Mermaid charts that we can put on-wiki.

@freephile freephile added documentation Improvements or additions to documentation enhancement New feature or request ansible RedHat Ansible DevOps Work on the GitHub system or Deployments labels Mar 17, 2024
@freephile
Copy link
Owner Author

cd
python3 -m venv myenv
source myenv/bin/activate
pip install ansible-playbook-grapher

Errors with

Collecting ansible-core<2.16.4,>=2.15 (from ansible-playbook-grapher)
  Could not find a version that satisfies the requirement ansible-core<2.16.4,>=2.15 (from ansible-playbook-grapher) (from versions: 0.0.1a1, 2.11.0b1, 2.11.0b2, 2.11.0b3, 2.11.0b4, 2.11.0rc1, 2.11.0rc2, 2.11.0, 2.11.1rc1, 2.11.1, 2.11.2rc1, 2.11.2, 2.11.3rc1, 2.11.3, 2.11.4rc1, 2.11.4, 2.11.5rc1, 2.11.5, 2.11.6rc1, 2.11.6, 2.11.7rc1, 2.11.7, 2.11.8rc1, 2.11.8, 2.11.9rc1, 2.11.9, 2.11.10rc1, 2.11.10, 2.11.11rc1, 2.11.11, 2.11.12rc1, 2.11.12)
No matching distribution found for ansible-core<2.16.4,>=2.15 (from ansible-playbook-grapher)
You are using pip version 9.0.3, however version 24.0 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

Even though
ansible --version
outputs

ansible [core 2.15.3]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.11/site-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.11.5 (main, Oct 25 2023, 16:19:59) [GCC 8.5.0 20210514 (Red Hat 8.5.0-20)] (/usr/bin/python3.11)
  jinja version = 3.1.2
  libyaml = True

and
ansible-community --version
outputs
Ansible community version 8.3.0

pip list
outputs

DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
pip (9.0.3)
setuptools (39.2.0)
You are using pip version 9.0.3, however version 24.0 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

After upgrading pip (still in the venv)
pip install --upgrade pip
Successfully installed pip-21.3.1

I was able to install ansible playbook grapher

pip install ansible-playbook-grapher

@freephile
Copy link
Owner Author

From the config directory, I get an error because we use an old module that can't be determined.

[config]# ansible-playbook-grapher ../src/playbooks/site.yml

/root/myenv/lib64/python3.6/site-packages/ansible/parsing/vault/__init__.py:44: CryptographyDeprecationWarning: Python 3.6 is no longer supported by the Python core team. Therefore, support for it is deprecated in cryptography. The next release of cryptography will remove support for Python 3.6.
  from cryptography.exceptions import InvalidSignature
Parsing playbook ../src/playbooks/site.yml
Traceback (most recent call last):
  File "/root/myenv/bin/ansible-playbook-grapher", line 8, in <module>
    sys.exit(main())
  File "/root/myenv/lib64/python3.6/site-packages/ansibleplaybookgrapher/cli.py", line 269, in main
    cli.run()
  File "/root/myenv/lib64/python3.6/site-packages/ansibleplaybookgrapher/cli.py", line 65, in run
    group_roles_by_name=self.options.group_roles_by_name,
  File "/root/myenv/lib64/python3.6/site-packages/ansibleplaybookgrapher/graphbuilder.py", line 86, in parse
    playbook_node = parser.parse()
  File "/root/myenv/lib64/python3.6/site-packages/ansibleplaybookgrapher/parser.py", line 172, in parse
    variable_manager=self.variable_manager,
  File "/root/myenv/lib64/python3.6/site-packages/ansible/playbook/__init__.py", line 51, in load
    pb._load_playbook_data(file_name=file_name, variable_manager=variable_manager)
  File "/root/myenv/lib64/python3.6/site-packages/ansible/playbook/__init__.py", line 109, in _load_playbook_data
    entry_obj = Play.load(entry, variable_manager=variable_manager, loader=self._loader, vars=vars)
  File "/root/myenv/lib64/python3.6/site-packages/ansible/playbook/play.py", line 116, in load
    return p.load_data(data, variable_manager=variable_manager, loader=loader)
  File "/root/myenv/lib64/python3.6/site-packages/ansible/playbook/base.py", line 235, in load_data
    self._attributes[target_name] = method(name, ds[name])
  File "/root/myenv/lib64/python3.6/site-packages/ansible/playbook/play.py", line 202, in _load_roles
    roles.append(Role.load(ri, play=self))
  File "/root/myenv/lib64/python3.6/site-packages/ansible/playbook/role/__init__.py", line 175, in load
    r._load_role_data(role_include, parent_role=parent_role)
  File "/root/myenv/lib64/python3.6/site-packages/ansible/playbook/role/__init__.py", line 265, in _load_role_data
    self._task_blocks = load_list_of_blocks(task_data, play=self._play, role=self, loader=self._loader, variable_manager=self._variable_manager)
  File "/root/myenv/lib64/python3.6/site-packages/ansible/playbook/helpers.py", line 77, in load_list_of_blocks
    loader=loader,
  File "/root/myenv/lib64/python3.6/site-packages/ansible/playbook/block.py", line 95, in load
    return b.load_data(data, variable_manager=variable_manager, loader=loader)
  File "/root/myenv/lib64/python3.6/site-packages/ansible/playbook/base.py", line 235, in load_data
    self._attributes[target_name] = method(name, ds[name])
  File "/root/myenv/lib64/python3.6/site-packages/ansible/playbook/block.py", line 131, in _load_block
    use_handlers=self._use_handlers,
  File "/root/myenv/lib64/python3.6/site-packages/ansible/playbook/helpers.py", line 366, in load_list_of_tasks
    t = Task.load(task_ds, block=block, role=role, task_include=task_include, variable_manager=variable_manager, loader=loader)
  File "/root/myenv/lib64/python3.6/site-packages/ansible/playbook/task.py", line 152, in load
    return t.load_data(data, variable_manager=variable_manager, loader=loader)
  File "/root/myenv/lib64/python3.6/site-packages/ansible/playbook/base.py", line 222, in load_data
    ds = self.preprocess_data(ds)
  File "/root/myenv/lib64/python3.6/site-packages/ansible/playbook/task.py", line 220, in preprocess_data
    (action, args, delegate_to) = args_parser.parse()
  File "/root/myenv/lib64/python3.6/site-packages/ansible/parsing/mod_args.py", line 333, in parse
    obj=self._task_ds)
ansible.errors.AnsibleParserError: couldn't resolve module/action 'authorized_key'. This often indicates a misspelling, missing collection, or incorrect module path.

The error appears to be in '/opt/meza/src/roles/base/tasks/main.yml': line 37, column 3, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:


- name: Set authorized key for alt-meza-ansible
  ^ here

@freephile
Copy link
Owner Author

I tried to work through the errors with the following, but still ended up deactivating the venv because the create command accidentally used system python instead of python3.11 which is erroneously??? reported by ansible --version in the VSCode terminal

ansible-galaxy collection list
ansible-galaxy collection install ansible.posix
ansible-galaxy collection install community.general
deactivate

@freephile
Copy link
Owner Author

freephile commented Mar 26, 2024

# create a Python 3.11 virtual environment in root's home directory
cd
python3.11 -m venv myenv
source myenv/bin/activate

# upgrade PIP
pip install --upgrade pip

# install Ansible Playbook Grapher
pip install ansible-playbook-grapher

# install the collections required by Meza
ansible-galaxy collection install ansible.posix
ansible-galaxy collection install community.general
ansible-galaxy collection install gluster.gluster
ansible-galaxy collection install community.mysql

# change to Meza's config directory to graph our site playbook
cd /opt/meza/config
ansible-playbook-grapher ../src/playbooks/site.yml


# finally, deactivate our Virtual Environment
deactivate

In this Virtual Environment, it shows Python 3.11 being used and maybe Ansible Core 2.16.3

 ansible --version
ansible [core 2.16.3]
  config file = /opt/meza/config/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /root/myenv/lib64/python3.11/site-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /root/myenv/bin/ansible
  python version = 3.11.5 (main, Oct 25 2023, 16:19:59) [GCC 8.5.0 20210514 (Red Hat 8.5.0-20)] (/root/myenv/bin/python3.11)
  jinja version = 3.1.3
  libyaml = True

@freephile
Copy link
Owner Author

site

@freephile
Copy link
Owner Author

ansible-playbook-grapher --include-role-tasks ../src/playbooks/site.yml
site

@freephile
Copy link
Owner Author

freephile commented Mar 26, 2024

This should be refined so that

  • the generated SVG (and dot) files can be added to the source tree
  • possibly use the output protocol handler to make the node links open in VSCode or GitHub
  • diagrams are generated for all playbooks, not just 'site.yml'
  • diagrams are generated for Mermaid, and imported into a Meza wiki

BUT The site diagram shows just how big and monolithic the system is. The real action item is to make the whole system much more modular and composable so that it's not a directed graph of 742 nodes.

@freephile freephile added this to the Documentation, Roadmap milestone Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ansible RedHat Ansible DevOps Work on the GitHub system or Deployments documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant