mirror of
https://github.com/haidaraM/ansible-playbook-grapher
synced 2024-11-10 06:04:15 +00:00
fix: remove some workaround about ansible 2.8 and update docs
This commit is contained in:
parent
9205d824a4
commit
4ce09488c9
4 changed files with 15 additions and 18 deletions
5
Makefile
5
Makefile
|
@ -23,10 +23,7 @@ test_install: build
|
|||
@./test_install.sh $(VIRTUALENV_DIR) $(ANSIBLE_VERSION)
|
||||
|
||||
test:
|
||||
# Ansible 2.8 CLI sets some global variables causing the tests to fail if the cli tests are run before
|
||||
# the grapher tests. It works in Ansible 2.9. So here we explicitly set the tests order.
|
||||
# TODO: Remove pytest arguments when we drop support for Ansible 2.8
|
||||
cd tests && pytest test_grapher.py test_cli.py test_postprocessor.py
|
||||
cd tests && pytest
|
||||
|
||||
clean:
|
||||
@echo "Cleaning..."
|
||||
|
|
|
@ -11,8 +11,8 @@ Inspired by [Ansible Inventory Grapher](https://github.com/willthames/ansible-in
|
|||
|
||||
## Prerequisites
|
||||
- Python 3
|
||||
- **Ansible** >= 2.8: If you still use an older version of Ansible, create a virtual environment and install ansible-playbook-grapher.
|
||||
**pip will install a version of Ansible >= 2.8 if not already installed.** I try to respect [Red Hat Ansible Engine Life Cycle](https://access.redhat.com/support/policy/updates/ansible-engine) for the supported Ansible version.
|
||||
- **Ansible** >= 2.9: If you still use an older version of Ansible, create a virtual environment and install ansible-playbook-grapher.
|
||||
**pip will install a version of Ansible >= 2.9 if not already installed.** I try to respect [Red Hat Ansible Engine Life Cycle](https://access.redhat.com/support/policy/updates/ansible-engine) for the supported Ansible version.
|
||||
- **Graphviz**: The tool used to generate the graph in SVG.
|
||||
```shell script
|
||||
$ sudo apt-get install graphviz # or yum install or brew install
|
||||
|
|
|
@ -4,6 +4,7 @@ import sys
|
|||
from abc import ABC
|
||||
|
||||
from ansible.cli import CLI
|
||||
from ansible.cli.arguments import option_helpers
|
||||
from ansible.release import __version__ as ansible_version
|
||||
from ansible.utils.display import Display
|
||||
from packaging import version
|
||||
|
@ -12,7 +13,7 @@ from ansibleplaybookgrapher import __prog__, __version__
|
|||
from ansibleplaybookgrapher.grapher import PlaybookGrapher
|
||||
from ansibleplaybookgrapher.postprocessor import PostProcessor
|
||||
|
||||
# We need to know if we are using ansible 2.8 because the CLI has been refactored in
|
||||
# At some time, we needed to know if we are using ansible 2.8 because the CLI has been refactored in this PR:
|
||||
# https://github.com/ansible/ansible/pull/50069
|
||||
IS_ANSIBLE_2_9_X = version.parse(ansible_version) >= version.parse("2.9")
|
||||
|
||||
|
@ -59,14 +60,14 @@ class GrapherCLI(CLI, ABC):
|
|||
|
||||
class PlaybookGrapherCLI(GrapherCLI):
|
||||
"""
|
||||
The dedicated playbook CLI for Ansible 2.9 and above.
|
||||
Note: Use this class as the main CLI when we drop support for ansible < 2.9
|
||||
The dedicated playbook CLI for Ansible 2.9 and above (for the moment)
|
||||
"""
|
||||
|
||||
def __init__(self, args, callback=None):
|
||||
super(PlaybookGrapherCLI, self).__init__(args=args, callback=callback)
|
||||
# we keep the old options as instance attribute for backward compatibility for the grapher
|
||||
# Ansible 2.8 has removed it and use a global context instead
|
||||
# We keep the old options as instance attribute for backward compatibility for the grapher CLI.
|
||||
# From Ansible 2.8, they remove this instance attribute 'options' and use a global context instead.
|
||||
# But this may change in the future: https://github.com/ansible/ansible/blob/bcb64054edaa7cf636bd38b8ab0259f6fb93f3f9/lib/ansible/context.py#L8
|
||||
self.options = None
|
||||
|
||||
def _add_my_options(self):
|
||||
|
@ -94,18 +95,17 @@ class PlaybookGrapherCLI(GrapherCLI):
|
|||
|
||||
self.parser.add_argument('playbook_filename', help='Playbook to graph', metavar='playbook')
|
||||
|
||||
# Use ansible helper to add some default options also
|
||||
option_helpers.add_subset_options(self.parser)
|
||||
option_helpers.add_vault_options(self.parser)
|
||||
option_helpers.add_runtask_options(self.parser)
|
||||
|
||||
def init_parser(self, usage="", desc=None, epilog=None):
|
||||
super(PlaybookGrapherCLI, self).init_parser(usage="%s [options] playbook.yml" % __prog__,
|
||||
desc="Make graphs from your Ansible Playbooks.", epilog=epilog)
|
||||
|
||||
self._add_my_options()
|
||||
|
||||
# add ansible specific options
|
||||
from ansible.cli.arguments import option_helpers as opt_help
|
||||
opt_help.add_subset_options(self.parser)
|
||||
opt_help.add_vault_options(self.parser)
|
||||
opt_help.add_runtask_options(self.parser)
|
||||
|
||||
def post_process_args(self, options):
|
||||
options = super(PlaybookGrapherCLI, self).post_process_args(options)
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
ansible>=2.8.0
|
||||
ansible>=2.9.0
|
||||
graphviz<1
|
||||
colour<1
|
||||
lxml<5
|
||||
|
|
Loading…
Reference in a new issue