Adding Netbox
This commit is contained in:
53
roles/ansible-network.network-engine/.github/ISSUE_TEMPLATE.md
vendored
Normal file
53
roles/ansible-network.network-engine/.github/ISSUE_TEMPLATE.md
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
<!---
|
||||
Verify first that your issue/request is not already reported on GitHub.
|
||||
Test if the latest release, and devel branch are affected too.-->
|
||||
|
||||
# ISSUE TYPE
|
||||
|
||||
<!--- Pick one below and delete the rest -->
|
||||
|
||||
- Bug Report
|
||||
- Feature Idea
|
||||
- Documentation Report
|
||||
|
||||
# ANSIBLE VERSION
|
||||
|
||||
```
|
||||
ansible --version
|
||||
|
||||
ansible-galaxy list | grep ansible.network
|
||||
```
|
||||
|
||||
# Network OS
|
||||
|
||||
- Operating System (inc version) of machine running Ansible
|
||||
- Network device make/model, including version
|
||||
|
||||
# SUMMARY
|
||||
|
||||
<!--- Explain the problem briefly -->
|
||||
|
||||
# STEPS TO REPRODUCE
|
||||
|
||||
<!--- For bugs, show exactly how to reproduce the problem, using a minimal test-case.
|
||||
For new features, show how the feature would be used.
|
||||
Paste example playbooks or commands between quotes below -->
|
||||
|
||||
```yaml
|
||||
|
||||
```
|
||||
|
||||
<!--- You can also paste gist.github.com links for larger files -->
|
||||
|
||||
# EXPECTED RESULTS
|
||||
|
||||
<!--- What did you expect to happen when running the steps above? -->
|
||||
|
||||
# ACTUAL RESULTS
|
||||
|
||||
<!--- What actually happened? If possible run with extra verbosity (ansible-playbook -vvvv ...)
|
||||
Paste verbatim command output between quotes below -->
|
||||
|
||||
```
|
||||
|
||||
```
|
||||
5
roles/ansible-network.network-engine/.gitignore
vendored
Normal file
5
roles/ansible-network.network-engine/.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
*.py[co]
|
||||
*.swp
|
||||
*.swo
|
||||
*.bak
|
||||
.tox
|
||||
14
roles/ansible-network.network-engine/.yamllint
Normal file
14
roles/ansible-network.network-engine/.yamllint
Normal file
@@ -0,0 +1,14 @@
|
||||
extends: default
|
||||
|
||||
ignore: |
|
||||
.git/
|
||||
.tox/
|
||||
|
||||
rules:
|
||||
braces:
|
||||
max-spaces-inside: 1
|
||||
level: error
|
||||
brackets:
|
||||
max-spaces-inside: 1
|
||||
level: error
|
||||
line-length: disable
|
||||
29
roles/ansible-network.network-engine/ANNOUNCE.md
Normal file
29
roles/ansible-network.network-engine/ANNOUNCE.md
Normal file
@@ -0,0 +1,29 @@
|
||||
Ansible Network: Network Engine Release
|
||||
----------------------------------------
|
||||
|
||||
The Ansible Network team is pleased to announce that the initial release of the Network Engine Ansible role is now available in Ansible Galaxy!
|
||||
|
||||
What is an Ansible Role?
|
||||
----------------------------------
|
||||
An Ansible Role is a collection of related tasks, methods, plugins, and modules in a standard format. You can use Roles in tasks or playbooks.
|
||||
|
||||
What does the Network Engine Role do?
|
||||
----------------------------------
|
||||
The Network Engine Role provides the fundamental building blocks for a data-model-driven approach to automated network management. Network Engine:
|
||||
|
||||
- extracts data about your network devices
|
||||
- returns the data as Ansible facts in a JSON data structure, ready to be added to your inventory host facts and/or consumed by Ansible tasks and templates
|
||||
- works on any network platform
|
||||
|
||||
With the Network Engine role, and other Roles built around it, you can normalize your Ansible facts across your entire network.
|
||||
|
||||
How do I get it?
|
||||
----------------------------------
|
||||
Via Ansible Galaxy using the following Linux command:
|
||||
|
||||
`ansible-galaxy install ansible-network.network-engine`
|
||||
|
||||
How do I use it?
|
||||
----------------------------------
|
||||
See the [User Guide](https://github.com/ansible-network/network-engine/blob/devel/docs/user_guide/README.md) for details and examples.
|
||||
|
||||
433
roles/ansible-network.network-engine/CHANGELOG.rst
Normal file
433
roles/ansible-network.network-engine/CHANGELOG.rst
Normal file
@@ -0,0 +1,433 @@
|
||||
==============================
|
||||
Ansible Network network-engine
|
||||
==============================
|
||||
|
||||
.. _Ansible Network network-engine_v2.7.5:
|
||||
|
||||
v2.7.5
|
||||
======
|
||||
|
||||
.. _Ansible Network network-engine_v2.7.5_Bugfixes:
|
||||
|
||||
Bugfixes
|
||||
--------
|
||||
|
||||
- Fix src_path to src command_parser `network-engine#230 <https://github.com/ansible-network/network-engine/pull/230>`_.
|
||||
|
||||
|
||||
.. _Ansible Network network-engine_v2.7.4:
|
||||
|
||||
v2.7.4
|
||||
======
|
||||
|
||||
.. _Ansible Network network-engine_v2.7.4_Bugfixes:
|
||||
|
||||
Bugfixes
|
||||
--------
|
||||
|
||||
- Fail validate_role_spec plugin if argument_spec is undefined `network-engine#221 <https://github.com/ansible-network/network-engine/pull/221>`_.
|
||||
|
||||
- Fix relative path failure in command_parser when template is not present in playbook directory `network-engine#222 <https://github.com/ansible-network/network-engine/pull/222>`_.
|
||||
|
||||
|
||||
.. _Ansible Network network-engine_v2.7.3:
|
||||
|
||||
v2.7.3
|
||||
======
|
||||
|
||||
.. _Ansible Network network-engine_v2.7.3_Minor Changes:
|
||||
|
||||
Minor Changes
|
||||
-------------
|
||||
|
||||
- Add verify_depedent_role_version action plugin `network-engine#214 <https://github.com/ansible-network/network-engine/pull/214>`_.
|
||||
|
||||
|
||||
.. _Ansible Network network-engine_v2.7.3_Deprecated Features:
|
||||
|
||||
Deprecated Features
|
||||
-------------------
|
||||
|
||||
- Deprecate lookup plugin network_template `network-engine#215 <https://github.com/ansible-network/network-engine/pull/215>`_.
|
||||
|
||||
|
||||
.. _Ansible Network network-engine_v2.7.2:
|
||||
|
||||
v2.7.2
|
||||
======
|
||||
|
||||
.. _Ansible Network network-engine_v2.7.2_Minor Changes:
|
||||
|
||||
Minor Changes
|
||||
-------------
|
||||
|
||||
- Add support for nested spec validation in validate_role_spec `network-engine#198 <https://github.com/ansible-network/network-engine/pull/198>`_.
|
||||
|
||||
|
||||
.. _Ansible Network network-engine_v2.7.1:
|
||||
|
||||
v2.7.1
|
||||
======
|
||||
|
||||
.. _Ansible Network network-engine_v2.7.1_Minor Changes:
|
||||
|
||||
Minor Changes
|
||||
-------------
|
||||
|
||||
- Add name option for textfsm to create facts to key `network-engine#202 <https://github.com/ansible-network/network-engine/pull/202>`_.
|
||||
|
||||
- Document name option for textfsm in cli plugin and update cli task `network-engine#205 <https://github.com/ansible-network/network-engine/pull/205>`_.
|
||||
|
||||
|
||||
.. _Ansible Network network-engine_v2.7.0:
|
||||
|
||||
v2.7.0
|
||||
======
|
||||
|
||||
.. _Ansible Network network-engine_v2.7.0_Major Changes:
|
||||
|
||||
Major Changes
|
||||
-------------
|
||||
|
||||
- Initial release of 2.7.0 ``network-engine`` Ansible role that is supported with Ansible 2.7.0
|
||||
|
||||
|
||||
.. _Ansible Network network-engine_v2.7.0_Bugfixes:
|
||||
|
||||
Bugfixes
|
||||
--------
|
||||
|
||||
- Fix native type conversion in json_template `network-engine#154 <https://github.com/ansible-network/network-engine/pull/154>`_.
|
||||
|
||||
- Fix templating repeat_for `network-engine#190 <https://github.com/ansible-network/network-engine/pull/190>`_.
|
||||
|
||||
- Add missing boilerplate for net_facts module `network-engine#194 <https://github.com/ansible-network/network-engine/pull/194>`_.
|
||||
|
||||
|
||||
.. _Ansible Network network-engine_v2.6.6:
|
||||
|
||||
v2.6.6
|
||||
======
|
||||
|
||||
.. _Ansible Network network-engine_v2.6.6_Minor Changes:
|
||||
|
||||
Minor Changes
|
||||
-------------
|
||||
|
||||
- Capability to filter AnsibleModule kwargs `network-engine#149 <https://github.com/ansible-network/network-engine/pull/149>`_.
|
||||
|
||||
|
||||
.. _Ansible Network network-engine_v2.6.6_Removed Features (previously deprecated):
|
||||
|
||||
Removed Features (previously deprecated)
|
||||
----------------------------------------
|
||||
|
||||
- Remove deprecated module ``cli_get``
|
||||
|
||||
|
||||
.. _Ansible Network network-engine_v2.6.5:
|
||||
|
||||
v2.6.5
|
||||
======
|
||||
|
||||
.. _Ansible Network network-engine_v2.6.5_Bugfixes:
|
||||
|
||||
Bugfixes
|
||||
--------
|
||||
|
||||
- Remove GenericLinux from supported platforms `network-engine#145 <https://github.com/ansible-network/network-engine/pull/145>`_.
|
||||
|
||||
|
||||
.. _Ansible Network network-engine_v2.6.4:
|
||||
|
||||
v2.6.4
|
||||
======
|
||||
|
||||
.. _Ansible Network network-engine_v2.6.4_Removed Features (previously deprecated):
|
||||
|
||||
Removed Features (previously deprecated)
|
||||
----------------------------------------
|
||||
|
||||
- Remove deprecated module ``text_parser``.
|
||||
|
||||
- Remove deprecated module ``textfsm``.
|
||||
|
||||
|
||||
.. _Ansible Network network-engine_v2.6.4_Bugfixes:
|
||||
|
||||
Bugfixes
|
||||
--------
|
||||
|
||||
- Fix repeat_for in json_template `network-engine#139 <https://github.com/ansible-network/network-engine/pull/139>`_.
|
||||
|
||||
|
||||
.. _Ansible Network network-engine_v2.6.4_Documentation Updates:
|
||||
|
||||
Documentation Updates
|
||||
---------------------
|
||||
|
||||
- Removes unnecessary details from README `network-engine#126 <https://github.com/ansible-network/network-engine/pull/126>`_.
|
||||
|
||||
|
||||
.. _Ansible Network network-engine_v2.6.3:
|
||||
|
||||
v2.6.3
|
||||
======
|
||||
|
||||
.. _Ansible Network network-engine_v2.6.3_Minor Changes:
|
||||
|
||||
Minor Changes
|
||||
-------------
|
||||
|
||||
- Makes parser directive extend templatable `network-engine#132 <https://github.com/ansible-network/network-engine/pull/132>`_.
|
||||
|
||||
|
||||
.. _Ansible Network network-engine_v2.6.3_Bugfixes:
|
||||
|
||||
Bugfixes
|
||||
--------
|
||||
|
||||
- Task to fail if ansible_min_version isn't met `network-engine#130 <https://github.com/ansible-network/network-engine/pull/130>`_.
|
||||
|
||||
|
||||
.. _Ansible Network network-engine_v2.6.2:
|
||||
|
||||
v2.6.2
|
||||
======
|
||||
|
||||
.. _Ansible Network network-engine_v2.6.2_New Lookup Plugins:
|
||||
|
||||
New Lookup Plugins
|
||||
------------------
|
||||
|
||||
- NEW ``config_template`` lookup plugin
|
||||
|
||||
- NEW ``yang_json2xml`` lookup plugin
|
||||
|
||||
|
||||
.. _Ansible Network network-engine_v2.6.2_New Filter Plugins:
|
||||
|
||||
New Filter Plugins
|
||||
------------------
|
||||
|
||||
- NEW ``to_lines`` filter plugin
|
||||
|
||||
|
||||
.. _Ansible Network network-engine_v2.6.2_New Modules:
|
||||
|
||||
New Modules
|
||||
-----------
|
||||
|
||||
- NEW ``validate_role_spec`` handle validating facts required by the role
|
||||
|
||||
|
||||
.. _Ansible Network network-engine_v2.6.2_Bugfixes:
|
||||
|
||||
Bugfixes
|
||||
--------
|
||||
|
||||
- Fix role path test dependency `network-engine#121 <https://github.com/ansible-network/network-engine/pull/121>`_.
|
||||
|
||||
|
||||
.. _Ansible Network network-engine_v2.6.1:
|
||||
|
||||
v2.6.1
|
||||
======
|
||||
|
||||
.. _Ansible Network network-engine_v2.6.1_Documentation Updates:
|
||||
|
||||
Documentation Updates
|
||||
---------------------
|
||||
|
||||
- The argument to end a block of text when searching with match_greedy was missing `network-engine#116 <https://github.com/ansible-network/network-engine/pull/116>`_.
|
||||
|
||||
|
||||
.. _Ansible Network network-engine_v2.6.0:
|
||||
|
||||
v2.6.0
|
||||
======
|
||||
|
||||
.. _Ansible Network network-engine_v2.6.0_Major Changes:
|
||||
|
||||
Major Changes
|
||||
-------------
|
||||
|
||||
- Initial release of 2.6.0 ``network-engine`` Ansible role that is supported with Ansible 2.6.0
|
||||
|
||||
|
||||
.. _Ansible Network network-engine_v2.5.4:
|
||||
|
||||
v2.5.4
|
||||
======
|
||||
|
||||
.. _Ansible Network network-engine_v2.5.4_Minor Changes:
|
||||
|
||||
Minor Changes
|
||||
-------------
|
||||
|
||||
- Add parsers to search path `network-engine#89 <https://github.com/ansible-network/network-engine/pull/89>`_.
|
||||
|
||||
- Fix export_as templating vars `network-engine#104 <https://github.com/ansible-network/network-engine/pull/104>`_.
|
||||
|
||||
|
||||
.. _Ansible Network network-engine_v2.5.4_Bugfixes:
|
||||
|
||||
Bugfixes
|
||||
--------
|
||||
|
||||
- Fix cli task parser undefined issue when only command is used `network-engine#103 <https://github.com/ansible-network/network-engine/pull/103>`_.
|
||||
|
||||
- Fix an issue with using the extend directive with a loop `network-engine#105 <https://github.com/ansible-network/network-engine/pull/105>`_.
|
||||
|
||||
- Fixes bug when loading a dir of parsers `network-engine#113 <https://github.com/ansible-network/network-engine/pull/113>`_.
|
||||
|
||||
|
||||
.. _Ansible Network network-engine_v2.5.3:
|
||||
|
||||
v2.5.3
|
||||
======
|
||||
|
||||
.. _Ansible Network network-engine_v2.5.3_Minor Changes:
|
||||
|
||||
Minor Changes
|
||||
-------------
|
||||
|
||||
- Templating the regex sent to the parser to allow us to use ansible variables in the regex string `network-engine#97 <https://github.com/ansible-network/network-engine/pull/97>`_.
|
||||
|
||||
|
||||
.. _Ansible Network network-engine_v2.5.3_Removed Features (previously deprecated):
|
||||
|
||||
Removed Features (previously deprecated)
|
||||
----------------------------------------
|
||||
|
||||
- Move yang2spec lookup to feature branch, till the right location for this plugin is identified `network-engine#100 <https://github.com/ansible-network/network-engine/pull/100>`_.
|
||||
|
||||
|
||||
.. _Ansible Network network-engine_v2.5.2:
|
||||
|
||||
v2.5.2
|
||||
======
|
||||
|
||||
.. _Ansible Network network-engine_v2.5.2_Minor Changes:
|
||||
|
||||
Minor Changes
|
||||
-------------
|
||||
|
||||
- Add new directives extend `network-engine#91 <https://github.com/ansible-network/network-engine/pull/91>`_.
|
||||
|
||||
- Adds conditional support to nested template objects `network-engine#55 <https://github.com/ansible-network/network-engine/pull/55>`_.
|
||||
|
||||
|
||||
.. _Ansible Network network-engine_v2.5.2_New Lookup Plugins:
|
||||
|
||||
New Lookup Plugins
|
||||
------------------
|
||||
|
||||
- New lookup plugin ``json_template``
|
||||
|
||||
- New lookup plugin ``network_template``
|
||||
|
||||
- New lookup plugin ``yang2spec``
|
||||
|
||||
- New lookup plugin ``netcfg_diff``
|
||||
|
||||
|
||||
.. _Ansible Network network-engine_v2.5.2_New Filter Plugins:
|
||||
|
||||
New Filter Plugins
|
||||
------------------
|
||||
|
||||
- New filter plugin ``interface_range``
|
||||
|
||||
- New filter plugin ``interface_split``
|
||||
|
||||
- New filter plugin ``vlan_compress``
|
||||
|
||||
- New filter plugin ``vlan_expand``
|
||||
|
||||
|
||||
.. _Ansible Network network-engine_v2.5.2_New Tasks:
|
||||
|
||||
New Tasks
|
||||
---------
|
||||
|
||||
- New task ``cli``
|
||||
|
||||
|
||||
.. _Ansible Network network-engine_v2.5.2_Bugfixes:
|
||||
|
||||
Bugfixes
|
||||
--------
|
||||
|
||||
- Fix AnsibleFilterError, deprecations, and unused imports `network-engine#82 <https://github.com/ansible-network/network-engine/pull/82>`_.
|
||||
|
||||
|
||||
.. _Ansible Network network-engine_v2.5.1:
|
||||
|
||||
v2.5.1
|
||||
======
|
||||
|
||||
.. _Ansible Network network-engine_v2.5.1_Deprecated Features:
|
||||
|
||||
Deprecated Features
|
||||
-------------------
|
||||
|
||||
- Module ``text_parser`` renamed to ``command_parser``; original name deprecated; legacy use supported; will be removed in 2.6.0.
|
||||
|
||||
- Module ``textfsm`` renamed to ``textfsm_parser``; original name deprecated; legacy use supported; will be removed in 2.6.0.
|
||||
|
||||
|
||||
.. _Ansible Network network-engine_v2.5.1_New Modules:
|
||||
|
||||
New Modules
|
||||
-----------
|
||||
|
||||
- New module ``command_parser`` (renamed from ``text_parser``)
|
||||
|
||||
- New module ``textfsm_parser`` (renamed from ``textfsm``)
|
||||
|
||||
|
||||
.. _Ansible Network network-engine_v2.5.1_Bugfixes:
|
||||
|
||||
Bugfixes
|
||||
--------
|
||||
|
||||
- Fix ``command_parser`` Absolute path with tilde in src should work `network-engine#58 <https://github.com/ansible-network/network-engine/pull/58>`_
|
||||
|
||||
- Fix content mush only accepts string type `network-engine#72 <https://github.com/ansible-network/network-engine/pull/72>`_
|
||||
|
||||
- Fix StringIO to work with Python3 in addition to Python2 `network-engine#53 <https://github.com/ansible-network/network-engine/pull/53>`_
|
||||
|
||||
|
||||
.. _Ansible Network network-engine_v2.5.1_Documentation Updates:
|
||||
|
||||
Documentation Updates
|
||||
---------------------
|
||||
|
||||
- User Guide `docs/user_guide <https://github.com/ansible-network/network-engine/tree/devel/docs/user_guide>`_.
|
||||
|
||||
|
||||
.. _Ansible Network network-engine_v2.5.0:
|
||||
|
||||
v2.5.0
|
||||
======
|
||||
|
||||
.. _Ansible Network network-engine_v2.5.0_Major Changes:
|
||||
|
||||
Major Changes
|
||||
-------------
|
||||
|
||||
- Initial release of the ``network-engine`` Ansible role.
|
||||
|
||||
- This role provides the foundation for building network roles by providing modules and plugins that are common to all Ansible Network roles. All of the artifacts in this role can be used independent of the platform that is being managed.
|
||||
|
||||
|
||||
.. _Ansible Network network-engine_v2.5.0_New Modules:
|
||||
|
||||
New Modules
|
||||
-----------
|
||||
|
||||
- NEW ``text_parser`` Parses ASCII text into JSON facts using text_parser engine and YAML-formatted input. Provides a rules-based text parser that is closely modeled after the Ansible playbook language. This parser will iterate over the rules and parse the output of structured ASCII text into a JSON data structure that can be added to the inventory host facts.
|
||||
|
||||
- NEW ``textfsm`` Parses ASCII text into JSON facts using textfsm engine and Google TextFSM-formatted input. Provides textfsm rules-based templates to parse data from text. The template acting as parser will iterate of the rules and parse the output of structured ASCII text into a JSON data structure that can be added to the inventory host facts.
|
||||
|
||||
91
roles/ansible-network.network-engine/CONTRIBUTING.md
Normal file
91
roles/ansible-network.network-engine/CONTRIBUTING.md
Normal file
@@ -0,0 +1,91 @@
|
||||
# Developer Guide
|
||||
|
||||
This role is developed and maintained by the Ansible Network Working Group.
|
||||
Contributions to this role are welcomed. This document will provide individuals
|
||||
with information about how to contribute to the further development of this
|
||||
role.
|
||||
|
||||
## Contributing
|
||||
|
||||
There are many ways you can contribute to this role. Adding new artifacts such
|
||||
as modules and plugins, testing and/or reviewing and updating documentation.
|
||||
|
||||
### Adding support for a new platform
|
||||
|
||||
To add support for a new platform to this role, there are a couple of things
|
||||
that need to be done.
|
||||
|
||||
1) Create the module for the platform specific implementation in Ansible. The
|
||||
module can be contributed directly to Ansible core, distributed through Ansible
|
||||
Galaxy or added to this role.
|
||||
|
||||
2) (Optional) If adding the module code directly to this role, add the module
|
||||
to `library/`
|
||||
|
||||
3) (Optional) If the new platform module is distributed through another Galaxy
|
||||
role, please update [README](README.md) Dependencies section to include the
|
||||
name of the Galaxy role that includes the module.
|
||||
|
||||
4) Once the module has been created, the add a new task in `tasks/` for the
|
||||
specific platform to be supported. Use any of the existing platform
|
||||
implementations as a guide.
|
||||
|
||||
5) (Optional) If a configuration parameter is not supported, then the
|
||||
implementation in tasks should detect that and provide a warning message.
|
||||
|
||||
6) Update the `meta/main.yaml` file to add the newly provided platform to
|
||||
the `platforms` meta data.
|
||||
|
||||
### Adding platform specific arguments
|
||||
|
||||
Sometimes there is a need to add platform specific arguments to a role for use
|
||||
by a platform specific module. This can be accomplished by adding the adding
|
||||
the arguments under a platform specific key.
|
||||
|
||||
Note: It is the responsibility of the task writer to handle the implementation
|
||||
of the platform specific arguments.
|
||||
|
||||
Here is an example that implements a platform specific argument:
|
||||
|
||||
```yaml
|
||||
tasks:
|
||||
- name: configure network device resource
|
||||
include_role:
|
||||
name: net_system
|
||||
vars:
|
||||
resource:
|
||||
foo: bar
|
||||
ios:
|
||||
foo: baz
|
||||
```
|
||||
|
||||
### Adding documentation for a platform specific implementation
|
||||
|
||||
While not required, there are times when providing implementation nodes are
|
||||
advantageous to instructing the playbook writer how to implement platform
|
||||
specific arguments. In order to provide platform specific documentation,
|
||||
create a file in the docs directory using GitHub Markdown. The file name
|
||||
should be the platform name.
|
||||
|
||||
For instance, let's assume we want to create implementation nodes for a
|
||||
fictitious platform call `foo`. Create a new file `docs/foo.md` and
|
||||
then add a link to [README](README.md) pointing to `docs/foo.md` in the `PLATFORM
|
||||
NOTES` section.
|
||||
|
||||
# Note
|
||||
|
||||
The release cadence for the network-engine role is two weeks and it will be
|
||||
released on every second Tuesday at 12:00 PM (GMT) from the date of prior release.
|
||||
For the PR to be available in the upcoming release it should be in a mergeable state
|
||||
that is CI is passing and all review comments fixed at least two days prior to scheduled date
|
||||
of release.
|
||||
|
||||
## Bug Reporting
|
||||
|
||||
If you have found a bug in the with the current role please open a [GitHub
|
||||
issue](../../issues)
|
||||
|
||||
## Contact
|
||||
|
||||
* [#ansible-network IRC channel](https://webchat.freenode.net/?channels=ansible-network) on Freenode.net
|
||||
|
||||
674
roles/ansible-network.network-engine/LICENSE
Normal file
674
roles/ansible-network.network-engine/LICENSE
Normal file
@@ -0,0 +1,674 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
{one line to give the program's name and a brief idea of what it does.}
|
||||
Copyright (C) {year} {name of author}
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
{project} Copyright (C) {year} {fullname}
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
||||
45
roles/ansible-network.network-engine/README.md
Normal file
45
roles/ansible-network.network-engine/README.md
Normal file
@@ -0,0 +1,45 @@
|
||||
# network-engine
|
||||
|
||||
[](https://galaxy.ansible.com/ansible-network/network-engine/)
|
||||
|
||||
This role provides the foundation for building network roles by providing
|
||||
modules and plugins that are common to all Ansible Network roles. Typically
|
||||
this role should not be directly invoked in a playbook.
|
||||
|
||||
To install this role: `ansible-galaxy install ansible-network.network-engine`
|
||||
|
||||
To see the version of this role you currently have installed: `ansible-galaxy info ansible-network.network-engine`
|
||||
|
||||
To ensure you have the latest version available: `ansible-galaxy install -f ansible-network.network-engine`
|
||||
|
||||
To find other roles maintained by the Ansible Network team, see our [Galaxy Profile](https://galaxy.ansible.com/ansible-network/).
|
||||
|
||||
Any open bugs and/or feature requests are tracked in [GitHub issues](https://github.com/ansible-network/network-engine/issues).
|
||||
|
||||
Interested in contributing to this role? Check out [CONTRIBUTING](https://github.com/ansible-network/network-engine/blob/devel/CONTRIBUTING.md) before submitting a pull request.
|
||||
|
||||
|
||||
## Functions
|
||||
|
||||
This section provides a list of the available functions that are included in
|
||||
this role. Any of the provided functions can be implemented in Ansible
|
||||
playbooks directly. To use a particular function, please see the `docs` link
|
||||
associated with the function.
|
||||
|
||||
* `cli` [[source]](https://github.com/ansible-network/network-engine/blob/devel/tasks/cli.yaml) [[docs]](https://github.com/ansible-network/network-engine/blob/devel/docs/tasks/cli.md).
|
||||
|
||||
## Developer Guide
|
||||
|
||||
- [How to use](https://github.com/ansible-network/network-engine/blob/devel/docs/user_guide/README.md)
|
||||
- [Parser Directives](https://github.com/ansible-network/network-engine/blob/devel/docs/directives/parser_directives.md)
|
||||
- [Filter Plugins](https://github.com/ansible-network/network-engine/blob/devel/docs/plugins/filter_plugins.md)
|
||||
- [How to test](https://github.com/ansible-network/network-engine/blob/devel/docs/tests/test_guide.md)
|
||||
|
||||
|
||||
## License
|
||||
|
||||
GPLv3
|
||||
|
||||
## Author Information
|
||||
|
||||
Ansible Network Community (ansible-network)
|
||||
174
roles/ansible-network.network-engine/action_plugins/cli.py
Normal file
174
roles/ansible-network.network-engine/action_plugins/cli.py
Normal file
@@ -0,0 +1,174 @@
|
||||
# (c) 2018, Ansible by Red Hat, inc
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
||||
'status': ['preview'],
|
||||
'supported_by': 'network'}
|
||||
|
||||
DOCUMENTATION = """
|
||||
---
|
||||
module: cli
|
||||
author: Peter Sprygada (@privateip)
|
||||
short_description: Runs the specific command and returns the output
|
||||
description:
|
||||
- The command specified in C(command) will be executed on the remote
|
||||
device and its output will be returned to the module. This module
|
||||
requires that the device is supported using the C(network_cli)
|
||||
connection plugin and has a valid C(cliconf) plugin to work correctly.
|
||||
version_added: "2.5"
|
||||
options:
|
||||
command:
|
||||
description:
|
||||
- The command to be executed on the remote node. The value for this
|
||||
argument will be passed unchanged to the network device and the
|
||||
output returned.
|
||||
required: yes
|
||||
default: null
|
||||
parser:
|
||||
description:
|
||||
- The parser file to pass the output from the command through to
|
||||
generate Ansible facts. If this argument is specified, the output
|
||||
from the command will be parsed based on the rules in the
|
||||
specified parser.
|
||||
default: null
|
||||
engine:
|
||||
description:
|
||||
- Defines the engine to use when parsing the output. This argument
|
||||
accepts one of two valid values, C(command_parser) or C(textfsm_parser).
|
||||
default: command_parser
|
||||
choices:
|
||||
- command_parser
|
||||
- textfsm_parser
|
||||
name:
|
||||
description:
|
||||
- The C(name) argument is used to define the top-level fact name to
|
||||
hold the output of textfsm_engine parser. If this argument is not provided,
|
||||
the output from parsing will not be exported. Note that this argument is
|
||||
only considered when C(engine) is C(textfsm_parser).
|
||||
default: null
|
||||
"""
|
||||
|
||||
EXAMPLES = """
|
||||
- name: return show version
|
||||
cli:
|
||||
command: show version
|
||||
|
||||
- name: return parsed command output
|
||||
cli:
|
||||
command: show version
|
||||
parser: parser_templates/show_version.yaml
|
||||
|
||||
- name: parse with textfsm_parser engine
|
||||
cli:
|
||||
command: show version
|
||||
parser: parser_templates/show_version
|
||||
engine: textfsm_parser
|
||||
name: system_facts
|
||||
"""
|
||||
|
||||
RETURN = """
|
||||
stdout:
|
||||
description: returns the output from the command
|
||||
returned: always
|
||||
type: dict
|
||||
json:
|
||||
description: the output converted from json to a hash
|
||||
returned: always
|
||||
type: dict
|
||||
"""
|
||||
|
||||
import json
|
||||
|
||||
from ansible.plugins.action import ActionBase
|
||||
from ansible.module_utils.connection import Connection, ConnectionError
|
||||
from ansible.module_utils._text import to_text
|
||||
from ansible.errors import AnsibleError
|
||||
from ansible.utils.display import Display
|
||||
|
||||
display = Display()
|
||||
|
||||
|
||||
class ActionModule(ActionBase):
|
||||
|
||||
def run(self, tmp=None, task_vars=None):
|
||||
''' handler for cli operations '''
|
||||
|
||||
if task_vars is None:
|
||||
task_vars = dict()
|
||||
|
||||
result = super(ActionModule, self).run(tmp, task_vars)
|
||||
del tmp # tmp no longer has any effect
|
||||
|
||||
try:
|
||||
command = self._task.args['command']
|
||||
parser = self._task.args.get('parser')
|
||||
engine = self._task.args.get('engine', 'command_parser')
|
||||
if engine == 'textfsm_parser':
|
||||
name = self._task.args.get('name')
|
||||
elif engine == 'command_parser' and self._task.args.get('name'):
|
||||
display.warning('name is unnecessary when using command_parser and will be ignored')
|
||||
del self._task.args['name']
|
||||
except KeyError as exc:
|
||||
raise AnsibleError(to_text(exc))
|
||||
|
||||
socket_path = getattr(self._connection, 'socket_path') or task_vars.get('ansible_socket')
|
||||
connection = Connection(socket_path)
|
||||
|
||||
# make command a required argument
|
||||
if not command:
|
||||
raise AnsibleError('missing required argument `command`')
|
||||
|
||||
try:
|
||||
output = connection.get(command)
|
||||
except ConnectionError as exc:
|
||||
raise AnsibleError(to_text(exc))
|
||||
|
||||
result['stdout'] = output
|
||||
|
||||
# try to convert the cli output to native json
|
||||
try:
|
||||
json_data = json.loads(output)
|
||||
except Exception:
|
||||
json_data = None
|
||||
|
||||
result['json'] = json_data
|
||||
|
||||
if parser:
|
||||
if engine not in ('command_parser', 'textfsm_parser'):
|
||||
raise AnsibleError('missing or invalid value for argument engine')
|
||||
|
||||
new_task = self._task.copy()
|
||||
new_task.args = {
|
||||
'file': parser,
|
||||
'content': (json_data or output)
|
||||
}
|
||||
if engine == 'textfsm_parser':
|
||||
new_task.args.update({'name': name})
|
||||
|
||||
kwargs = {
|
||||
'task': new_task,
|
||||
'connection': self._connection,
|
||||
'play_context': self._play_context,
|
||||
'loader': self._loader,
|
||||
'templar': self._templar,
|
||||
'shared_loader_obj': self._shared_loader_obj
|
||||
}
|
||||
|
||||
task_parser = self._shared_loader_obj.action_loader.get(engine, **kwargs)
|
||||
result.update(task_parser.run(task_vars=task_vars))
|
||||
|
||||
self._remove_tmp_path(self._connection._shell.tmpdir)
|
||||
|
||||
# this is needed so the strategy plugin can identify the connection as
|
||||
# a persistent connection and track it, otherwise the connection will
|
||||
# not be closed at the end of the play
|
||||
socket_path = getattr(self._connection, 'socket_path') or task_vars.get('ansible_socket')
|
||||
self._task.args['_ansible_socket'] = socket_path
|
||||
|
||||
return result
|
||||
@@ -0,0 +1,416 @@
|
||||
# (c) 2018, Ansible by Red Hat, inc
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import os
|
||||
import sys
|
||||
import collections
|
||||
|
||||
from ansible import constants as C
|
||||
from ansible.plugins.action import ActionBase
|
||||
from ansible.module_utils.common._collections_compat import Mapping
|
||||
from ansible.module_utils.six import iteritems, string_types
|
||||
from ansible.module_utils._text import to_text
|
||||
from ansible.errors import AnsibleError
|
||||
from ansible.utils.display import Display
|
||||
|
||||
try:
|
||||
from ansible.module_utils.network.common.utils import to_list
|
||||
except ImportError:
|
||||
# keep role compatible with Ansible 2.4
|
||||
from ansible.module_utils.network_common import to_list
|
||||
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), os.path.pardir, 'lib'))
|
||||
from network_engine.plugins import template_loader, parser_loader
|
||||
from network_engine.utils import dict_merge, generate_source_path
|
||||
|
||||
display = Display()
|
||||
|
||||
|
||||
def warning(msg):
|
||||
if C.ACTION_WARNINGS:
|
||||
display.warning(msg)
|
||||
|
||||
|
||||
class ActionModule(ActionBase):
|
||||
|
||||
VALID_FILE_EXTENSIONS = ('.yaml', '.yml', '.json')
|
||||
VALID_GROUP_DIRECTIVES = ('pattern_group', 'block')
|
||||
VALID_ACTION_DIRECTIVES = ('parser_metadata', 'pattern_match', 'set_vars', 'json_template')
|
||||
VALID_DIRECTIVES = VALID_GROUP_DIRECTIVES + VALID_ACTION_DIRECTIVES
|
||||
VALID_EXPORT_AS = ('list', 'elements', 'dict', 'object', 'hash')
|
||||
|
||||
def run(self, tmp=None, task_vars=None):
|
||||
if task_vars is None:
|
||||
task_vars = dict()
|
||||
|
||||
result = super(ActionModule, self).run(tmp, task_vars)
|
||||
|
||||
try:
|
||||
source_dir = self._task.args.get('dir')
|
||||
source_file = self._task.args.get('file')
|
||||
content = self._task.args['content']
|
||||
except KeyError as exc:
|
||||
return {'failed': True, 'msg': 'missing required argument: %s' % exc}
|
||||
|
||||
if source_dir and source_file:
|
||||
return {'failed': True, 'msg': '`dir` and `file` are mutually exclusive arguments'}
|
||||
|
||||
if source_dir:
|
||||
sources = self.get_files(to_list(source_dir))
|
||||
else:
|
||||
if source_file:
|
||||
sources = to_list(source_file)
|
||||
else:
|
||||
searchpath = []
|
||||
searchpath = task_vars.get('ansible_search_path', [])
|
||||
if not searchpath:
|
||||
searchpath.append(self._loader._basedir)
|
||||
|
||||
if 'parser_templates' in os.listdir(searchpath[0]):
|
||||
subdir_searchpath = os.path.join(searchpath[0], 'parser_templates')
|
||||
|
||||
# parser in {{ playbook_dir }}/parser_templates/{{ ansible_network_os }}
|
||||
if task_vars['ansible_network_os'] in os.listdir(subdir_searchpath):
|
||||
newsearchpath = os.path.join(subdir_searchpath, task_vars['ansible_network_os'])
|
||||
sources = self.get_parser(path=newsearchpath)
|
||||
|
||||
# parser in {{ playbook_dir }}/parser_templates
|
||||
else:
|
||||
sources = self.get_parser(path=subdir_searchpath)
|
||||
|
||||
# parser in {{ playbook_dir }}
|
||||
else:
|
||||
sources = self.get_parser(path=searchpath[0])
|
||||
|
||||
facts = {}
|
||||
|
||||
self.template = template_loader.get('json_template', self._templar)
|
||||
|
||||
paths = self._task.get_search_path()
|
||||
for src in sources:
|
||||
src = generate_source_path(paths, src)
|
||||
if src is None:
|
||||
raise AnsibleError("src [%s] is either missing or invalid" % src)
|
||||
|
||||
tasks = self._loader.load_from_file(src)
|
||||
|
||||
self.ds = {'content': content}
|
||||
self.ds.update(task_vars)
|
||||
|
||||
for task in tasks:
|
||||
name = task.pop('name', None)
|
||||
display.vvvv('processing directive: %s' % name)
|
||||
|
||||
register = task.pop('register', None)
|
||||
extend = task.pop('extend', None)
|
||||
if extend:
|
||||
extend = self.template(extend, self.ds)
|
||||
|
||||
export = task.pop('export', False)
|
||||
export_as = task.pop('export_as', 'list')
|
||||
export_as = self.template(export_as, self.ds)
|
||||
if export_as not in self.VALID_EXPORT_AS:
|
||||
raise AnsibleError('invalid value for export_as, got %s' % export_as)
|
||||
|
||||
if 'export_facts' in task:
|
||||
task['set_vars'] = task.pop('export_facts')
|
||||
export = True
|
||||
elif 'set_vars' not in task:
|
||||
if export and not register:
|
||||
warning('entry will not be exported due to missing register option')
|
||||
|
||||
when = task.pop('when', None)
|
||||
if when is not None:
|
||||
if not self._check_conditional(when, self.ds):
|
||||
display.vvv('command_parser: skipping task [%s] due to conditional check' % name)
|
||||
continue
|
||||
|
||||
loop = task.pop('loop', None)
|
||||
loop_var = task.pop('loop_control', {}).get('loop_var') or 'item'
|
||||
|
||||
if loop is not None:
|
||||
loop = self.template(loop, self.ds)
|
||||
if not loop:
|
||||
display.vvv('command_parser: loop option was defined but no loop data found')
|
||||
res = list()
|
||||
|
||||
if loop:
|
||||
# loop is a hash so break out key and value
|
||||
if isinstance(loop, Mapping):
|
||||
for loop_key, loop_value in iteritems(loop):
|
||||
self.ds[loop_var] = {'key': loop_key, 'value': loop_value}
|
||||
resp = self._process_directive(task)
|
||||
res.append(resp)
|
||||
|
||||
# loop is either a list or a string
|
||||
else:
|
||||
for loop_item in loop:
|
||||
self.ds[loop_var] = loop_item
|
||||
resp = self._process_directive(task)
|
||||
res.append(resp)
|
||||
|
||||
if 'set_vars' in task:
|
||||
if register:
|
||||
self.ds[register] = res
|
||||
if export:
|
||||
if extend:
|
||||
facts.update(self.merge_facts(task_vars, extend, register, res))
|
||||
else:
|
||||
facts[register] = res
|
||||
else:
|
||||
self.ds.update(res)
|
||||
if export:
|
||||
facts.update(res)
|
||||
elif register:
|
||||
self.ds[register] = res
|
||||
if export:
|
||||
if export_as in ('dict', 'hash', 'object'):
|
||||
if extend:
|
||||
facts.update(self.merge_facts(task_vars, extend, register, res, expand=True))
|
||||
else:
|
||||
if register not in facts:
|
||||
facts[register] = {}
|
||||
for item in res:
|
||||
facts[register] = self.rec_update(facts[register], item)
|
||||
else:
|
||||
if extend:
|
||||
facts.update(self.merge_facts(task_vars, extend, register, res))
|
||||
else:
|
||||
facts[register] = res
|
||||
else:
|
||||
res = self._process_directive(task)
|
||||
if 'set_vars' in task:
|
||||
if register:
|
||||
self.ds[register] = res
|
||||
if export:
|
||||
if extend:
|
||||
facts.update(self.merge_facts(task_vars, extend, register, res))
|
||||
else:
|
||||
facts[register] = res
|
||||
else:
|
||||
self.ds.update(res)
|
||||
if export:
|
||||
facts.update(res)
|
||||
elif res and register:
|
||||
self.ds[register] = res
|
||||
if export:
|
||||
if register:
|
||||
if extend:
|
||||
facts.update(self.merge_facts(task_vars, extend, register, res))
|
||||
else:
|
||||
facts[register] = res
|
||||
else:
|
||||
for r in to_list(res):
|
||||
for k, v in iteritems(r):
|
||||
facts.update({to_text(k): v})
|
||||
|
||||
task_vars.update(facts)
|
||||
|
||||
result.update({
|
||||
'ansible_facts': facts,
|
||||
'included': sources
|
||||
})
|
||||
|
||||
return result
|
||||
|
||||
def merge_facts(self, task_vars, extend, register, res, expand=False):
|
||||
update = self.build_update(extend, register, res, expand)
|
||||
root = extend.split('.')[0]
|
||||
current = {root: task_vars.get(root, {})}
|
||||
return dict_merge(current, update)
|
||||
|
||||
def build_update(self, path, child, value, expand=False):
|
||||
"""Build an update based on the current results
|
||||
|
||||
This method will take the current results and build a nested dict
|
||||
object. The keys for the nested dict object are identified by
|
||||
path.
|
||||
|
||||
:param path: The path of the nest keys
|
||||
|
||||
:param child: The child key name to assign the value to
|
||||
|
||||
:param value: The value to assign to the child key
|
||||
|
||||
:param expand: When set to True, this will iterate over the value
|
||||
|
||||
:returns: A nest dict object
|
||||
"""
|
||||
update_set = dict()
|
||||
working_set = update_set
|
||||
|
||||
if expand is True:
|
||||
for key in path.split('.'):
|
||||
working_set[key] = dict()
|
||||
working_set = working_set[key]
|
||||
working_set[child] = {}
|
||||
for item in value:
|
||||
working_set[child] = self.rec_update(working_set[child], item)
|
||||
else:
|
||||
for key in path.split('.'):
|
||||
working_set[key] = dict()
|
||||
working_set = working_set[key]
|
||||
working_set[child] = value
|
||||
|
||||
return update_set
|
||||
|
||||
def get_parser(self, path):
|
||||
sources = list()
|
||||
src_file = list()
|
||||
|
||||
for i in os.listdir(path):
|
||||
if i.startswith('show_'):
|
||||
f, ext = os.path.splitext(i)
|
||||
if ext in self.VALID_FILE_EXTENSIONS:
|
||||
src_file.append(i)
|
||||
|
||||
if len(src_file) == 1:
|
||||
sources.append(os.path.join(path, src_file[0]))
|
||||
elif len(src_file) == 0:
|
||||
raise AnsibleError("no parser file found in {0}, please create a parser".format(path))
|
||||
else:
|
||||
raise AnsibleError("too many files in {0}, please use `file` or `dir` parameter".format(path))
|
||||
|
||||
return sources
|
||||
|
||||
def get_files(self, source_dirs):
|
||||
include_files = list()
|
||||
_processed = set()
|
||||
|
||||
for source_dir in source_dirs:
|
||||
if not os.path.isdir(source_dir):
|
||||
raise AnsibleError('%s does not appear to be a valid directory' % source_dir)
|
||||
|
||||
for filename in os.listdir(source_dir):
|
||||
fn, fext = os.path.splitext(filename)
|
||||
if fn not in _processed:
|
||||
_processed.add(fn)
|
||||
|
||||
filename = os.path.join(source_dir, filename)
|
||||
|
||||
if not os.path.isfile(filename) or fext not in self.VALID_FILE_EXTENSIONS:
|
||||
continue
|
||||
else:
|
||||
include_files.append(filename)
|
||||
|
||||
return include_files
|
||||
|
||||
def rec_update(self, d, u):
|
||||
for k, v in iteritems(u):
|
||||
if isinstance(v, Mapping):
|
||||
d[k] = self.rec_update(d.get(k, {}), v)
|
||||
else:
|
||||
d[k] = v
|
||||
return d
|
||||
|
||||
def do_pattern_group(self, block):
|
||||
|
||||
results = list()
|
||||
registers = {}
|
||||
|
||||
for entry in block:
|
||||
task = entry.copy()
|
||||
|
||||
name = task.pop('name', None)
|
||||
display.vvv("command_parser: starting pattern_match [%s] in pattern_group" % name)
|
||||
|
||||
register = task.pop('register', None)
|
||||
|
||||
when = task.pop('when', None)
|
||||
if when is not None:
|
||||
if not self._check_conditional(when, self.ds):
|
||||
warning('skipping task due to conditional check failure')
|
||||
continue
|
||||
|
||||
loop = task.pop('loop', None)
|
||||
if loop:
|
||||
loop = self.template(loop, self.ds)
|
||||
|
||||
loop_var = task.pop('loop_control', {}).get('loop_var') or 'item'
|
||||
display.vvvv('command_parser: loop_var is %s' % loop_var)
|
||||
|
||||
if not set(task).issubset(('pattern_group', 'pattern_match')):
|
||||
raise AnsibleError('invalid directive specified')
|
||||
|
||||
if 'pattern_group' in task:
|
||||
if loop and isinstance(loop, collections.Iterable) and not isinstance(loop, string_types):
|
||||
res = list()
|
||||
for loop_item in loop:
|
||||
self.ds[loop_var] = loop_item
|
||||
res.append(self.do_pattern_group(task['pattern_group']))
|
||||
else:
|
||||
res = self.do_pattern_group(task['pattern_group'])
|
||||
|
||||
if res:
|
||||
results.append(res)
|
||||
if register:
|
||||
registers[register] = res
|
||||
|
||||
elif isinstance(loop, collections.Iterable) and not isinstance(loop, string_types):
|
||||
loop_result = list()
|
||||
|
||||
for loop_item in loop:
|
||||
self.ds[loop_var] = loop_item
|
||||
loop_result.append(self._process_directive(task))
|
||||
|
||||
results.append(loop_result)
|
||||
|
||||
if register:
|
||||
registers[register] = loop_result
|
||||
|
||||
else:
|
||||
res = self._process_directive(task)
|
||||
if res:
|
||||
results.append(res)
|
||||
if register:
|
||||
registers[register] = res
|
||||
|
||||
return registers
|
||||
|
||||
def _process_directive(self, task):
|
||||
for directive, args in iteritems(task):
|
||||
if directive == 'block':
|
||||
display.deprecated('`block` is not longer supported, use `pattern_group` instead', version=2.6)
|
||||
directive = 'pattern_group'
|
||||
|
||||
if directive not in self.VALID_DIRECTIVES:
|
||||
raise AnsibleError('invalid directive in parser: %s' % directive)
|
||||
|
||||
meth = getattr(self, 'do_%s' % directive)
|
||||
|
||||
if meth:
|
||||
if directive in self.VALID_GROUP_DIRECTIVES:
|
||||
return meth(args)
|
||||
elif directive in self.VALID_ACTION_DIRECTIVES:
|
||||
return meth(**args)
|
||||
else:
|
||||
raise AnsibleError('invalid directive: %s' % directive)
|
||||
|
||||
def do_parser_metadata(self, version=None, command=None, network_os=None):
|
||||
if version:
|
||||
display.vvv('command_parser: using parser version %s' % version)
|
||||
|
||||
if network_os not in (None, self.ds['ansible_network_os']):
|
||||
raise AnsibleError('parser expected %s, got %s' % (network_os, self.ds['ansible_network_os']))
|
||||
|
||||
def do_pattern_match(self, regex, content=None, match_all=None, match_until=None, match_greedy=None):
|
||||
content = self.template(content, self.ds) or self.template("{{ content }}", self.ds)
|
||||
regex = self.template(regex, self.ds)
|
||||
parser = parser_loader.get('pattern_match', content)
|
||||
return parser.match(regex, match_all, match_until, match_greedy)
|
||||
|
||||
def do_json_template(self, template):
|
||||
return self.template.run(template, self.ds)
|
||||
|
||||
def do_set_vars(self, **kwargs):
|
||||
return self.template(kwargs, self.ds)
|
||||
|
||||
def _check_conditional(self, when, variables):
|
||||
conditional = "{%% if %s %%}True{%% else %%}False{%% endif %%}"
|
||||
return self.template(conditional % when, variables)
|
||||
@@ -0,0 +1,81 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# (c) 2018, Ansible by Red Hat, inc
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
from ansible.module_utils.six import StringIO, string_types
|
||||
|
||||
from ansible.plugins.action import ActionBase
|
||||
from ansible.errors import AnsibleError
|
||||
|
||||
try:
|
||||
import textfsm
|
||||
HAS_TEXTFSM = True
|
||||
except ImportError:
|
||||
HAS_TEXTFSM = False
|
||||
|
||||
|
||||
class ActionModule(ActionBase):
|
||||
|
||||
def run(self, tmp=None, task_vars=None):
|
||||
''' handler for textfsm action '''
|
||||
|
||||
if task_vars is None:
|
||||
task_vars = dict()
|
||||
|
||||
result = super(ActionModule, self).run(tmp, task_vars)
|
||||
del tmp # tmp no longer has any effect
|
||||
|
||||
try:
|
||||
if not HAS_TEXTFSM:
|
||||
raise AnsibleError('textfsm_parser engine requires the TextFSM library to be installed')
|
||||
|
||||
try:
|
||||
filename = self._task.args.get('file')
|
||||
src = self._task.args.get('src')
|
||||
content = self._task.args['content']
|
||||
name = self._task.args.get('name')
|
||||
except KeyError as exc:
|
||||
raise AnsibleError('missing required argument: %s' % exc)
|
||||
|
||||
if src and filename:
|
||||
raise AnsibleError('`src` and `file` are mutually exclusive arguments')
|
||||
|
||||
if not isinstance(content, string_types):
|
||||
return {'failed': True, 'msg': '`content` must be of type str, got %s' % type(content)}
|
||||
|
||||
if filename:
|
||||
tmpl = open(filename)
|
||||
else:
|
||||
tmpl = StringIO()
|
||||
tmpl.write(src.strip())
|
||||
tmpl.seek(0)
|
||||
|
||||
try:
|
||||
re_table = textfsm.TextFSM(tmpl)
|
||||
fsm_results = re_table.ParseText(content)
|
||||
|
||||
except Exception as exc:
|
||||
raise AnsibleError(str(exc))
|
||||
|
||||
final_facts = []
|
||||
for item in fsm_results:
|
||||
facts = {}
|
||||
facts.update(dict(zip(re_table.header, item)))
|
||||
final_facts.append(facts)
|
||||
|
||||
if name:
|
||||
result['ansible_facts'] = {name: final_facts}
|
||||
else:
|
||||
result['ansible_facts'] = {}
|
||||
|
||||
finally:
|
||||
self._remove_tmp_path(self._connection._shell.tmpdir)
|
||||
|
||||
return result
|
||||
@@ -0,0 +1,127 @@
|
||||
# (c) 2018, Ansible by Red Hat, inc
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
||||
'status': ['preview'],
|
||||
'supported_by': 'network'}
|
||||
|
||||
DOCUMENTATION = """
|
||||
---
|
||||
module: validate_role_spec
|
||||
author: Peter Sprygada (@privateip
|
||||
short_description: Validate required arguments are set from facts
|
||||
description:
|
||||
- This module will accept an external argument spec file that will be used to
|
||||
validate arguments have been configured and set properly in order to allow
|
||||
the role to proceed. This validate specification file provides the
|
||||
equivalent of the Ansible module argument spec.
|
||||
version_added: "2.7"
|
||||
options:
|
||||
spec:
|
||||
description:
|
||||
- Relative or absolute path to the arugment specification file to use to
|
||||
validate arguments are properly set for role execution.
|
||||
required: yes
|
||||
"""
|
||||
|
||||
EXAMPLES = """
|
||||
- name: use spec file for role validation
|
||||
validate_role_spec:
|
||||
spec: args.yaml
|
||||
"""
|
||||
|
||||
RETURN = """
|
||||
"""
|
||||
import os
|
||||
import json
|
||||
|
||||
from ansible.plugins.action import ActionBase
|
||||
from ansible.module_utils._text import to_text, to_bytes
|
||||
from ansible.module_utils.six import iteritems, string_types
|
||||
from ansible.module_utils import basic
|
||||
from ansible.errors import AnsibleModuleError
|
||||
from ansible.utils.display import Display
|
||||
|
||||
display = Display()
|
||||
|
||||
|
||||
class ActionModule(ActionBase):
|
||||
|
||||
VALID_MODULE_KWARGS = (
|
||||
'argument_spec', 'mutually_exclusive', 'required_if',
|
||||
'required_one_of', 'required_together'
|
||||
)
|
||||
|
||||
def run(self, tmp=None, task_vars=None):
|
||||
''' handler for cli operations '''
|
||||
|
||||
if task_vars is None:
|
||||
task_vars = dict()
|
||||
|
||||
result = super(ActionModule, self).run(tmp, task_vars)
|
||||
del tmp # tmp no longer has any effect
|
||||
|
||||
try:
|
||||
spec = self._task.args['spec']
|
||||
except KeyError as exc:
|
||||
raise AnsibleModuleError(to_text(exc))
|
||||
|
||||
if not spec:
|
||||
raise AnsibleModuleError('missing required argument: spec')
|
||||
|
||||
spec_fp = os.path.join(task_vars['role_path'], 'meta/%s' % spec)
|
||||
display.vvv('using role spec %s' % spec_fp)
|
||||
spec = self._loader.load_from_file(spec_fp)
|
||||
|
||||
if 'argument_spec' not in spec:
|
||||
return {'failed': True, 'msg': 'missing required field in specification file: argument_spec'}
|
||||
|
||||
argument_spec = spec['argument_spec']
|
||||
|
||||
args = {}
|
||||
self._handle_options(task_vars, args, argument_spec)
|
||||
|
||||
basic._ANSIBLE_ARGS = to_bytes(json.dumps({'ANSIBLE_MODULE_ARGS': args}))
|
||||
basic.AnsibleModule.fail_json = self.fail_json
|
||||
|
||||
spec = dict([(k, v) for k, v in iteritems(spec) if k in self.VALID_MODULE_KWARGS])
|
||||
validated_spec = basic.AnsibleModule(**spec)
|
||||
|
||||
result['role_params'] = validated_spec.params
|
||||
result['changed'] = False
|
||||
self._remove_tmp_path(self._connection._shell.tmpdir)
|
||||
|
||||
return result
|
||||
|
||||
def fail_json(self, msg):
|
||||
raise AnsibleModuleError(msg)
|
||||
|
||||
def _handle_options(self, task_vars, args, spec):
|
||||
for key, attrs in iteritems(spec):
|
||||
if attrs is None:
|
||||
spec[key] = {'type': 'str'}
|
||||
elif isinstance(attrs, dict):
|
||||
suboptions_spec = attrs.get('options')
|
||||
if suboptions_spec:
|
||||
args[key] = dict()
|
||||
self._handle_options(task_vars, args[key], suboptions_spec)
|
||||
if key in task_vars:
|
||||
if isinstance(task_vars[key], string_types):
|
||||
value = self._templar.do_template(task_vars[key])
|
||||
if value:
|
||||
args[key] = value
|
||||
else:
|
||||
args[key] = task_vars[key]
|
||||
elif attrs:
|
||||
if 'aliases' in attrs:
|
||||
for item in attrs['aliases']:
|
||||
if item in task_vars:
|
||||
args[key] = self._templar.do_template(task_vars[item])
|
||||
else:
|
||||
args[key] = None
|
||||
@@ -0,0 +1,188 @@
|
||||
# (c) 2019, Ansible Inc,
|
||||
#
|
||||
# This file is part of Ansible
|
||||
#
|
||||
# Ansible is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Ansible is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import os
|
||||
import yaml
|
||||
import copy
|
||||
import re
|
||||
|
||||
from ansible import constants as C
|
||||
from ansible.module_utils._text import to_text
|
||||
from ansible.playbook.role.requirement import RoleRequirement
|
||||
from ansible.plugins.action import ActionBase
|
||||
from ansible.utils.display import Display
|
||||
|
||||
|
||||
display = Display()
|
||||
|
||||
|
||||
class ActionModule(ActionBase):
|
||||
|
||||
def run(self, tmp=None, task_vars=None):
|
||||
result = super(ActionModule, self).run(task_vars=task_vars)
|
||||
self.META_MAIN = os.path.join('meta', 'main.yml')
|
||||
self.META_INSTALL = os.path.join('meta', '.galaxy_install_info')
|
||||
|
||||
try:
|
||||
role_path = self._task.args.get('role_path')
|
||||
role_root_dir = os.path.split(role_path)[0]
|
||||
except KeyError as exc:
|
||||
return {'failed': True, 'msg': 'missing required argument: %s' % exc}
|
||||
|
||||
# Get dependancy version dict if not encoded in meta
|
||||
depends_dict = self._task.args.get('depends_map')
|
||||
|
||||
try:
|
||||
self._depends = self._get_role_dependencies(role_path)
|
||||
# check if we know min_version for each dependant role
|
||||
# from meta file or through user input to this plugin
|
||||
(rc, msg) = self._check_depends(self._depends, depends_dict)
|
||||
if not rc:
|
||||
result['failed'] = True
|
||||
result['msg'] = msg
|
||||
return result
|
||||
default_roles_path = copy.copy(C.DEFAULT_ROLES_PATH)
|
||||
default_roles_path.append(role_root_dir)
|
||||
(rc, msg) = self._find_dependant_role_version(
|
||||
self._depends, default_roles_path)
|
||||
|
||||
if rc == 'Error':
|
||||
result['failed'] = True
|
||||
result['msg'] = msg
|
||||
elif rc == 'Warning':
|
||||
result['changed'] = True
|
||||
result['Warning'] = True
|
||||
result['msg'] = msg
|
||||
elif rc == 'Success':
|
||||
result['changed'] = False
|
||||
result['msg'] = msg
|
||||
except Exception as exc:
|
||||
result['failed'] = True
|
||||
result['msg'] = ('Exception received : %s' % exc)
|
||||
|
||||
return result
|
||||
|
||||
def _get_role_dependencies(self, role_path):
|
||||
role_dependencies = []
|
||||
dep_info = None
|
||||
meta_path = os.path.join(role_path, self.META_MAIN)
|
||||
if os.path.isfile(meta_path):
|
||||
try:
|
||||
f = open(meta_path, 'r')
|
||||
metadata = yaml.safe_load(f)
|
||||
role_dependencies = metadata.get('dependencies') or []
|
||||
except (OSError, IOError):
|
||||
display.vvv("Unable to load metadata for %s" % role_path)
|
||||
return False
|
||||
finally:
|
||||
f.close()
|
||||
if role_dependencies:
|
||||
for dep in role_dependencies:
|
||||
dep_req = RoleRequirement()
|
||||
dep_info = dep_req.role_yaml_parse(dep)
|
||||
|
||||
return dep_info
|
||||
|
||||
def _find_dependant_role_version(self, dep_role, search_role_path):
|
||||
found = False
|
||||
dep_role_list = []
|
||||
if isinstance(dep_role, dict):
|
||||
# single role dependancy
|
||||
dep_role_list.append(dep_role)
|
||||
else:
|
||||
dep_role_list = dep_role
|
||||
|
||||
# First preferrence is to find role in defined C.default_roles_path
|
||||
for roles in dep_role_list:
|
||||
for r_path in search_role_path:
|
||||
dep_role_path = os.path.join(r_path, roles['name'])
|
||||
if os.path.exists(dep_role_path):
|
||||
found = True
|
||||
install_ver = self._get_role_version(dep_role_path)
|
||||
if install_ver == 'unknown':
|
||||
msg = "WARNING! : role: %s installed version is unknown " \
|
||||
"please check version if you downloded it from scm" % roles['name']
|
||||
return ("Warning", msg)
|
||||
if install_ver < roles['version']:
|
||||
msg = "Error! : role: %s installed version :%s is less than " \
|
||||
"required version: %s" % (roles['name'],
|
||||
install_ver, roles['version'])
|
||||
return ("Error", msg)
|
||||
if not found:
|
||||
msg = "role : %s is not installed in role search path: %s" \
|
||||
% (roles['name'], search_role_path)
|
||||
return ("Error", msg)
|
||||
|
||||
return ("Success", 'Success: All dependent roles meet min version requirements')
|
||||
|
||||
def _check_depends(self, depends, depends_dict):
|
||||
depends_list = []
|
||||
if isinstance(depends, dict):
|
||||
# single role dependancy
|
||||
depends_list.append(depends)
|
||||
else:
|
||||
depends_list = depends
|
||||
for dep in depends_list:
|
||||
if dep['version'] and depends_dict is None:
|
||||
# Nothing to be done. Use version from meta
|
||||
return (True, '')
|
||||
if dep['version'] is None and depends_dict is None:
|
||||
msg = "could not find min version from meta for dependent role : %s" \
|
||||
" you can pass this info as depends_map arg e.g." \
|
||||
"depends_map: - name: %s \n version: 2.6.5" \
|
||||
% (dep['name'], dep['name'])
|
||||
return (False, msg)
|
||||
# Galaxy might return empty string when meta does not have version
|
||||
# specified
|
||||
if dep['version'] == '' and depends_dict is None:
|
||||
msg = "could not find min version from meta for dependent role : %s" \
|
||||
" you can pass this info as depends_map arg e.g." \
|
||||
"depends_map: - name: %s \n version: 2.6.5" \
|
||||
% (dep['name'], dep['name'])
|
||||
return (False, msg)
|
||||
for in_depends in depends_dict:
|
||||
if in_depends['name'] == dep['name']:
|
||||
if in_depends['version'] is None:
|
||||
msg = 'min_version for role_name: %s is Unknown' % dep['name']
|
||||
return (False, msg)
|
||||
else:
|
||||
ver = to_text(in_depends['version'])
|
||||
# if version is defined without 'v<>' add 'v' for
|
||||
# compliance with galaxy versioning
|
||||
galaxy_compliant_ver = re.sub(r'^(\d+\..*)', r'v\1', ver)
|
||||
dep['version'] = galaxy_compliant_ver
|
||||
return (True, '')
|
||||
|
||||
def _get_role_version(self, role_path):
|
||||
version = "unknown"
|
||||
install_info = None
|
||||
info_path = os.path.join(role_path, self.META_INSTALL)
|
||||
if os.path.isfile(info_path):
|
||||
try:
|
||||
f = open(info_path, 'r')
|
||||
install_info = yaml.safe_load(f)
|
||||
except (OSError, IOError):
|
||||
display.vvv(
|
||||
"Unable to load galaxy install info for %s" % role_path)
|
||||
return "unknown"
|
||||
finally:
|
||||
f.close()
|
||||
if install_info:
|
||||
version = install_info.get("version", None)
|
||||
return version
|
||||
7
roles/ansible-network.network-engine/bindep.txt
Normal file
7
roles/ansible-network.network-engine/bindep.txt
Normal file
@@ -0,0 +1,7 @@
|
||||
# This is a cross-platform list tracking distribution packages needed by tests;
|
||||
# see http://docs.openstack.org/infra/bindep/ for additional information.
|
||||
|
||||
gcc-c++ [test platform:rpm]
|
||||
python3-devel [test !platform:centos-7 platform:rpm]
|
||||
python3 [test !platform:centos-7 platform:rpm]
|
||||
python36 [test !platform:centos-7 !platform:fedora-28]
|
||||
22
roles/ansible-network.network-engine/changelogs/config.yaml
Normal file
22
roles/ansible-network.network-engine/changelogs/config.yaml
Normal file
@@ -0,0 +1,22 @@
|
||||
---
|
||||
# FIXME GUNDALOW: This file will need work once we have defined the Git Tag & branch strategy
|
||||
# Currently we've just copied ansible/ansible's changelogs/config.yaml
|
||||
release_tag_re: '(v(?:[\d.ab\-]|rc)+)'
|
||||
pre_release_tag_re: '(?P<pre_release>(?:[ab]|rc)+\d*)$'
|
||||
notesdir: fragments
|
||||
prelude_section_name: release_summary
|
||||
sections:
|
||||
- ['major_changes', 'Major Changes']
|
||||
- ['minor_changes', 'Minor Changes']
|
||||
- ['deprecated_features', 'Deprecated Features']
|
||||
- ['removed_features', 'Removed Features (previously deprecated)']
|
||||
- ['new_lookup_plugins', 'New Lookup Plugins']
|
||||
- ['new_callback_plugins', 'New Callback Plugins']
|
||||
- ['new_connection_plugins', 'New Connection Plugins']
|
||||
- ['new_test_plugins', 'New Test Plugins']
|
||||
- ['new_filter_plugins', 'New Filter Plugins']
|
||||
- ['new_modules', 'New Modules']
|
||||
- ['new_tasks', 'New Tasks']
|
||||
- ['bugfixes', 'Bugfixes']
|
||||
- ['known_issues', 'Known Issues']
|
||||
- ['docs', 'Documentation Updates']
|
||||
@@ -0,0 +1,13 @@
|
||||
---
|
||||
major_changes:
|
||||
- Initial release of the ``network-engine`` Ansible role.
|
||||
- This role provides the foundation for building network roles by providing modules and plugins that are common to all Ansible Network roles. All of the artifacts in this role can be used independent of the platform that is being managed.
|
||||
|
||||
new_modules:
|
||||
- NEW ``text_parser`` Parses ASCII text into JSON facts using text_parser engine and YAML-formatted input.
|
||||
Provides a rules-based text parser that is closely modeled after the Ansible
|
||||
playbook language. This parser will iterate over the rules and parse the
|
||||
output of structured ASCII text into a JSON data structure that can be
|
||||
added to the inventory host facts.
|
||||
- NEW ``textfsm`` Parses ASCII text into JSON facts using textfsm engine and Google TextFSM-formatted input.
|
||||
Provides textfsm rules-based templates to parse data from text. The template acting as parser will iterate of the rules and parse the output of structured ASCII text into a JSON data structure that can be added to the inventory host facts.
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
bugfixes:
|
||||
- Fix ``command_parser`` Absolute path with tilde in src should work `network-engine#58 <https://github.com/ansible-network/network-engine/pull/58>`_
|
||||
- Fix content mush only accepts string type `network-engine#72 <https://github.com/ansible-network/network-engine/pull/72>`_
|
||||
- Fix StringIO to work with Python3 in addition to Python2 `network-engine#53 <https://github.com/ansible-network/network-engine/pull/53>`_
|
||||
@@ -0,0 +1,3 @@
|
||||
---
|
||||
docs:
|
||||
- User Guide `docs/user_guide <https://github.com/ansible-network/network-engine/tree/devel/docs/user_guide>`_.
|
||||
@@ -0,0 +1,8 @@
|
||||
---
|
||||
new_modules:
|
||||
- New module ``command_parser`` (renamed from ``text_parser``)
|
||||
- New module ``textfsm_parser`` (renamed from ``textfsm``)
|
||||
|
||||
deprecated_features:
|
||||
- Module ``text_parser`` renamed to ``command_parser``; original name deprecated; legacy use supported; will be removed in 2.6.0.
|
||||
- Module ``textfsm`` renamed to ``textfsm_parser``; original name deprecated; legacy use supported; will be removed in 2.6.0.
|
||||
@@ -0,0 +1,3 @@
|
||||
---
|
||||
bugfixes:
|
||||
- Fix AnsibleFilterError, deprecations, and unused imports `network-engine#82 <https://github.com/ansible-network/network-engine/pull/82>`_.
|
||||
@@ -0,0 +1,6 @@
|
||||
---
|
||||
new_filter_plugins:
|
||||
- New filter plugin ``interface_range``
|
||||
- New filter plugin ``interface_split``
|
||||
- New filter plugin ``vlan_compress``
|
||||
- New filter plugin ``vlan_expand``
|
||||
@@ -0,0 +1,6 @@
|
||||
---
|
||||
new_lookup_plugins:
|
||||
- New lookup plugin ``json_template``
|
||||
- New lookup plugin ``network_template``
|
||||
- New lookup plugin ``yang2spec``
|
||||
- New lookup plugin ``netcfg_diff``
|
||||
@@ -0,0 +1,4 @@
|
||||
---
|
||||
minor_changes:
|
||||
- Add new directives extend `network-engine#91 <https://github.com/ansible-network/network-engine/pull/91>`_.
|
||||
- Adds conditional support to nested template objects `network-engine#55 <https://github.com/ansible-network/network-engine/pull/55>`_.
|
||||
@@ -0,0 +1,3 @@
|
||||
---
|
||||
new_tasks:
|
||||
- New task ``cli``
|
||||
@@ -0,0 +1,3 @@
|
||||
---
|
||||
minor_changes:
|
||||
- Templating the regex sent to the parser to allow us to use ansible variables in the regex string `network-engine#97 <https://github.com/ansible-network/network-engine/pull/97>`_.
|
||||
@@ -0,0 +1,3 @@
|
||||
---
|
||||
removed_features:
|
||||
- Move yang2spec lookup to feature branch, till the right location for this plugin is identified `network-engine#100 <https://github.com/ansible-network/network-engine/pull/100>`_.
|
||||
@@ -0,0 +1,4 @@
|
||||
---
|
||||
bugfixes:
|
||||
- Fix cli task parser undefined issue when only command is used `network-engine#103 <https://github.com/ansible-network/network-engine/pull/103>`_.
|
||||
- Fix an issue with using the extend directive with a loop `network-engine#105 <https://github.com/ansible-network/network-engine/pull/105>`_.
|
||||
@@ -0,0 +1,4 @@
|
||||
---
|
||||
minor_changes:
|
||||
- Add parsers to search path `network-engine#89 <https://github.com/ansible-network/network-engine/pull/89>`_.
|
||||
- Fix export_as templating vars `network-engine#104 <https://github.com/ansible-network/network-engine/pull/104>`_.
|
||||
@@ -0,0 +1,3 @@
|
||||
---
|
||||
major_changes:
|
||||
- Initial release of 2.6.0 ``network-engine`` Ansible role that is supported with Ansible 2.6.0
|
||||
@@ -0,0 +1,3 @@
|
||||
---
|
||||
bugfixes:
|
||||
- Fixes bug when loading a dir of parsers `network-engine#113 <https://github.com/ansible-network/network-engine/pull/113>`_.
|
||||
@@ -0,0 +1,3 @@
|
||||
---
|
||||
docs:
|
||||
- The argument to end a block of text when searching with match_greedy was missing `network-engine#116 <https://github.com/ansible-network/network-engine/pull/116>`_.
|
||||
@@ -0,0 +1,3 @@
|
||||
---
|
||||
bugfixes:
|
||||
- Fix role path test dependency `network-engine#121 <https://github.com/ansible-network/network-engine/pull/121>`_.
|
||||
@@ -0,0 +1,3 @@
|
||||
---
|
||||
new_filter_plugins:
|
||||
- NEW ``to_lines`` filter plugin
|
||||
@@ -0,0 +1,4 @@
|
||||
---
|
||||
new_lookup_plugins:
|
||||
- NEW ``config_template`` lookup plugin
|
||||
- NEW ``yang_json2xml`` lookup plugin
|
||||
@@ -0,0 +1,3 @@
|
||||
---
|
||||
new_modules:
|
||||
- NEW ``validate_role_spec`` handle validating facts required by the role
|
||||
@@ -0,0 +1,3 @@
|
||||
---
|
||||
bugfixes:
|
||||
- Task to fail if ansible_min_version isn't met `network-engine#130 <https://github.com/ansible-network/network-engine/pull/130>`_.
|
||||
@@ -0,0 +1,3 @@
|
||||
---
|
||||
minor_changes:
|
||||
- Makes parser directive extend templatable `network-engine#132 <https://github.com/ansible-network/network-engine/pull/132>`_.
|
||||
@@ -0,0 +1,3 @@
|
||||
---
|
||||
bugfixes:
|
||||
- Fix repeat_for in json_template `network-engine#139 <https://github.com/ansible-network/network-engine/pull/139>`_.
|
||||
@@ -0,0 +1,3 @@
|
||||
---
|
||||
docs:
|
||||
- Removes unnecessary details from README `network-engine#126 <https://github.com/ansible-network/network-engine/pull/126>`_.
|
||||
@@ -0,0 +1,4 @@
|
||||
---
|
||||
removed_features:
|
||||
- Remove deprecated module ``text_parser``.
|
||||
- Remove deprecated module ``textfsm``.
|
||||
@@ -0,0 +1,3 @@
|
||||
---
|
||||
bugfixes:
|
||||
- Remove GenericLinux from supported platforms `network-engine#145 <https://github.com/ansible-network/network-engine/pull/145>`_.
|
||||
@@ -0,0 +1,3 @@
|
||||
---
|
||||
minor_changes:
|
||||
- Capability to filter AnsibleModule kwargs `network-engine#149 <https://github.com/ansible-network/network-engine/pull/149>`_.
|
||||
@@ -0,0 +1,3 @@
|
||||
---
|
||||
removed_features:
|
||||
- Remove deprecated module ``cli_get``
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
bugfixes:
|
||||
- Fix native type conversion in json_template `network-engine#154 <https://github.com/ansible-network/network-engine/pull/154>`_.
|
||||
- Fix templating repeat_for `network-engine#190 <https://github.com/ansible-network/network-engine/pull/190>`_.
|
||||
- Add missing boilerplate for net_facts module `network-engine#194 <https://github.com/ansible-network/network-engine/pull/194>`_.
|
||||
@@ -0,0 +1,3 @@
|
||||
---
|
||||
major_changes:
|
||||
- Initial release of 2.7.0 ``network-engine`` Ansible role that is supported with Ansible 2.7.0
|
||||
@@ -0,0 +1,3 @@
|
||||
---
|
||||
minor_changes:
|
||||
- Add support for nested spec validation in validate_role_spec `network-engine#198 <https://github.com/ansible-network/network-engine/pull/198>`_.
|
||||
@@ -0,0 +1,4 @@
|
||||
---
|
||||
minor_changes:
|
||||
- Add name option for textfsm to create facts to key `network-engine#202 <https://github.com/ansible-network/network-engine/pull/202>`_.
|
||||
- Document name option for textfsm in cli plugin and update cli task `network-engine#205 <https://github.com/ansible-network/network-engine/pull/205>`_.
|
||||
@@ -0,0 +1,3 @@
|
||||
---
|
||||
deprecated_features:
|
||||
- Deprecate lookup plugin network_template `network-engine#215 <https://github.com/ansible-network/network-engine/pull/215>`_.
|
||||
@@ -0,0 +1,3 @@
|
||||
---
|
||||
minor_changes:
|
||||
- Add verify_depedent_role_version action plugin `network-engine#214 <https://github.com/ansible-network/network-engine/pull/214>`_.
|
||||
@@ -0,0 +1,4 @@
|
||||
---
|
||||
bugfixes:
|
||||
- Fail validate_role_spec plugin if argument_spec is undefined `network-engine#221 <https://github.com/ansible-network/network-engine/pull/221>`_.
|
||||
- Fix relative path failure in command_parser when template is not present in playbook directory `network-engine#222 <https://github.com/ansible-network/network-engine/pull/222>`_.
|
||||
@@ -0,0 +1,3 @@
|
||||
---
|
||||
bugfixes:
|
||||
- Fix src_path to src command_parser `network-engine#230 <https://github.com/ansible-network/network-engine/pull/230>`_.
|
||||
19
roles/ansible-network.network-engine/defaults/main.yml
Normal file
19
roles/ansible-network.network-engine/defaults/main.yml
Normal file
@@ -0,0 +1,19 @@
|
||||
---
|
||||
# defaults file for network-engine
|
||||
#
|
||||
network_engine_path: "{{ role_path }}"
|
||||
network_engine_lib_path: "{{ network_engine_path }}/lib"
|
||||
|
||||
# defaults used in tasks/cli.yaml
|
||||
#
|
||||
# command to run on network device
|
||||
network_engine_command: "{{ command | default(None) }}"
|
||||
|
||||
# the path to parser file
|
||||
network_engine_parser: "{{ parser | default(None) }}"
|
||||
|
||||
# engine to use for parsing output to JSON facts
|
||||
network_engine_engine: "{{ engine | default('command_parser') }}"
|
||||
|
||||
# name to display facts for textfsm_parser
|
||||
network_engine_name: "{{ name | default(None) }}"
|
||||
@@ -0,0 +1,283 @@
|
||||
# CLI Parser Directives
|
||||
|
||||
The `command_parser` module is a module that can be used to parse the results of
|
||||
text strings into Ansible facts. The primary motivation for developing the
|
||||
`command_parser` module is to convert structured ASCII text output (such as
|
||||
the stdout returned from network devices) into JSON data structures suitable to be
|
||||
used as host facts.
|
||||
|
||||
The parser template file format is loosely based on the Ansible playbook directives
|
||||
language. It uses the Ansible directive language to ease the transition from
|
||||
writing playbooks to writing parser templates. However, parser templates developed using this
|
||||
module are not written directly into the playbook, but are a separate file
|
||||
called from playbooks. This is done for a variety of reasons but most notably
|
||||
to keep separation between the parsing logic and playbook execution.
|
||||
|
||||
The `command_parser` works based on a set of directives that perform actions
|
||||
on structured data with the end result being a valid JSON structure that can be
|
||||
returned to the Ansible facts system.
|
||||
|
||||
## Parser language
|
||||
|
||||
The parser template format uses YAML formatting, providing an ordered list of directives
|
||||
to be performed on the content (provided by the module argument). The overall
|
||||
general structure of a directive is as follows:
|
||||
|
||||
```yaml
|
||||
- name: some description name of the task to be performed
|
||||
directive:
|
||||
argument: value
|
||||
argument_option: value
|
||||
argument: value
|
||||
directive_option: value
|
||||
directive_option: value
|
||||
```
|
||||
|
||||
The `command_parser` currently supports the following top-level directives:
|
||||
|
||||
* `pattern_match`
|
||||
* `pattern_group`
|
||||
* `json_template`
|
||||
* `export_facts`
|
||||
|
||||
In addition to the directives, the following common directive options are
|
||||
currently supported:
|
||||
|
||||
* `name`
|
||||
* `block`
|
||||
* `loop`
|
||||
* `loop_control`
|
||||
|
||||
* `loop_var`
|
||||
|
||||
* `when`
|
||||
* `register`
|
||||
* `export`
|
||||
* `export_as`
|
||||
* `extend`
|
||||
|
||||
Any of the directive options are accepted but in some cases, the option may
|
||||
provide no operation. For instance, when using the `export_facts`
|
||||
directive, the options `register`, `export` and `export_as` are all
|
||||
ignored. The module should provide warnings when an option is ignored.
|
||||
|
||||
The following sections provide more details about how to use the parser
|
||||
directives to parse text into JSON structure.
|
||||
|
||||
## Directive Options
|
||||
|
||||
This section provides details on the various options that are available to be
|
||||
configured on any directive.
|
||||
|
||||
### `name`
|
||||
|
||||
All entries in the parser template many contain a `name` directive. The
|
||||
`name` directive can be used to provide an arbitrary description as to the
|
||||
purpose of the parser items. The use of `name` is optional for all
|
||||
directives.
|
||||
|
||||
The default value for `name` is `null`.
|
||||
|
||||
### `register`
|
||||
|
||||
Use the `register` option to register the results of a directive operation
|
||||
temporarily into the variable name you specify
|
||||
so you can retrieve it later in your parser template. You use `register` in
|
||||
a parser template just as you would in an Ansible playbook.
|
||||
|
||||
Variables created with `register` alone are not available outside of the parser context.
|
||||
Any values registered are only available within the scope of the parser activities.
|
||||
If you want to provide values back to the playbook, you must also define the [export](#export) option.
|
||||
|
||||
Typically you will use `register` alone for parsing each individual part of the
|
||||
command output, then amalgamate them into a single variable at the end of the parser template,
|
||||
register that variable and set `export: yes` on it.
|
||||
|
||||
The default value for `register` is `null`.
|
||||
|
||||
<a id="export"></a>
|
||||
|
||||
### `export`
|
||||
|
||||
Use the `export` option to export any value back to the calling task as an
|
||||
Ansible fact. The `export` option accepts a boolean value that defines if
|
||||
the registered fact should be exported to the calling task in the playbook (or
|
||||
role) scope. To export the value, simply set `export` to True.
|
||||
|
||||
Note this option requires the `register` value to be set in some cases and will
|
||||
produce a warning message if the `register` option is not provided.
|
||||
|
||||
The default value for `export` is `False`.
|
||||
|
||||
### `export_as`
|
||||
|
||||
Use the `export_as` option to export a value back to the calling task as an
|
||||
Ansible fact in a specific format. The `export_as` option defines the structure of the exported data.
|
||||
Accepted values for `export_as`:
|
||||
|
||||
* `dict`
|
||||
* `hash`
|
||||
* `object`
|
||||
* `list`
|
||||
* `elements` that defines the structure
|
||||
|
||||
**Note** this option requires the `register` value to be set and `export: True`.
|
||||
Variables can also be used with `export_as`.
|
||||
How to use variable with `export_as` is as follows:
|
||||
|
||||
Variable should be defined in vars or defaults or in playbook.
|
||||
```yaml
|
||||
vars:
|
||||
export_type: "list"
|
||||
```
|
||||
|
||||
Parser file needs to have the variable set to `export_as`.
|
||||
```
|
||||
export_as: "{{ export_type }}"
|
||||
```
|
||||
|
||||
### `extend`
|
||||
|
||||
Use the `extend` option to extend a current fact hierarchy with the new
|
||||
registered fact. This will case the facts to be merged and returned as a
|
||||
single tree. If the fact doesn't previously exist, this will create the entire
|
||||
structure.
|
||||
|
||||
The default value for `extend` is `null`.
|
||||
|
||||
### loop
|
||||
|
||||
Use the `loop` option to loop over a directive in order to process values.
|
||||
With the `loop` option, the parser will iterate over the directive and
|
||||
provide each of the values provided by the loop content to the directive for
|
||||
processing.
|
||||
|
||||
Access to the individual items is the same as it would be for Ansible
|
||||
playbooks. When iterating over a list of items, you can access the individual
|
||||
item using the `{{ item }}` variable. When looping over a hash, you can
|
||||
access `{{ item.key }}` and `{{ item.value }}`.
|
||||
|
||||
### `loop_control`
|
||||
|
||||
Use the `loop_control` option to specify the name of the variable to be
|
||||
used for the loop instead of default loop variable `item`.
|
||||
When looping over a hash, you can access `{{ foo.key }}` and `{{ foo.value }}` where `foo`
|
||||
is `loop_var`.
|
||||
The general structure of `loop_control` is as follows:
|
||||
|
||||
```yaml
|
||||
- name: User defined variable
|
||||
pattern_match:
|
||||
regex: "^(\\S+)"
|
||||
content: "{{ foo }}"
|
||||
loop: "{{ context }}"
|
||||
loop_control:
|
||||
loop_var: foo
|
||||
|
||||
```
|
||||
|
||||
### `when`
|
||||
|
||||
Use the `when` option to place a condition on the directive to
|
||||
decided if it is executed or not. The `when` option operates the same as
|
||||
it would in an Ansible playbook.
|
||||
|
||||
For example, if you only want to perform the match statement
|
||||
when the value of `ansible_network_os` is set to `ios`, you can apply
|
||||
the `when` conditional like this:
|
||||
|
||||
```yaml
|
||||
- name: conditionally matched var
|
||||
pattern_match:
|
||||
regex: "hostname (.+)"
|
||||
when: ansible_network_os == 'ios'
|
||||
```
|
||||
|
||||
## Directives
|
||||
|
||||
The directives perform actions on the content using regular expressions to
|
||||
extract various values. Each directive provides some additional arguments that
|
||||
can be used to perform its operation.
|
||||
|
||||
### `pattern_match`
|
||||
|
||||
Use the `pattern_match` directive to extract one or more values from
|
||||
the structured ASCII text based on regular expressions.
|
||||
|
||||
The following arguments are supported for this directive:
|
||||
|
||||
* `regex`
|
||||
* `content`
|
||||
* `match_all`
|
||||
* `match_greedy`
|
||||
* `match_until` : Sets a ending boundary for `match_greedy`.
|
||||
|
||||
The `regex` argument templates the value given to it so variables and filters can be used.
|
||||
Example :
|
||||
```yaml
|
||||
- name: Use a variable and a filter
|
||||
pattern_match:
|
||||
regex: "{{ inventory_hostname | lower }} (.+)"
|
||||
```
|
||||
|
||||
### `pattern_group`
|
||||
|
||||
Use the `pattern_group` directive to group multiple
|
||||
`pattern_match` results together.
|
||||
|
||||
The following arguments are supported for this directive:
|
||||
|
||||
* `json_template`
|
||||
* `set_vars`
|
||||
* `export_facts`
|
||||
|
||||
### `json_template`
|
||||
|
||||
Use the `json_template` directive to create a JSON data structure based on a
|
||||
template. This directive will allow you to template out a multi-level JSON
|
||||
blob.
|
||||
|
||||
The following arguments are supported for this directive:
|
||||
|
||||
* `template`
|
||||
|
||||
|
||||
**Note**
|
||||
Native jinja2 datatype (eg. 'int', 'float' etc.) rendering is supported with Ansible version >= 2.7
|
||||
and jinja2 library version >= 2.10. To enable native jinja2 config add below configuration in active
|
||||
ansible configuration file.
|
||||
```
|
||||
[defaults]
|
||||
jinja2_native= True
|
||||
```
|
||||
|
||||
Usage example:
|
||||
```yaml
|
||||
- set_fact:
|
||||
count: "1"
|
||||
|
||||
- name: print count
|
||||
debug:
|
||||
msg: "{{ count|int }}"
|
||||
```
|
||||
|
||||
With jinja2_native configuration enabled the output of above example task will have
|
||||
```
|
||||
"msg": 1
|
||||
```
|
||||
|
||||
and with jinja2_native configuration disabled (default) output of above example task will have
|
||||
```
|
||||
"msg": "1"
|
||||
```
|
||||
|
||||
### `set_vars`
|
||||
|
||||
Use the `set_vars` directive to set variables to the values like key / value pairs
|
||||
and return a dictionary.
|
||||
|
||||
### `export_facts`
|
||||
|
||||
Use the `export_facts` directive to take an arbitrary set of key / value pairs
|
||||
and expose (return) them back to the playbook global namespace. Any key /
|
||||
value pairs that are provided in this directive become available on the host.
|
||||
@@ -0,0 +1,276 @@
|
||||
# CLI Template Directives
|
||||
|
||||
**Note** `network_template` lookup plugin is deprecated in v2.7.3 and will be removed
|
||||
in version v2.7.7 i.e, four releases from the deprecation version.
|
||||
|
||||
The `network_template` module supports a number of keyword based objectives that
|
||||
handle how to process the template. Templates are broken up into a series
|
||||
of blocks that process lines. Blocks are logical groups that have a common
|
||||
set of properties in common.
|
||||
|
||||
Blocks can also include other template files and are processed in the same
|
||||
manner as lines. See includes below for a description on how to use the
|
||||
include directive.
|
||||
|
||||
The template module works by processing the lines directives in sequential
|
||||
order. The module will attempt to template each line in the lines directive
|
||||
and, if successful, add the line to the final output. Values used for
|
||||
variable substitution come from the host facts. If the line could not
|
||||
be successfully templated, the line is skipped and a warning message is
|
||||
displayed that the line could not be templated.
|
||||
|
||||
There are additional directives that can be combined to support looping over
|
||||
lists and hashes as well as applying conditional statements to blocks, lines
|
||||
and includes.
|
||||
|
||||
## `name`
|
||||
|
||||
Entries in the template may contain a `name` field. The `name` field
|
||||
is used to provide a description of the entry. It is also used to provide
|
||||
feedback when processing the template to indicate when an entry is
|
||||
skipped or fails.
|
||||
|
||||
## `lines`
|
||||
|
||||
The `lines` directive provides an ordered list of statements to attempt
|
||||
to template. Each entry in the `lines` directive will be evaluated for
|
||||
variable substitution. If the entry can be successfully templated, then the
|
||||
output will be added to the final set of entries. If the entry cannot be
|
||||
successfully templated, then the entry is ignored (skipped) and a warning
|
||||
message is provided. If the entry in the `lines` directive contains
|
||||
only static text (no variables), then the line will always be processed.
|
||||
|
||||
The `lines` directive also supports standard Jinja2 filters as well as any
|
||||
Ansible specific Jinja2 filters. For example, lets assume we want to add a
|
||||
default value if a more specific value was not assigned by a fact.
|
||||
|
||||
```yaml
|
||||
- name: render the system hostname
|
||||
lines:
|
||||
- "hostname {{ hostname | default(inventory_hostname_short }}"
|
||||
```
|
||||
|
||||
## `block`
|
||||
|
||||
A group of `lines` directives can be combined into a `block`
|
||||
directive. These `block` directives are used to apply a common set of
|
||||
values to one or more `lines` or `includes` entries.
|
||||
|
||||
For instance, a `block` directive that contains one or more `lines`
|
||||
entries could be use the same set of `loop` values or have a
|
||||
common `when` conditional statement applied to them.
|
||||
|
||||
## `include`
|
||||
|
||||
Sometimes it is advantageous to break up templates into separate files and
|
||||
combine them. The `include` directive will instruct the current template
|
||||
to load another template file and process it.
|
||||
|
||||
The `include` directive also supports variable substitution for the
|
||||
provided file name and can be processed with the `loop` and `when`
|
||||
directives.
|
||||
|
||||
## `when`
|
||||
|
||||
The `when` directive allows for conditional statements to be applied to
|
||||
a set of `lines`, a `block` and/or the `include` directive. The
|
||||
`when` statement is evaluated prior to processing the statements and if
|
||||
the condition is true, the statements will attempt to be templated. If the
|
||||
statement is false, the statements are skipped and a message returned.
|
||||
|
||||
## `loop`
|
||||
|
||||
Depending on the input facts, sometimes it is necessary to iterate over a
|
||||
set of statements. The `loop` directive allows the same set of statements
|
||||
to be processed in such a manner. The `loop` directive takes, as input,
|
||||
the name of a fact that is either a list or a hash and iterates over the
|
||||
statements for each entry.
|
||||
|
||||
When the provided fact is a list of items, the value will be assigned to a
|
||||
variable called `item` and can be referenced by the statements.
|
||||
|
||||
When the provided fact is a hash of items, the hash key will be assigned to
|
||||
the `item.key` variable and the hash value will be assigned to the
|
||||
`item.value` variable. Both can then be referenced by the statements.
|
||||
|
||||
## `loop_control`
|
||||
|
||||
The `loop_control` directive allows the template to configure aspects
|
||||
related to how loops are process. This directive provides a set of suboptions
|
||||
to configure how loops are processed.
|
||||
|
||||
### `loop_var`
|
||||
|
||||
The `loop_var` directive allows the template to override the default
|
||||
variable name `item`. This is useful when handling nested loops such
|
||||
that both inner and outer loops values can be accessed.
|
||||
|
||||
When setting the `loop_var` to some string, the string will replace
|
||||
`item` as the variable name used to access the values.
|
||||
|
||||
For example, lets assume instead of using item, we want to use a different
|
||||
variable name such as entry:
|
||||
|
||||
```yaml
|
||||
- name: render entries
|
||||
lines:
|
||||
- "hostname {{ entry.hostname }}"
|
||||
- "domain-name {{ entry.domain_name }}"
|
||||
loop: "{{ system }}"
|
||||
loop_control:
|
||||
loop_var: entry
|
||||
```
|
||||
|
||||
## `join`
|
||||
|
||||
When building template statements that include optional values for
|
||||
configuration, the `join` directive can be useful. The `join`
|
||||
directive instructs the template to combine the templated lines together
|
||||
into a single string to insert into the configuration.
|
||||
|
||||
For example, lets assume there is a need to add the following statement to
|
||||
the configuration:
|
||||
|
||||
```
|
||||
ip domain-name ansible.com vrf management
|
||||
ip domain-name redhat.com
|
||||
```
|
||||
|
||||
To support templating the above lines, the facts might include the domain-name
|
||||
and the vrf name values. Here is the example facts:
|
||||
|
||||
```yaml
|
||||
---
|
||||
system:
|
||||
- domain_name: ansible.com
|
||||
vrf: management
|
||||
- domain_name redhat.com
|
||||
```
|
||||
|
||||
And the template statement would be the following:
|
||||
|
||||
```yaml
|
||||
- name: render domain-name
|
||||
lines:
|
||||
- "ip domain-name {{ item.domain_name }}"
|
||||
- "vrf {{ item.vrf }}"
|
||||
loop: "{{ system }}"
|
||||
join: yes
|
||||
```
|
||||
|
||||
When this entry is processed, the first iteration will successfully template
|
||||
both lines and add `ip domain-name ansible.com vrf management` to the
|
||||
output.
|
||||
|
||||
When the second entry is processed, the first line will be successfully
|
||||
templated but since there is no management key, the second line will return a
|
||||
null value. The final line added to the configuration will be ` ip
|
||||
domain-name redhat.com`.
|
||||
|
||||
If the `join` directive had been omitted, then the final set of
|
||||
configuration statements would be as follows:
|
||||
|
||||
```
|
||||
ip domain-name ansible.com
|
||||
vrf management
|
||||
ip domain-name redhat.com
|
||||
```
|
||||
|
||||
## `join_delimiter`
|
||||
|
||||
When the `join` delimiter is used, the templated values are combined into a
|
||||
single string that is added to the final output. The lines are joined using a
|
||||
space. The delimiting character used when processing the `join` can be
|
||||
modified using `join_delimiter` directive.
|
||||
|
||||
Here is an example of using the this directive. Take the following entry:
|
||||
|
||||
```yaml
|
||||
- name: render domain-name
|
||||
lines:
|
||||
- "ip domain-name {{ item.domain_name }}"
|
||||
- "vrf {{ item.vrf }}"
|
||||
loop: "{{ system }}"
|
||||
join: yes
|
||||
join_delimiter: ,
|
||||
```
|
||||
|
||||
When the preceding statements are processed, the final output would be
|
||||
(assuming all variables are provided):
|
||||
|
||||
```
|
||||
ip domain-name ansible.com,vrf management
|
||||
ip domain-name redhat.com
|
||||
```
|
||||
|
||||
## `indent`
|
||||
|
||||
The `indent` directive is used to add one or more leading spaces to the
|
||||
final templated statement. It can be used to recreated a structured
|
||||
configuration file.
|
||||
|
||||
Take the following template entry as an example:
|
||||
|
||||
```yaml
|
||||
- name: render the interface context
|
||||
lines: "interface Ethernet0/1"
|
||||
|
||||
- name: render the interface configuration
|
||||
lines:
|
||||
- "ip address 192.168.10.1/24"
|
||||
- "no shutdown"
|
||||
- "description this is an example"
|
||||
indent: 3
|
||||
|
||||
- name: render the interface context
|
||||
lines: "!"
|
||||
```
|
||||
|
||||
Then the statements above are processed, the output will look like the
|
||||
following:
|
||||
|
||||
```
|
||||
interface Ethernet0/1
|
||||
ip address 192.168.10.1/24
|
||||
no shutdown
|
||||
description this is an example
|
||||
!
|
||||
```
|
||||
|
||||
## `required`
|
||||
|
||||
The `required` directive specifies that all of the statements must be
|
||||
templated otherwise a failure is generated. Essentially it is a way to
|
||||
make certain that the variables are defined.
|
||||
|
||||
For example, take the following:
|
||||
|
||||
```yaml
|
||||
- name: render router ospf context
|
||||
lines:
|
||||
- "router ospf {{ process_id }}"
|
||||
required: yes
|
||||
```
|
||||
|
||||
When the above is processed, if the variable `process_id` is not present,
|
||||
then the statement cannot be templated. Since the `required` directive
|
||||
is set to true, the statement will cause the template to generate a failure
|
||||
message.
|
||||
|
||||
## `missing_key`
|
||||
|
||||
By default, when statements are processed and a variable is undefined, the
|
||||
module will simply display a warning message to the screen. In some cases, it
|
||||
is desired to either suppress warning messages on a missing key or to force the
|
||||
module to fail on a missing key.
|
||||
|
||||
To change the default behaviour, use the `missing_key` directive. This
|
||||
directive accepts one of three choices:
|
||||
|
||||
* `ignore`
|
||||
* `warn` (default)
|
||||
* `fail`
|
||||
|
||||
The value of this directive will instruct the template how to handle any
|
||||
condition where the desired variable is undefined.
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
# network_engine filter plugins
|
||||
|
||||
The [filter_plugins/network_engine code](https://github.com/ansible-network/network-engine/blob/devel/library/filter_plugins/network_engine.py)
|
||||
offers four options for managing multiple interfaces and vlans.
|
||||
|
||||
## interface_split
|
||||
|
||||
The `interface_split` plugin splits an interface and returns its parts:
|
||||
|
||||
{{ 'Ethernet1' | interface_split }} returns '1' as index and 'Ethernet' as name
|
||||
|
||||
{{ 'Ethernet1' | interface_split('name') }} returns 'Ethernet'
|
||||
|
||||
{{ 'Ethernet1' | interface_split('index') }} returns '1'
|
||||
|
||||
[interface_split tests](https://github.com/ansible-network/network-engine/blob/devel/tests/interface_split/interface_split/tasks/interface_split.yaml)
|
||||
|
||||
## interface_range
|
||||
|
||||
The `interface_range` plugin expands an interface range and returns a list of the interfaces within that range:
|
||||
|
||||
{{ 'Ethernet1-3' | interface_range }} returns ['Ethernet1', 'Ethernet2', 'Ethernet3']
|
||||
|
||||
{{ 'Ethernet1,3-4,5' | interface_range }} returns ['Ethernet1', 'Ethernet3', 'Ethernet4', 'Ethernet5']
|
||||
|
||||
{{ 'Ethernet1/3-5,8' | interface_range }} returns ['Ethernet1/3', 'Ethernet1/4', 'Ethernet1/5', 'Ethernet1/8']
|
||||
|
||||
[interface_range tests](https://github.com/ansible-network/network-engine/blob/devel/tests/interface_range/interface_range/tasks/interface_range.yaml)
|
||||
|
||||
## vlan_compress
|
||||
|
||||
The `vlan_compress` plugin compresses a list of vlans into a range:
|
||||
|
||||
{{ 'vlan1,2,3,4,5' | vlan_compress }} returns ['1-5']
|
||||
|
||||
{{ 'vlan1,2,4,5' | vlan_compress }} returns ['1-2,4-5']
|
||||
|
||||
{{ 'vlan1,2,3,5' | vlan_compress }} returns ['1-3,5']
|
||||
|
||||
[vlan_compress tests](https://github.com/ansible-network/network-engine/blob/devel/tests/vlan_compress/vlan_compress/tasks/vlan_compress.yaml)
|
||||
|
||||
## vlan_expand
|
||||
|
||||
The `vlan_expand` plugin expands a vlan range and returns a list of the vlans within that range:
|
||||
|
||||
{{ 'vlan1,3-5,7' | vlan_expand }} returns [1,3,4,5,7]
|
||||
|
||||
{{ 'vlan1-5' | vlan_expand }} returns [1,2,3,4,5]
|
||||
|
||||
[vlan_expand tests](https://github.com/ansible-network/network-engine/blob/devel/tests/vlan_expand/vlan_expand/tasks/vlan_expand.yaml)
|
||||
@@ -0,0 +1,24 @@
|
||||
# Plugin verify_dependent_role_version
|
||||
|
||||
|
||||
The `verify_dependent_role_version` plugin checks for required minimum version of dependant roles.
|
||||
The plugin works only inside a role. It verifies the required minimum version of all roles are
|
||||
installed as defined under dependancies in meta/main.yml of the role.
|
||||
|
||||
## How to Use
|
||||
|
||||
meta/main.yml
|
||||
|
||||
```yaml
|
||||
dependencies:
|
||||
- src: ansible-network.network-engine
|
||||
version: v2.7.2
|
||||
```
|
||||
|
||||
tasks/main.yml
|
||||
|
||||
```yaml
|
||||
- name: Validate we have required minimum version of dependent roles installed
|
||||
verify_dependent_role_version:
|
||||
role_path: "{{ role_path }}"
|
||||
```
|
||||
125
roles/ansible-network.network-engine/docs/tasks/cli.md
Normal file
125
roles/ansible-network.network-engine/docs/tasks/cli.md
Normal file
@@ -0,0 +1,125 @@
|
||||
# Task cli
|
||||
The ```cli``` task provides an implementation for running CLI commands on
|
||||
network devices that is platform agnostic. The ```cli``` task accepts a
|
||||
command and will attempt to execute that command on the remote device returning
|
||||
the command ouput.
|
||||
|
||||
If the ```parser``` argument is provided, the output from the command will be
|
||||
passed through the parser and returned as JSON facts using the ```engine```
|
||||
argument.
|
||||
|
||||
|
||||
## Requirements
|
||||
The following is the list of requirements for using the this task:
|
||||
|
||||
* Ansible 2.5 or later
|
||||
* Connection ```network_cli```
|
||||
* ansible_network_os
|
||||
|
||||
## Arguments
|
||||
The following are the list of required and optional arguments supported by this
|
||||
task.
|
||||
|
||||
### command
|
||||
This argument specifies the command to be executed on the remote device. The
|
||||
```command``` argument is a required value.
|
||||
|
||||
### parser
|
||||
This argument specifies the location of the parser to pass the output from the command to
|
||||
in order to generate JSON data. The ```parser``` argument is an optional value, but required
|
||||
when ```engine``` is used.
|
||||
|
||||
### engine
|
||||
The ```engine``` argument is used to define which parsing engine to use when parsing the output
|
||||
of the CLI commands. This argument uses the file specified to ```parser``` for parsing output to
|
||||
JSON facts. This argument requires ```parser``` argument to be specified.
|
||||
|
||||
This action currently supports two different parsers:
|
||||
|
||||
* ```command_parser```
|
||||
* ```textfsm_parser```
|
||||
|
||||
The default value is ```command_parser```.
|
||||
|
||||
## How to use
|
||||
This section describes how to use the ```cli``` task in a playbook.
|
||||
|
||||
|
||||
The following example runs CLI command on the network node.
|
||||
```yaml
|
||||
|
||||
---
|
||||
- hosts: ios01
|
||||
connection: network_cli
|
||||
|
||||
tasks:
|
||||
- name: run cli command with cli task
|
||||
import_role:
|
||||
name: ansible-network.network-engine
|
||||
tasks_from: cli
|
||||
vars:
|
||||
ansible_network_os: ios
|
||||
command: show version
|
||||
|
||||
```
|
||||
|
||||
When run with verbose mode, the output returned is as follows:
|
||||
|
||||
```
|
||||
|
||||
ok: [ios01] => {
|
||||
"changed": false,
|
||||
"json": null,
|
||||
"stdout": "Cisco IOS Software, IOSv Software (VIOS-ADVENTERPRISEK9-M), Version 15.6(2)T, RELEASE SOFTWARE (fc2)\nTechnical Support: http://www.cisco.com/techsupport\nCopyright (c) 1986-2016 by Cisco Systems, Inc.\nCompiled Tue 22-Mar-16 16:19 by prod_rel_team\n\n\nROM: Bootstrap program is IOSv\n\nan-ios-01 uptime is 19 weeks, 5 days, 19 hours, 14 minutes\nSystem returned to ROM by reload\nSystem image file is \"flash0:/vios-adventerprisek9-m\"\nLast reload reason: Unknown reason\n\n\n\nThis product contains cryptographic features and is subject to United\nStates and local country laws governing import, export, transfer and\nuse. Delivery of Cisco cryptographic products does not imply\nthird-party authority to import, export, distribute or use encryption.\nImporters, exporters, distributors and users are responsible for\ncompliance with U.S. and local country laws. By using this product you\nagree to comply with applicable laws and regulations. If you are unable\nto comply with U.S. and local laws, return this product immediately.\n\nA summary of U.S. laws governing Cisco cryptographic products may be found at:\nhttp://www.cisco.com/wwl/export/crypto/tool/stqrg.html\n\nIf you require further assistance please contact us by sending email to\nexport@cisco.com.\n\nCisco IOSv (revision 1.0) with with 460033K/62464K bytes of memory.\nProcessor board ID 92O0KON393UV5P77JRKZ5\n4 Gigabit Ethernet interfaces\nDRAM configuration is 72 bits wide with parity disabled.\n256K bytes of non-volatile configuration memory.\n2097152K bytes of ATA System CompactFlash 0 (Read/Write)\n0K bytes of ATA CompactFlash 1 (Read/Write)\n0K bytes of ATA CompactFlash 2 (Read/Write)\n10080K bytes of ATA CompactFlash 3 (Read/Write)\n\n\n\nConfiguration register is 0x0"
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
The following example runs cli command and parse output to JSON facts.
|
||||
```yaml
|
||||
|
||||
---
|
||||
- hosts: ios01
|
||||
connection: network_cli
|
||||
|
||||
tasks:
|
||||
- name: run cli command and parse output to JSON facts
|
||||
import_role:
|
||||
name: ansible-network.network-engine
|
||||
tasks_from: cli
|
||||
vars:
|
||||
ansible_network_os: ios
|
||||
command: show version
|
||||
parser: parser_templates/ios/show_version.yaml
|
||||
engine: command_parser
|
||||
|
||||
```
|
||||
|
||||
When run with verbose mode, the output returned is as follows:
|
||||
|
||||
```
|
||||
|
||||
ok: [ios01] => {
|
||||
"ansible_facts": {
|
||||
"system_facts": {
|
||||
"image_file": "\"flash0:/vios-adventerprisek9-m\"",
|
||||
"memory": {
|
||||
"free": "62464K",
|
||||
"total": "460033K"
|
||||
},
|
||||
"model": "IOSv",
|
||||
"uptime": "19 weeks, 5 days, 19 hours, 34 minutes",
|
||||
"version": "15.6(2)T"
|
||||
}
|
||||
},
|
||||
"changed": false,
|
||||
"included": [
|
||||
"parser_templates/ios/show_version.yaml"
|
||||
],
|
||||
"json": null,
|
||||
"stdout": "Cisco IOS Software, IOSv Software (VIOS-ADVENTERPRISEK9-M), Version 15.6(2)T, RELEASE SOFTWARE (fc2)\nTechnical Support: http://www.cisco.com/techsupport\nCopyright (c) 1986-2016 by Cisco Systems, Inc.\nCompiled Tue 22-Mar-16 16:19 by prod_rel_team\n\n\nROM: Bootstrap program is IOSv\n\nan-ios-01 uptime is 19 weeks, 5 days, 19 hours, 34 minutes\nSystem returned to ROM by reload\nSystem image file is \"flash0:/vios-adventerprisek9-m\"\nLast reload reason: Unknown reason\n\n\n\nThis product contains cryptographic features and is subject to United\nStates and local country laws governing import, export, transfer and\nuse. Delivery of Cisco cryptographic products does not imply\nthird-party authority to import, export, distribute or use encryption.\nImporters, exporters, distributors and users are responsible for\ncompliance with U.S. and local country laws. By using this product you\nagree to comply with applicable laws and regulations. If you are unable\nto comply with U.S. and local laws, return this product immediately.\n\nA summary of U.S. laws governing Cisco cryptographic products may be found at:\nhttp://www.cisco.com/wwl/export/crypto/tool/stqrg.html\n\nIf you require further assistance please contact us by sending email to\nexport@cisco.com.\n\nCisco IOSv (revision 1.0) with with 460033K/62464K bytes of memory.\nProcessor board ID 92O0KON393UV5P77JRKZ5\n4 Gigabit Ethernet interfaces\nDRAM configuration is 72 bits wide with parity disabled.\n256K bytes of non-volatile configuration memory.\n2097152K bytes of ATA System CompactFlash 0 (Read/Write)\n0K bytes of ATA CompactFlash 1 (Read/Write)\n0K bytes of ATA CompactFlash 2 (Read/Write)\n10080K bytes of ATA CompactFlash 3 (Read/Write)\n\n\n\nConfiguration register is 0x0"
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
To know how to write a parser for ```command_parser``` or ```textfsm_parser``` engine, please follow the user guide [here](https://github.com/ansible-network/network-engine/blob/devel/docs/user_guide/README.md).
|
||||
@@ -0,0 +1,55 @@
|
||||
# Test Guide
|
||||
|
||||
The tests in network-engine are role based where the entry point is `tests/test.yml`.
|
||||
The tests for `textfsm_parser` and `command_parser` are run against `localhost`.
|
||||
|
||||
## How to run tests locally
|
||||
|
||||
```
|
||||
cd tests/
|
||||
ansible-playbook -i inventory test.yml
|
||||
```
|
||||
|
||||
## Role Structure
|
||||
|
||||
```
|
||||
role_name
|
||||
├── defaults
|
||||
│ └── main.yaml
|
||||
├── meta
|
||||
│ └── main.yaml
|
||||
├── output
|
||||
│ └── platform_name
|
||||
│ ├── show_interfaces.txt
|
||||
│ └── show_version.txt
|
||||
├── parser_templates
|
||||
│ └── platform_name
|
||||
│ ├── show_interfaces.yaml
|
||||
│ └── show_version.yaml
|
||||
└── tasks
|
||||
├── platform_name.yaml
|
||||
└── main.yaml
|
||||
```
|
||||
|
||||
If you add any new Role for test, make sure to include the role in `test.yml`:
|
||||
|
||||
```yaml
|
||||
|
||||
roles:
|
||||
- command_parser
|
||||
- textfsm_parser
|
||||
- $role_name
|
||||
```
|
||||
|
||||
## Add new platforms tests to an existing roles
|
||||
|
||||
Create directory with the `platform_name` in `output` and `parser_templates` directories
|
||||
which will contain output and parser files of the platform.
|
||||
|
||||
Add corresponding playbook with the `platform_name` in `tasks/$platform_name.yaml`
|
||||
and add an entry in `tasks/main.yaml`:
|
||||
|
||||
```yaml
|
||||
- name: platform_name command_parser test
|
||||
import_tasks: platform_name.yaml
|
||||
```
|
||||
@@ -0,0 +1,48 @@
|
||||
Using the Network Engine Role
|
||||
----------------------------------
|
||||
|
||||
The Network Engine role is supported as a dependency of other Roles. The Network Engine Role extracts data about your network devices as Ansible facts in a JSON data structure, ready to be added to your inventory host facts and/or consumed by Ansible tasks and templates. You define the data elements you want to extract from each network OS command in parser templates, using either YAML or Google TextFSM syntax. The matching rules may be different on each network platform, but by defining the same variable names for the output on all platforms, you can normalize similar data across platforms. That's how the Network Engine Role supports truly platform-agnostic network automation.
|
||||
|
||||
The Network Engine role can also be used directly, though direct usage is not supported with your Red Hat subscription.
|
||||
|
||||
The initial release of the Network Engine role includes two parser modules:
|
||||
* [command_parser](https://github.com/ansible-network/network-engine/blob/devel/docs/user_guide/command_parser.md) accepts YAML input, uses an internally maintained, loosely defined parsing language based on Ansible playbook directives
|
||||
* [textfsm_parser](https://github.com/ansible-network/network-engine/blob/devel/docs/user_guide/textfsm_parser.md) accepts Google TextFSM input, uses Google TextFSM parsing language
|
||||
|
||||
Both modules iterate over the data definitions in your parser templates, parse command output from your network devices (structured ASCII text) to find matches, and then convert the matches into Ansible facts in a JSON data structure.
|
||||
|
||||
The task ```cli``` provided by the role, can also be directly implemented in your playbook. The documentation can be found here [tasks/cli](https://github.com/ansible-network/network-engine/blob/devel/docs/tasks/cli.md).
|
||||
|
||||
To manage multiple interfaces and vlans, the Network Engine role also offers [filter_plugins](https://github.com/ansible-network/network-engine/blob/devel/docs/plugins/filter_plugins.md) that turn lists of Interfaces or VLANs into ranges and vice versa.
|
||||
|
||||
Modules:
|
||||
--------
|
||||
- `command_parser`
|
||||
- `textfsm_parser`
|
||||
- `net_facts`
|
||||
|
||||
To use the Network Engine Role:
|
||||
----------------------------------------
|
||||
1. Install the role from Ansible Galaxy
|
||||
`ansible-galaxy install ansible-network.network-engine` will copy the Network Engine role to `~/.ansible/roles/`.
|
||||
1. Select the parser engine you prefer
|
||||
For YAML formatting, use `command_parser`; for TextFSM formatting, use `textfsm_parser`. The parser docs include
|
||||
examples of how to define your data and create your tasks.
|
||||
1. Define the data you want to extract (or use a pre-existing parser template)
|
||||
See the parser_template sections of the command_parser and textfsm_parser docs for examples.
|
||||
1. Create a playbook to extract the data you've defined
|
||||
See the Playbook sections of the command_parser and textfsm_parser docs for examples.
|
||||
1. Run the playbook with `ansible-playbook -i /path/to/your/inventory -u my_user -k /path/to/your/playbook`
|
||||
1. Consume the JSON-formatted Ansible facts about your device(s) in inventory, templates, and tasks.
|
||||
|
||||
Additional Resources
|
||||
-------------------------------------
|
||||
|
||||
* [README](https://galaxy.ansible.com/ansible-network/network-engine/#readme)
|
||||
* [command_parser tests](https://github.com/ansible-network/network-engine/tree/devel/tests/command_parser)
|
||||
* [textfsm_parser tests](https://github.com/ansible-network/network-engine/tree/devel/tests/textfsm_parser)
|
||||
* [Full changelog diff](https://github.com/ansible-network/network-engine/blob/devel/CHANGELOG.rst)
|
||||
|
||||
Contributing and Reporting Feedback
|
||||
-------------------------------------
|
||||
[Review issues](https://github.com/ansible-network/network-engine/issues)
|
||||
@@ -0,0 +1,223 @@
|
||||
# command_parser
|
||||
|
||||
The [command_parser](https://github.com/ansible-network/network-engine/blob/devel/library/command_parser.py)
|
||||
module is closely modeled after the Ansible playbook language.
|
||||
This module iterates over matching rules defined in YAML format, extracts data from structured ASCII text based on those rules,
|
||||
and returns Ansible facts in a JSON data structure that can be added to the inventory host facts and/or consumed by Ansible tasks and templates.
|
||||
|
||||
The `command_parser` module requires two inputs:
|
||||
- the output of commands run on the network device, passed to the `content` parameter
|
||||
- the parser template that defines the rules for parsing the output, passed to either the `file` or the `dir` parameter
|
||||
|
||||
## Parameters
|
||||
|
||||
### content
|
||||
|
||||
The `content` parameter for `command_parser` must point to the ASCII text output of commands run on network devices. The text output can be in a variable or in a file.
|
||||
|
||||
|
||||
### file
|
||||
|
||||
The `file` parameter for `command_parser` must point to a parser template that contains a rule for each data field you want to extract from your network devices.
|
||||
|
||||
Parser templates for the `command_parser` module in the Network Engine role use YAML notation.
|
||||
|
||||
|
||||
### dir
|
||||
|
||||
Points to a directory containing parser templates. Use this parameter instead of `file` if your playbook uses multiple parser templates.
|
||||
|
||||
## Sample Parser Templates
|
||||
|
||||
Parser templates for the `command_parser` module in the Network Engine role use YAML syntax.
|
||||
To write a parser template, follow the [parser_directives documentation](docs/directives/parser_directives.md).
|
||||
|
||||
Here are two sample YAML parser templates:
|
||||
|
||||
`parser_templates/ios/show_interfaces.yaml`
|
||||
```yaml
|
||||
|
||||
---
|
||||
- name: parser meta data
|
||||
parser_metadata:
|
||||
version: 1.0
|
||||
command: show interface
|
||||
network_os: ios
|
||||
|
||||
- name: match sections
|
||||
pattern_match:
|
||||
regex: "^(\\S+) is up,"
|
||||
match_all: yes
|
||||
match_greedy: yes
|
||||
register: section
|
||||
|
||||
- name: match interface values
|
||||
pattern_group:
|
||||
- name: match name
|
||||
pattern_match:
|
||||
regex: "^(\\S+)"
|
||||
content: "{{ item }}"
|
||||
register: name
|
||||
|
||||
- name: match hardware
|
||||
pattern_match:
|
||||
regex: "Hardware is (\\S+),"
|
||||
content: "{{ item }}"
|
||||
register: type
|
||||
|
||||
- name: match mtu
|
||||
pattern_match:
|
||||
regex: "MTU (\\d+)"
|
||||
content: "{{ item }}"
|
||||
register: mtu
|
||||
|
||||
- name: match description
|
||||
pattern_match:
|
||||
regex: "Description: (.*)"
|
||||
content: "{{ item }}"
|
||||
register: description
|
||||
loop: "{{ section }}"
|
||||
register: interfaces
|
||||
|
||||
- name: generate json data structure
|
||||
json_template:
|
||||
template:
|
||||
- key: "{{ item.name.matches.0 }}"
|
||||
object:
|
||||
- key: config
|
||||
object:
|
||||
- key: name
|
||||
value: "{{ item.name.matches.0 }}"
|
||||
- key: type
|
||||
value: "{{ item.type.matches.0 }}"
|
||||
- key: mtu
|
||||
value: "{{ item.mtu.matches.0 }}"
|
||||
- key: description
|
||||
value: "{{ item.description.matches.0 }}"
|
||||
loop: "{{ interfaces }}"
|
||||
export: yes
|
||||
register: interface_facts
|
||||
|
||||
```
|
||||
|
||||
`parser_templates/ios/show_version.yaml`
|
||||
|
||||
```yaml
|
||||
|
||||
---
|
||||
- name: parser meta data
|
||||
parser_metadata:
|
||||
version: 1.0
|
||||
command: show version
|
||||
network_os: ios
|
||||
|
||||
- name: match version
|
||||
pattern_match:
|
||||
regex: "Version (\\S+),"
|
||||
register: version
|
||||
|
||||
- name: match model
|
||||
pattern_match:
|
||||
regex: "^Cisco (.+) \\(revision"
|
||||
register: model
|
||||
|
||||
- name: match image
|
||||
pattern_match:
|
||||
regex: "^System image file is (\\S+)"
|
||||
register: image
|
||||
|
||||
- name: match uptime
|
||||
pattern_match:
|
||||
regex: "uptime is (.+)"
|
||||
register: uptime
|
||||
|
||||
- name: match total memory
|
||||
pattern_match:
|
||||
regex: "with (\\S+)/(\\w*) bytes of memory"
|
||||
register: total_mem
|
||||
|
||||
- name: match free memory
|
||||
pattern_match:
|
||||
regex: "with \\w*/(\\S+) bytes of memory"
|
||||
register: free_mem
|
||||
|
||||
- name: export system facts to playbook
|
||||
set_vars:
|
||||
model: "{{ model.matches.0 }}"
|
||||
image_file: "{{ image.matches.0 }}"
|
||||
uptime: "{{ uptime.matches.0 }}"
|
||||
version: "{{ version.matches.0 }}"
|
||||
memory:
|
||||
total: "{{ total_mem.matches.0 }}"
|
||||
free: "{{ free_mem.matches.0 }}"
|
||||
export: yes
|
||||
register: system_facts
|
||||
|
||||
```
|
||||
|
||||
## Sample Playbooks
|
||||
|
||||
To extract the data defined in your parser template, create a playbook that includes the Network Engine role and references the `content` and `file` (or `dir`) parameters of the `command_parser` module.
|
||||
|
||||
Each example playbook below runs a show command, imports the Network Engine role, extracts data from the text output of the command by matching it against the rules defined
|
||||
in your parser template, and stores the results in a variable. To view the content of that final variable, make sure `export: yes` is set in your parser template, and run your playbook in `verbose` mode: `ansible-playbook -vvv`.
|
||||
|
||||
Make sure the `hosts` definition in the playbook matches a host group in your inventory - in these examples, the playbook expects a group called `ios`.
|
||||
|
||||
The first example parses the output of the `show interfaces` command on IOS and creates facts from that output:
|
||||
|
||||
```yaml
|
||||
|
||||
---
|
||||
|
||||
# ~/my-playbooks/gather-interface-info.yml
|
||||
|
||||
- hosts: ios
|
||||
connection: network_cli
|
||||
|
||||
tasks:
|
||||
- name: Collect interface information from device
|
||||
ios_command:
|
||||
commands:
|
||||
- show interfaces
|
||||
register: ios_interface_output
|
||||
|
||||
- name: import the network-engine role
|
||||
import_role:
|
||||
name: ansible-network.network-engine
|
||||
|
||||
- name: Generate interface facts as JSON
|
||||
command_parser:
|
||||
file: "parser_templates/ios/show_interfaces.yaml"
|
||||
content: "{{ ios_interface_output.stdout.0 }}"
|
||||
|
||||
```
|
||||
|
||||
The second example parses the output of the `show version` command on IOS and creates facts from that output:
|
||||
|
||||
```yaml
|
||||
|
||||
---
|
||||
|
||||
# ~/my-playbooks/gather-version-info.yml
|
||||
|
||||
- hosts: ios
|
||||
connection: network_cli
|
||||
|
||||
tasks:
|
||||
- name: Collect version information from device
|
||||
ios_command:
|
||||
commands:
|
||||
- show version
|
||||
register: ios_version_output
|
||||
|
||||
- name: import the network-engine role
|
||||
import_role:
|
||||
name: ansible-network.network-engine
|
||||
|
||||
- name: Generate version facts as JSON
|
||||
command_parser:
|
||||
file: "parser_templates/ios/show_version.yaml"
|
||||
content: "{{ ios_version_output.stdout.0 }}"
|
||||
|
||||
```
|
||||
@@ -0,0 +1,82 @@
|
||||
# textfsm_parser
|
||||
|
||||
The [textfsm_parser](https://github.com/ansible-network/network-engine/blob/devel/library/textfsm_parser.py)
|
||||
module is based on [Google TextFSM](https://github.com/google/textfsm/wiki/TextFSM) definitions.
|
||||
This module iterates over matching rules defined in TextFSM format, extracts data from structured ASCII text based on those rules,
|
||||
and returns Ansible facts in a JSON data structure that can be added to inventory host facts and/or consumed by Ansible tasks and templates.
|
||||
|
||||
The `textfsm_parser` module requires two inputs:
|
||||
- the output of commands run on the network device, passed to the `content` parameter
|
||||
- the parser template that defines the rules for parsing the output, passed to either the `file` or the `src` parameter
|
||||
|
||||
## content
|
||||
|
||||
The `content` parameter for `textfsm_parser` must point to the ASCII text output of commands run on network devices. The text output can be in a variable or in a file.
|
||||
|
||||
## file
|
||||
|
||||
The `file` parameter for `textfsm_parser` must point to a parser template that contains a TextFSM rule for each data field you want to extract from your network devices.
|
||||
|
||||
Parser templates for the `textfsm_parser` module in the Network Engine role use TextFSM notation.
|
||||
|
||||
### name
|
||||
|
||||
The `name` parameter for `textfsm_parser` names the variable in which Ansible will store the JSON data structure. If name is not set, the JSON facts from parsing will not be displayed/exported.
|
||||
|
||||
### src
|
||||
|
||||
The `src` parameter for `textfsm_parser` loads your parser template from an external source, usually a URL.
|
||||
|
||||
## Sample Parser Templates
|
||||
|
||||
Here is a sample TextFSM parser template:
|
||||
|
||||
`parser_templates/ios/show_interfaces`
|
||||
```
|
||||
|
||||
Value Required name (\S+)
|
||||
Value type ([\w ]+)
|
||||
Value description (.*)
|
||||
Value mtu (\d+)
|
||||
|
||||
Start
|
||||
^${name} is up
|
||||
^\s+Hardware is ${type} -> Continue
|
||||
^\s+Description: ${description}
|
||||
^\s+MTU ${mtu} bytes, -> Record
|
||||
|
||||
```
|
||||
|
||||
## Sample Playbooks
|
||||
|
||||
To extract the data defined in your parser template, create a playbook that includes the Network Engine role and references the `content` and `file` parameters of the `command_parser` module.
|
||||
|
||||
The example playbook below runs a show command, imports the Network Engine role, extracts data from the text output of the command by matching it against the rules defined
|
||||
in your parser template, and stores the results in a variable. To view the content of that final variable, add it to the `name` parameter as shown in the example and run the playbook in `verbose` mode: `ansible-playbook -v`.
|
||||
|
||||
Make sure the `hosts` definition in the playbook matches a host group in your inventory - in these examples, the playbook expects a group called `ios`.
|
||||
|
||||
The example below parses the output of the `show interfaces` command on IOS and creates facts from that output:
|
||||
|
||||
```yaml
|
||||
|
||||
---
|
||||
|
||||
# ~/my-playbooks/textfsm-gather-interface-info.yml
|
||||
|
||||
- hosts: ios
|
||||
connection: network_cli
|
||||
|
||||
tasks:
|
||||
- name: Collect interface information from device
|
||||
ios_command:
|
||||
commands: "show interfaces"
|
||||
register: ios_interface_output
|
||||
|
||||
- name: Generate interface facts as JSON
|
||||
textfsm_parser:
|
||||
file: "parser_templates/ios/show_interfaces"
|
||||
content: "{{ ios_interface_output.stdout.0 }}"
|
||||
name: interface_facts
|
||||
|
||||
```
|
||||
@@ -0,0 +1,122 @@
|
||||
# Copyright (c) 2018 Ansible Project
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import re
|
||||
|
||||
from ansible.module_utils.six import string_types
|
||||
from ansible.errors import AnsibleFilterError
|
||||
|
||||
|
||||
def interface_split(interface, key=None):
|
||||
match = re.match(r'([A-Za-z\-]*)(.+)', interface)
|
||||
if not match:
|
||||
raise AnsibleFilterError('unable to parse interface %s' % interface)
|
||||
obj = {'name': match.group(1), 'index': match.group(2)}
|
||||
if key:
|
||||
return obj[key]
|
||||
else:
|
||||
return obj
|
||||
|
||||
|
||||
def interface_range(interface):
|
||||
if not isinstance(interface, string_types):
|
||||
raise AnsibleFilterError('value must be of type string, got %s' % type(interface))
|
||||
|
||||
parts = interface.rpartition('/')
|
||||
if parts[1]:
|
||||
prefix = '%s/' % parts[0]
|
||||
index = parts[2]
|
||||
else:
|
||||
match = re.match(r'([A-Za-z]*)(.+)', interface)
|
||||
if not match:
|
||||
raise AnsibleFilterError('unable to parse interface %s' % interface)
|
||||
prefix = match.group(1)
|
||||
index = match.group(2)
|
||||
|
||||
indicies = list()
|
||||
|
||||
for item in index.split(','):
|
||||
tokens = item.split('-')
|
||||
|
||||
if len(tokens) == 1:
|
||||
indicies.append(tokens[0])
|
||||
|
||||
elif len(tokens) == 2:
|
||||
start, end = tokens
|
||||
for i in range(int(start), int(end) + 1):
|
||||
indicies.append(i)
|
||||
i += 1
|
||||
|
||||
return ['%s%s' % (prefix, index) for index in indicies]
|
||||
|
||||
|
||||
def _gen_ranges(vlan):
|
||||
s = e = None
|
||||
for i in sorted(vlan):
|
||||
if s is None:
|
||||
s = e = i
|
||||
elif i == e or i == e + 1:
|
||||
e = i
|
||||
else:
|
||||
yield (s, e)
|
||||
s = e = i
|
||||
if s is not None:
|
||||
yield (s, e)
|
||||
|
||||
|
||||
def vlan_compress(vlan):
|
||||
if not isinstance(vlan, list):
|
||||
raise AnsibleFilterError('value must be of type list, got %s' % type(vlan))
|
||||
|
||||
return (','.join(['%d' % s if s == e else '%d-%d' % (s, e) for (s, e) in _gen_ranges(vlan)]))
|
||||
|
||||
|
||||
def vlan_expand(vlan):
|
||||
if not isinstance(vlan, string_types):
|
||||
raise AnsibleFilterError('value must be of type string, got %s' % type(vlan))
|
||||
|
||||
match = re.match(r'([A-Za-z]*)(.+)', vlan)
|
||||
if not match:
|
||||
raise AnsibleFilterError('unable to parse vlan %s' % vlan)
|
||||
|
||||
index = match.group(2)
|
||||
indices = list()
|
||||
|
||||
for item in index.split(','):
|
||||
tokens = item.split('-')
|
||||
|
||||
if len(tokens) == 1:
|
||||
indices.append(int(tokens[0]))
|
||||
|
||||
elif len(tokens) == 2:
|
||||
start, end = tokens
|
||||
for i in range(int(start), int(end) + 1):
|
||||
indices.append(i)
|
||||
i += 1
|
||||
|
||||
return ['%d' % int(index) for index in indices]
|
||||
|
||||
|
||||
def to_lines(value):
|
||||
if isinstance(value, (list, set, tuple)):
|
||||
return value
|
||||
elif isinstance(value, string_types):
|
||||
return value.split('\n')
|
||||
raise AnsibleFilterError('cannot convert value to lines')
|
||||
|
||||
|
||||
class FilterModule(object):
|
||||
''' Network interface filter '''
|
||||
|
||||
def filters(self):
|
||||
return {
|
||||
'interface_split': interface_split,
|
||||
'interface_range': interface_range,
|
||||
'vlan_compress': vlan_compress,
|
||||
'vlan_expand': vlan_expand,
|
||||
'to_lines': to_lines
|
||||
}
|
||||
15
roles/ansible-network.network-engine/includes/init.yaml
Normal file
15
roles/ansible-network.network-engine/includes/init.yaml
Normal file
@@ -0,0 +1,15 @@
|
||||
---
|
||||
- name: read ansible_min_version from meta data
|
||||
include_vars:
|
||||
file: ../meta/main.yml
|
||||
name: ansible_galaxy_meta
|
||||
|
||||
- name: validate minimum Ansible version
|
||||
fail:
|
||||
msg: "This role requires Ansible {{ ansible_galaxy_meta.galaxy_info.min_ansible_version }} or higher. You are currently running Ansible {{ ansible_version.full }}."
|
||||
when: 'ansible_version.full is version_compare(ansible_galaxy_meta.galaxy_info.min_ansible_version, "<")'
|
||||
|
||||
- name: validate connection is network_cli
|
||||
fail:
|
||||
msg: "expected connection network_cli, got {{ ansible_connection }}"
|
||||
when: ansible_connection != 'network_cli'
|
||||
@@ -0,0 +1,54 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright 2018 Red Hat
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
||||
'status': ['preview'],
|
||||
'supported_by': 'network'}
|
||||
|
||||
|
||||
DOCUMENTATION = '''
|
||||
---
|
||||
module: command_parser
|
||||
short_description: Parses text into JSON facts based on rules
|
||||
description:
|
||||
- Provides a rules base text parser that is closely modeled after the Ansible
|
||||
playbook language. This parser will iterate of the rules and parse the
|
||||
output of structured ASCII text into a JSON data structure that can be
|
||||
added to the inventory host facts.
|
||||
version_added: "2.5"
|
||||
options:
|
||||
dir:
|
||||
description:
|
||||
- The path to the directory that contains the parsers. The module will
|
||||
load all parsers found in this directory and pass the content through
|
||||
the them. This argument is mutually exclusive with C(file).
|
||||
default: null
|
||||
file:
|
||||
description:
|
||||
- The path to the parser to load from disk on the Ansible
|
||||
controller. This can be either the absolute path or relative path.
|
||||
This argument is mutually exclusive with C(dir).
|
||||
Default path is {{ playbook_dir }}/parser_templates/{{ ansible_network_os }}
|
||||
or {{ playbook_dir }}/parser_templates or {{ playbook_dir }}
|
||||
default: "{{ playbook_dir }}/parser_templates/{{ ansible_network_os }}"
|
||||
content:
|
||||
description:
|
||||
- The text content to pass to the parser engine. This argument provides
|
||||
the input to the text parser for generating the JSON data.
|
||||
required: true
|
||||
author:
|
||||
- Peter Sprygada (@privateip)
|
||||
'''
|
||||
|
||||
EXAMPLES = '''
|
||||
- command_parser:
|
||||
file: files/parser_templates/show_interface.yaml
|
||||
content: "{{ lookup('file', 'output/show_interfaces.txt') }}"
|
||||
'''
|
||||
58
roles/ansible-network.network-engine/library/net_facts.py
Normal file
58
roles/ansible-network.network-engine/library/net_facts.py
Normal file
@@ -0,0 +1,58 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# (c) 2018, Red Hat, Inc.
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
||||
'status': ['preview'],
|
||||
'supported_by': 'network'}
|
||||
|
||||
|
||||
DOCUMENTATION = """
|
||||
---
|
||||
module: net_facts
|
||||
version_added: "2.7"
|
||||
short_description: Collect device capabilities from Network devices
|
||||
description:
|
||||
- Collect basic fact capabilities from Network devices and return
|
||||
the capabilities as Ansible facts.
|
||||
|
||||
author:
|
||||
- Trishna Guha (@trishnaguha)
|
||||
options: {}
|
||||
"""
|
||||
|
||||
EXAMPLES = """
|
||||
- facts:
|
||||
"""
|
||||
|
||||
RETURN = """
|
||||
"""
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.connection import Connection
|
||||
|
||||
|
||||
def main():
|
||||
""" main entry point for Ansible module
|
||||
"""
|
||||
argument_spec = {}
|
||||
|
||||
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)
|
||||
|
||||
connection = Connection(module._socket_path)
|
||||
facts = connection.get_capabilities()
|
||||
facts = module.from_json(facts)
|
||||
result = {
|
||||
'changed': False,
|
||||
'ansible_facts': {'ansible_network_facts': {'capabilities': facts['device_info']}}
|
||||
}
|
||||
module.exit_json(**result)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -0,0 +1,70 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright 2018 Red Hat
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
||||
'status': ['preview'],
|
||||
'supported_by': 'network'}
|
||||
|
||||
DOCUMENTATION = '''
|
||||
---
|
||||
module: textfsm_parser
|
||||
author: Peter Sprygada (@privateip)
|
||||
short_description: Parses text into JSON facts using TextFSM
|
||||
description:
|
||||
- Provides textfsm rule based templates to parse data from text.
|
||||
The template acting as parser will iterate of the rules and parse
|
||||
the output of structured ASCII text into a JSON data structure
|
||||
that can be added to the inventory host facts.
|
||||
requirements:
|
||||
- textfsm
|
||||
version_added: "2.5"
|
||||
options:
|
||||
file:
|
||||
description:
|
||||
- Path to the TextFSM parser to use to parse the output from a command.
|
||||
The C(file) argument accepts either a relative or absolute path
|
||||
to the TextFSM file.
|
||||
default: null
|
||||
src:
|
||||
description:
|
||||
- The C(src) argument can be used to load the content of a TextFSM
|
||||
parser file. This argument allow the TextFSM parser to be loaded
|
||||
from an external source. See EXAMPLES.
|
||||
default: null
|
||||
content:
|
||||
description:
|
||||
- The output of the command to parse using the rules in the TextFSM
|
||||
file. The content should be a text string.
|
||||
required: true
|
||||
name:
|
||||
description:
|
||||
- The C(name) argument is used to define the top-level fact name to
|
||||
hold the output of the parser. If this argument is not provided,
|
||||
the output from parsing will not be exported.
|
||||
default: null
|
||||
'''
|
||||
|
||||
EXAMPLES = '''
|
||||
- name: parse the content of a command
|
||||
textfsm_parser:
|
||||
file: files/parser_templates/show_interface.yaml
|
||||
content: "{{ lookup('file', 'output/show_interfaces.txt') }}"
|
||||
|
||||
- name: store returned facts into a key call output
|
||||
textfsm_parser:
|
||||
file: files/parser_templates/show_interface.yaml
|
||||
content: "{{ lookup('file', 'output/show_interfaces.txt') }}"
|
||||
name: output
|
||||
|
||||
- name: read the parser from an url
|
||||
textfsm_parser:
|
||||
src: "{{ lookup('url', 'http://server/path/to/parser') }}"
|
||||
content: "{{ lookup('file', 'output/show_interfaces.txt') }}"
|
||||
'''
|
||||
@@ -0,0 +1,48 @@
|
||||
# (c) 2012, Michael DeHaan <michael.dehaan@gmail.com>
|
||||
# (c) 2012-17 Ansible Project
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
DOCUMENTATION = """
|
||||
lookup: config_template
|
||||
author: Peter Sprygada (privateip)
|
||||
version_added: "2.7"
|
||||
short_description: retrieve contents of file after templating with Jinja2
|
||||
description:
|
||||
- This lookup plugin implements the standard template plugin with a slight
|
||||
twist in that it supports using default(omit) to remove an entire line
|
||||
options:
|
||||
_terms:
|
||||
description: list of files to template
|
||||
"""
|
||||
|
||||
EXAMPLES = """
|
||||
- name: show templating results
|
||||
debug: msg="{{ lookup('config_template', './some_template.j2') }}
|
||||
"""
|
||||
|
||||
RETURN = """
|
||||
_raw:
|
||||
description: file(s) content after templating
|
||||
"""
|
||||
from ansible.plugins.lookup.template import LookupModule as LookupBase
|
||||
|
||||
|
||||
class LookupModule(LookupBase):
|
||||
|
||||
def run(self, terms, variables, **kwargs):
|
||||
|
||||
ret = super(LookupModule, self).run(terms, variables, **kwargs)
|
||||
|
||||
omit = variables['omit']
|
||||
filtered = list()
|
||||
|
||||
for line in ret[0].split('\n'):
|
||||
if all((line, omit not in line, not line.startswith('!'))):
|
||||
filtered.append(line)
|
||||
|
||||
return [filtered]
|
||||
@@ -0,0 +1,68 @@
|
||||
# (c) 2018 Red Hat, Inc.
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
DOCUMENTATION = """
|
||||
lookup: json_template
|
||||
author: Ansible Network
|
||||
version_added: "2.5"
|
||||
short_description: retrieve and template device configuration
|
||||
description:
|
||||
- This plugin lookups the content(key-value pair) of a JSON file
|
||||
and returns network configuration in JSON format.
|
||||
options:
|
||||
_terms:
|
||||
description: File for lookup
|
||||
"""
|
||||
|
||||
EXAMPLES = """
|
||||
- name: show interface lookup result
|
||||
debug: msg="{{ lookup('json_template', './show_interface.json') }}
|
||||
"""
|
||||
|
||||
RETURN = """
|
||||
_raw:
|
||||
description: JSON file content
|
||||
"""
|
||||
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
|
||||
from ansible.errors import AnsibleError, AnsibleParserError
|
||||
from ansible.plugins.lookup import LookupBase, display
|
||||
from ansible.module_utils._text import to_bytes
|
||||
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), os.path.pardir, 'lib'))
|
||||
from network_engine.plugins import template_loader
|
||||
|
||||
|
||||
class LookupModule(LookupBase):
|
||||
|
||||
def run(self, terms, variables, **kwargs):
|
||||
|
||||
ret = list()
|
||||
|
||||
self.ds = variables.copy()
|
||||
self.template = template_loader.get('json_template', self._templar)
|
||||
|
||||
display.debug("File lookup term: %s" % terms[0])
|
||||
|
||||
lookupfile = self.find_file_in_search_path(variables, 'files', terms[0])
|
||||
display.vvvv("File lookup using %s as file" % lookupfile)
|
||||
try:
|
||||
if lookupfile:
|
||||
with open(to_bytes(lookupfile, errors='surrogate_or_strict'), 'rb') as f:
|
||||
json_data = list()
|
||||
json_data.append(json.load(f))
|
||||
ret.append(self.template.run(json_data, self.ds))
|
||||
else:
|
||||
raise AnsibleParserError()
|
||||
except AnsibleParserError:
|
||||
raise AnsibleError("could not locate file in lookup: %s" % terms[0])
|
||||
|
||||
return ret
|
||||
@@ -0,0 +1,119 @@
|
||||
# (c) 2018 Red Hat, Inc.
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
DOCUMENTATION = """
|
||||
lookup: netcfg_diff
|
||||
author: Ansible Network
|
||||
version_added: "2.5"
|
||||
short_description: Generates a text configuration difference between two configuration
|
||||
mainly used with network devices.
|
||||
description:
|
||||
- This plugin lookups will generate a difference between two text configuration that
|
||||
is supported by Network OS. This difference can be used to identify the
|
||||
exact change that is required to be pushed to remote host.
|
||||
options:
|
||||
_terms:
|
||||
description:
|
||||
- Specifies the wanted text configuration. Theis is usually
|
||||
the text configuration that is expected to be present on remote host.
|
||||
required: True
|
||||
have:
|
||||
description:
|
||||
- Specifies the text configuration. The C(have) is usually
|
||||
the text configuration that is active on remote host.
|
||||
required: True
|
||||
match:
|
||||
description:
|
||||
- Instructs the module on the way to perform the matching of
|
||||
the set of text commands between C(want) and C(have).
|
||||
If match is set to I(line), commands are matched line by line. If
|
||||
match is set to I(strict), command lines are matched with respect
|
||||
to position. If match is set to I(exact), command lines
|
||||
must be an equal match.
|
||||
default: line
|
||||
choices: ['line', 'strict', 'exact']
|
||||
replace:
|
||||
description:
|
||||
- Instructs the module on the way to perform the configuration
|
||||
diff. If the replace argument is set to I(line) then
|
||||
the modified lines are pushed in the generated diff. If the replace argument
|
||||
is set to I(block) then the entire command block is pushed in the generated
|
||||
diff if any line is not correct.
|
||||
default: line
|
||||
choices: ['line', 'block']
|
||||
indent:
|
||||
description:
|
||||
- Specifies the indentation used for the block in text configuration. The value of C(indent)
|
||||
is specific on network platform to which the text configuration in C(want) and C(have)
|
||||
conforms to.
|
||||
default: 1
|
||||
type: int
|
||||
ignore_lines:
|
||||
description:
|
||||
- This specifies the lines to be ignored while generating diff. The value of C(ignore_lines) can
|
||||
also be a python regex.
|
||||
|
||||
"""
|
||||
|
||||
EXAMPLES = """
|
||||
- name: generate diff between two text configuration
|
||||
debug: msg="{{ lookup('netcfg_diff', want, have=have) }}
|
||||
"""
|
||||
|
||||
RETURN = """
|
||||
_raw:
|
||||
description: The text difference between values of want and have with want as base reference
|
||||
"""
|
||||
|
||||
from ansible.plugins.lookup import LookupBase
|
||||
from ansible.module_utils.network.common.config import NetworkConfig, dumps
|
||||
from ansible.errors import AnsibleError
|
||||
|
||||
|
||||
MATCH_CHOICES = ('line', 'strict', 'exact')
|
||||
REPLACE_CHOICES = ('line', 'block')
|
||||
|
||||
|
||||
class LookupModule(LookupBase):
|
||||
|
||||
def run(self, terms, variables, **kwargs):
|
||||
|
||||
ret = []
|
||||
|
||||
try:
|
||||
want = terms[0]
|
||||
except IndexError:
|
||||
raise AnsibleError("value of 'want' must be specified")
|
||||
|
||||
try:
|
||||
have = kwargs['have']
|
||||
except KeyError:
|
||||
raise AnsibleError("value of 'have' must be specified")
|
||||
|
||||
match = kwargs.get('match', 'line')
|
||||
if match not in MATCH_CHOICES:
|
||||
choices_str = ", ".join(MATCH_CHOICES)
|
||||
raise AnsibleError("value of match must be one of: %s, got: %s" % (choices_str, match))
|
||||
|
||||
replace = kwargs.get('replace', 'line')
|
||||
if replace not in REPLACE_CHOICES:
|
||||
choices_str = ", ".join(REPLACE_CHOICES)
|
||||
raise AnsibleError("value of replace must be one of: %s, got: %s" % (choices_str, replace))
|
||||
|
||||
indent = int(kwargs.get('indent', 1))
|
||||
ignore_lines = kwargs.get('ignore_lines')
|
||||
|
||||
running_obj = NetworkConfig(indent=indent, contents=have, ignore_lines=ignore_lines)
|
||||
candidate_obj = NetworkConfig(indent=indent, contents=want, ignore_lines=ignore_lines)
|
||||
|
||||
configobjs = candidate_obj.difference(running_obj, match=match, replace=replace)
|
||||
|
||||
diff = dumps(configobjs, output='commands')
|
||||
ret.append(diff)
|
||||
|
||||
return ret
|
||||
@@ -0,0 +1,257 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# (c) 2018, Ansible by Red Hat, inc
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
#
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
DOCUMENTATION = """
|
||||
lookup: network_template
|
||||
author: Ansible Network
|
||||
version_added: "2.5"
|
||||
short_description: template device configuration
|
||||
description:
|
||||
- This plugin will lookup the file and template it into a network
|
||||
configuration.
|
||||
deprecated:
|
||||
removed_in: "2.7.7"
|
||||
options:
|
||||
_terms:
|
||||
description: list of files to template
|
||||
"""
|
||||
|
||||
EXAMPLES = """
|
||||
- name: show config template results
|
||||
debug: msg="{{ lookup('network_template', './config_template.j2') }}
|
||||
"""
|
||||
|
||||
RETURN = """
|
||||
_raw:
|
||||
description: file(s) content after templating
|
||||
"""
|
||||
|
||||
|
||||
import collections
|
||||
|
||||
from ansible.plugins.lookup import LookupBase, display
|
||||
from ansible.module_utils.common._collections_compat import Mapping
|
||||
from ansible.module_utils.network.common.utils import to_list
|
||||
from ansible.module_utils.six import iteritems, string_types
|
||||
from ansible.module_utils._text import to_text, to_bytes
|
||||
from ansible.errors import AnsibleError, AnsibleUndefinedVariable
|
||||
|
||||
|
||||
class LookupModule(LookupBase):
|
||||
|
||||
def run(self, terms, variables, **kwargs):
|
||||
self.ds = variables.copy()
|
||||
|
||||
config_lines = list()
|
||||
|
||||
for term in to_list(terms[0]):
|
||||
display.debug("File lookup term: %s" % term)
|
||||
|
||||
lookupfile = self.find_file_in_search_path(variables, 'templates', term)
|
||||
display.vvvv("File lookup using %s as file" % lookupfile)
|
||||
|
||||
if lookupfile:
|
||||
with open(to_bytes(lookupfile, errors='surrogate_or_strict'), 'rb'):
|
||||
tasks = self._loader.load_from_file(lookupfile)
|
||||
|
||||
for task in tasks:
|
||||
task.pop('name', None)
|
||||
register = task.pop('register', None)
|
||||
|
||||
when = task.pop('when', None)
|
||||
if when is not None:
|
||||
if not self._check_conditional(when, self.ds):
|
||||
display.vvv('skipping task due to conditional check failure')
|
||||
continue
|
||||
|
||||
loop = task.pop('loop', None)
|
||||
|
||||
if loop:
|
||||
loop = self.template(loop, self.ds)
|
||||
loop_result = list()
|
||||
|
||||
if isinstance(loop, Mapping):
|
||||
for loop_key, loop_value in iteritems(loop):
|
||||
self.ds['item'] = {'key': loop_key, 'value': loop_value}
|
||||
res = self._process_directive(task)
|
||||
if res:
|
||||
loop_result.extend(to_list(res))
|
||||
|
||||
elif isinstance(loop, collections.Iterable) and not isinstance(loop, string_types):
|
||||
for loop_item in loop:
|
||||
self.ds['item'] = loop_item
|
||||
res = self._process_directive(task)
|
||||
if res:
|
||||
loop_result.extend(to_list(res))
|
||||
|
||||
config_lines.extend(loop_result)
|
||||
|
||||
if register:
|
||||
self.ds[register] = loop_result
|
||||
|
||||
else:
|
||||
res = self._process_directive(task)
|
||||
if res:
|
||||
config_lines.extend(to_list(res))
|
||||
if register:
|
||||
self.ds[register] = res
|
||||
|
||||
else:
|
||||
raise AnsibleError("the template file %s could not be found for the lookup" % term)
|
||||
|
||||
return [to_text('\n'.join(config_lines)).strip()]
|
||||
|
||||
def do_context(self, block):
|
||||
|
||||
results = list()
|
||||
|
||||
for entry in block:
|
||||
task = entry.copy()
|
||||
task.pop('name', None)
|
||||
task.pop('register', None)
|
||||
|
||||
when = task.pop('when', None)
|
||||
if when is not None:
|
||||
if not self._check_conditional(when, self.ds):
|
||||
display.vvv('skipping context due to conditional check failure')
|
||||
continue
|
||||
|
||||
loop = task.pop('loop', None)
|
||||
if loop:
|
||||
loop = self.template(loop, self.ds)
|
||||
|
||||
if 'context' in task:
|
||||
res = self.do_context(task['context'])
|
||||
if res:
|
||||
results.extend(res)
|
||||
|
||||
elif isinstance(loop, Mapping):
|
||||
loop_result = list()
|
||||
for loop_key, loop_value in iteritems(loop):
|
||||
self.ds['item'] = {'key': loop_key, 'value': loop_value}
|
||||
loop_result.extend(to_list(self._process_directive(task)))
|
||||
results.extend(loop_result)
|
||||
|
||||
elif isinstance(loop, collections.Iterable) and not isinstance(loop, string_types):
|
||||
loop_result = list()
|
||||
for loop_item in loop:
|
||||
self.ds['item'] = loop_item
|
||||
loop_result.extend(to_list(self._process_directive(task)))
|
||||
results.extend(loop_result)
|
||||
|
||||
else:
|
||||
res = self._process_directive(task)
|
||||
if res:
|
||||
results.extend(to_list(res))
|
||||
|
||||
return results
|
||||
|
||||
def _process_directive(self, task):
|
||||
for directive, args in iteritems(task):
|
||||
if directive == 'context':
|
||||
meth = getattr(self, 'do_%s' % directive)
|
||||
if meth:
|
||||
return meth(args)
|
||||
else:
|
||||
meth = getattr(self, 'do_%s' % directive)
|
||||
if meth:
|
||||
return meth(**args)
|
||||
|
||||
def do_lines_template(self, template, join=False, when=None, required=False):
|
||||
templated_lines = list()
|
||||
_processed = list()
|
||||
|
||||
if when is not None:
|
||||
if not self._check_conditional(when, self.ds):
|
||||
display.vvv("skipping due to conditional failure")
|
||||
return templated_lines
|
||||
|
||||
for line in to_list(template):
|
||||
res = self.template(line, self.ds)
|
||||
if res:
|
||||
_processed.append(res)
|
||||
elif not res and join:
|
||||
break
|
||||
|
||||
if required and not _processed:
|
||||
raise AnsibleError('unabled to templated required line')
|
||||
elif _processed and join:
|
||||
templated_lines.append(' '.join(_processed))
|
||||
elif _processed:
|
||||
templated_lines.extend(_processed)
|
||||
|
||||
return templated_lines
|
||||
|
||||
def _process_include(self, item, variables):
|
||||
name = item.get('name')
|
||||
include = item['include']
|
||||
|
||||
src = self.template(include, variables)
|
||||
source = self._find_needle('templates', src)
|
||||
|
||||
when = item.get('when')
|
||||
|
||||
if when:
|
||||
conditional = "{%% if %s %%}True{%% else %%}False{%% endif %%}"
|
||||
if not self.template(conditional % when, variables, fail_on_undefined=False):
|
||||
display.vvvvv("include '%s' skipped due to conditional check failure" % name)
|
||||
return []
|
||||
|
||||
display.display('including file %s' % source)
|
||||
include_data = self._loader.load_from_file(source)
|
||||
|
||||
template_data = item.copy()
|
||||
|
||||
# replace include directive with block directive and contents of
|
||||
# included file. this will preserve other values such as loop,
|
||||
# loop_control, etc
|
||||
template_data.pop('include')
|
||||
template_data['block'] = include_data
|
||||
|
||||
return self.build([template_data], variables)
|
||||
|
||||
def template(self, data, variables, convert_bare=False):
|
||||
|
||||
if isinstance(data, Mapping):
|
||||
templated_data = {}
|
||||
for key, value in iteritems(data):
|
||||
templated_key = self.template(key, variables, convert_bare=convert_bare)
|
||||
templated_data[templated_key] = self.template(value, variables, convert_bare=convert_bare)
|
||||
return templated_data
|
||||
|
||||
elif isinstance(data, collections.Iterable) and not isinstance(data, string_types):
|
||||
return [self.template(i, variables, convert_bare=convert_bare) for i in data]
|
||||
|
||||
else:
|
||||
data = data or {}
|
||||
tmp_avail_vars = self._templar._available_variables
|
||||
self._templar.set_available_variables(variables)
|
||||
try:
|
||||
resp = self._templar.template(data, convert_bare=convert_bare)
|
||||
resp = self._coerce_to_native(resp)
|
||||
except AnsibleUndefinedVariable:
|
||||
resp = None
|
||||
finally:
|
||||
self._templar.set_available_variables(tmp_avail_vars)
|
||||
return resp
|
||||
|
||||
def _coerce_to_native(self, value):
|
||||
if not isinstance(value, bool):
|
||||
try:
|
||||
value = int(value)
|
||||
except Exception:
|
||||
if value is None or len(value) == 0:
|
||||
return None
|
||||
return value
|
||||
|
||||
def _check_conditional(self, when, variables):
|
||||
conditional = "{%% if %s %%}True{%% else %%}False{%% endif %%}"
|
||||
return self.template(conditional % when, variables)
|
||||
@@ -0,0 +1 @@
|
||||
{install_date: 'Thu May 2 18:45:34 2019', version: v2.7.5}
|
||||
37
roles/ansible-network.network-engine/meta/main.yml
Normal file
37
roles/ansible-network.network-engine/meta/main.yml
Normal file
@@ -0,0 +1,37 @@
|
||||
---
|
||||
galaxy_info:
|
||||
author: ansible-network
|
||||
description: This role provides the foundation for building network roles by providing modules and plugins that are common to all Ansible Network roles.
|
||||
company: Red Hat
|
||||
|
||||
issue_tracker_url: https://github.com/ansible-network/network-engine/issues
|
||||
|
||||
license: GPLv3
|
||||
|
||||
min_ansible_version: 2.7
|
||||
|
||||
# If this a Container Enabled role, provide the minimum Ansible Container version.
|
||||
# min_ansible_container_version:
|
||||
|
||||
# Optionally specify the branch Galaxy will use when accessing the GitHub
|
||||
# repo for this role. During role install, if no tags are available,
|
||||
# Galaxy will use this branch. During import Galaxy will access files on
|
||||
# this branch. If Travis integration is configured, only notifications for this
|
||||
# branch will be accepted. Otherwise, in all cases, the repo's default branch
|
||||
# (usually master) will be used.
|
||||
# github_branch:
|
||||
|
||||
platforms:
|
||||
- name: network
|
||||
versions:
|
||||
- all
|
||||
|
||||
galaxy_tags:
|
||||
- ansible
|
||||
- network
|
||||
- networking
|
||||
- engine
|
||||
- core
|
||||
- cli
|
||||
|
||||
dependencies: []
|
||||
2
roles/ansible-network.network-engine/requirements.txt
Normal file
2
roles/ansible-network.network-engine/requirements.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
ansible
|
||||
textfsm
|
||||
10
roles/ansible-network.network-engine/tasks/cli.yaml
Normal file
10
roles/ansible-network.network-engine/tasks/cli.yaml
Normal file
@@ -0,0 +1,10 @@
|
||||
---
|
||||
- name: initialize function
|
||||
include_tasks: includes/init.yaml
|
||||
|
||||
- name: run command on remote network node and use engine to parse output into JSON facts
|
||||
cli:
|
||||
command: "{{ network_engine_command }}"
|
||||
parser: "{{ network_engine_parser | default(omit) }}"
|
||||
engine: "{{ network_engine_engine | default(omit) }}"
|
||||
name: "{{ network_engine_name | default(omit) }}"
|
||||
2
roles/ansible-network.network-engine/tasks/main.yml
Normal file
2
roles/ansible-network.network-engine/tasks/main.yml
Normal file
@@ -0,0 +1,2 @@
|
||||
---
|
||||
# tasks file for network-engine
|
||||
@@ -0,0 +1,3 @@
|
||||
ara
|
||||
flake8
|
||||
yamllint
|
||||
4
roles/ansible-network.network-engine/tests/ansible.cfg
Normal file
4
roles/ansible-network.network-engine/tests/ansible.cfg
Normal file
@@ -0,0 +1,4 @@
|
||||
[defaults]
|
||||
host_key_checking = False
|
||||
retry_files_enabled = False
|
||||
gathering = explicit
|
||||
@@ -0,0 +1,4 @@
|
||||
---
|
||||
parser_path: "{{ role_path }}/parser_templates/{{ ansible_network_os }}"
|
||||
output_path: "{{ role_path }}/output/{{ ansible_network_os }}"
|
||||
export_type: "list"
|
||||
@@ -0,0 +1,85 @@
|
||||
GigabitEthernet0/0 is up, line protocol is up
|
||||
Hardware is iGbE, address is 5e00.0002.0000 (bia 5e00.0002.0000)
|
||||
Description: OOB Management
|
||||
Internet address is 10.8.38.65/24
|
||||
MTU 1500 bytes, BW 1000000 Kbit/sec, DLY 10 usec,
|
||||
reliability 253/255, txload 1/255, rxload 1/255
|
||||
Encapsulation ARPA, loopback not set
|
||||
Keepalive set (10 sec)
|
||||
Full Duplex, Auto Speed, link type is auto, media type is RJ45
|
||||
output flow-control is unsupported, input flow-control is unsupported
|
||||
ARP type: ARPA, ARP Timeout 04:00:00
|
||||
Last input 00:00:00, output 00:00:00, output hang never
|
||||
Last clearing of "show interface" counters never
|
||||
Input queue: 0/75/0/0 (size/max/drops/flushes); Total output drops: 0
|
||||
Queueing strategy: fifo
|
||||
Output queue: 0/40 (size/max)
|
||||
5 minute input rate 2000 bits/sec, 2 packets/sec
|
||||
5 minute output rate 2000 bits/sec, 2 packets/sec
|
||||
4973387 packets input, 816226566 bytes, 0 no buffer
|
||||
Received 228869 broadcasts (0 IP multicasts)
|
||||
461509 runts, 0 giants, 0 throttles
|
||||
461509 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored
|
||||
0 watchdog, 0 multicast, 0 pause input
|
||||
3316083 packets output, 432440225 bytes, 0 underruns
|
||||
0 output errors, 0 collisions, 3 interface resets
|
||||
2303378 unknown protocol drops
|
||||
0 babbles, 0 late collision, 0 deferred
|
||||
1 lost carrier, 0 no carrier, 0 pause output
|
||||
0 output buffer failures, 0 output buffers swapped out
|
||||
GigabitEthernet0/1 is up, line protocol is up
|
||||
Hardware is iGbE, address is fa16.3e4e.c5e5 (bia fa16.3e4e.c5e5)
|
||||
Description: test-interface
|
||||
MTU 2000 bytes, BW 1000000 Kbit/sec, DLY 10 usec,
|
||||
reliability 255/255, txload 1/255, rxload 1/255
|
||||
Encapsulation ARPA, loopback not set
|
||||
Keepalive set (10 sec)
|
||||
Full Duplex, 1Gbps, link type is auto, media type is RJ45
|
||||
output flow-control is unsupported, input flow-control is unsupported
|
||||
ARP type: ARPA, ARP Timeout 04:00:00
|
||||
Last input 4d07h, output 4d07h, output hang never
|
||||
Last clearing of "show interface" counters never
|
||||
Input queue: 0/75/0/0 (size/max/drops/flushes); Total output drops: 0
|
||||
Queueing strategy: fifo
|
||||
Output queue: 0/40 (size/max)
|
||||
5 minute input rate 0 bits/sec, 0 packets/sec
|
||||
5 minute output rate 0 bits/sec, 0 packets/sec
|
||||
89815 packets input, 27598643 bytes, 0 no buffer
|
||||
Received 1 broadcasts (0 IP multicasts)
|
||||
0 runts, 0 giants, 0 throttles
|
||||
0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored
|
||||
0 watchdog, 0 multicast, 0 pause input
|
||||
404016 packets output, 27896846 bytes, 0 underruns
|
||||
0 output errors, 0 collisions, 51 interface resets
|
||||
89728 unknown protocol drops
|
||||
0 babbles, 0 late collision, 0 deferred
|
||||
28 lost carrier, 0 no carrier, 0 pause output
|
||||
0 output buffer failures, 0 output buffers swapped out
|
||||
GigabitEthernet0/2 is up, line protocol is up
|
||||
Hardware is iGbE, address is fa16.3eca.c938 (bia fa16.3eca.c938)
|
||||
Description: test-interface-2
|
||||
MTU 2000 bytes, BW 1000000 Kbit/sec, DLY 10 usec,
|
||||
reliability 255/255, txload 1/255, rxload 1/255
|
||||
Encapsulation ARPA, loopback not set
|
||||
Keepalive set (10 sec)
|
||||
Full Duplex, 1Gbps, link type is auto, media type is RJ45
|
||||
output flow-control is unsupported, input flow-control is unsupported
|
||||
ARP type: ARPA, ARP Timeout 04:00:00
|
||||
Last input 3w1d, output 00:00:08, output hang never
|
||||
Last clearing of "show interface" counters never
|
||||
Input queue: 0/75/0/0 (size/max/drops/flushes); Total output drops: 0
|
||||
Queueing strategy: fifo
|
||||
Output queue: 0/40 (size/max)
|
||||
5 minute input rate 0 bits/sec, 0 packets/sec
|
||||
5 minute output rate 0 bits/sec, 0 packets/sec
|
||||
487240 packets input, 36339153 bytes, 0 no buffer
|
||||
Received 8 broadcasts (0 IP multicasts)
|
||||
183253 runts, 0 giants, 0 throttles
|
||||
183253 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored
|
||||
0 watchdog, 0 multicast, 0 pause input
|
||||
1115575 packets output, 73936479 bytes, 0 underruns
|
||||
0 output errors, 0 collisions, 12 interface resets
|
||||
0 unknown protocol drops
|
||||
0 babbles, 0 late collision, 0 deferred
|
||||
5 lost carrier, 0 no carrier, 0 pause output
|
||||
0 output buffer failures, 0 output buffers swapped out
|
||||
@@ -0,0 +1,44 @@
|
||||
Cisco IOS Software, IOSv Software (VIOS-ADVENTERPRISEK9-M), Version 15.6(2)T, RELEASE SOFTWARE (fc2)
|
||||
Technical Support: http://www.cisco.com/techsupport
|
||||
Copyright (c) 1986-2016 by Cisco Systems, Inc.
|
||||
Compiled Tue 22-Mar-16 16:19 by prod_rel_team
|
||||
|
||||
|
||||
ROM: Bootstrap program is IOSv
|
||||
|
||||
an-ios-01 uptime is 10 weeks, 6 days, 22 hours, 30 minutes
|
||||
System returned to ROM by reload
|
||||
System image file is "flash0:/vios-adventerprisek9-m"
|
||||
Last reload reason: Unknown reason
|
||||
|
||||
|
||||
|
||||
This product contains cryptographic features and is subject to United
|
||||
States and local country laws governing import, export, transfer and
|
||||
use. Delivery of Cisco cryptographic products does not imply
|
||||
third-party authority to import, export, distribute or use encryption.
|
||||
Importers, exporters, distributors and users are responsible for
|
||||
compliance with U.S. and local country laws. By using this product you
|
||||
agree to comply with applicable laws and regulations. If you are unable
|
||||
to comply with U.S. and local laws, return this product immediately.
|
||||
|
||||
A summary of U.S. laws governing Cisco cryptographic products may be found at:
|
||||
http://www.cisco.com/wwl/export/crypto/tool/stqrg.html
|
||||
|
||||
If you require further assistance please contact us by sending email to
|
||||
export@cisco.com.
|
||||
|
||||
Cisco IOSv (revision 1.0) with with 460033K/62464K bytes of memory.
|
||||
Processor board ID 92O0KON393UV5P77JRKZ5
|
||||
4 Gigabit Ethernet interfaces
|
||||
DRAM configuration is 72 bits wide with parity disabled.
|
||||
256K bytes of non-volatile configuration memory.
|
||||
2097152K bytes of ATA System CompactFlash 0 (Read/Write)
|
||||
0K bytes of ATA CompactFlash 1 (Read/Write)
|
||||
0K bytes of ATA CompactFlash 2 (Read/Write)
|
||||
10080K bytes of ATA CompactFlash 3 (Read/Write)
|
||||
|
||||
|
||||
|
||||
Configuration register is 0x0
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
---
|
||||
- name: parser meta data
|
||||
parser_metadata:
|
||||
version: 1.0
|
||||
command: show interface
|
||||
network_os: ios
|
||||
|
||||
- name: match sections
|
||||
pattern_match:
|
||||
regex: "^(\\S+) is up,"
|
||||
match_all: true
|
||||
match_greedy: true
|
||||
register: section
|
||||
|
||||
- name: match interface values
|
||||
pattern_group:
|
||||
- name: match name
|
||||
pattern_match:
|
||||
regex: "^(\\S+)"
|
||||
content: "{{ item }}"
|
||||
register: name
|
||||
|
||||
- name: match hardware
|
||||
pattern_match:
|
||||
regex: "Hardware is (\\S+),"
|
||||
content: "{{ item }}"
|
||||
register: type
|
||||
|
||||
- name: match mtu
|
||||
pattern_match:
|
||||
regex: "MTU (\\d+)"
|
||||
content: "{{ item }}"
|
||||
register: mtu
|
||||
|
||||
- name: match description
|
||||
pattern_match:
|
||||
regex: "Description: (.*)"
|
||||
content: "{{ item }}"
|
||||
register: description
|
||||
loop: "{{ section }}"
|
||||
register: interfaces
|
||||
|
||||
- name: generate json data structure
|
||||
json_template:
|
||||
template:
|
||||
- key: "{{ item.name.matches.0 }}"
|
||||
object:
|
||||
- key: config
|
||||
object:
|
||||
- key: name
|
||||
value: "{{ item.name.matches.0 }}"
|
||||
- key: type
|
||||
value: "{{ item.type.matches.0 }}"
|
||||
- key: mtu
|
||||
value: "{{ item.mtu.matches.0 }}"
|
||||
- key: description
|
||||
value: "{{ item.description.matches.0 }}"
|
||||
loop: "{{ interfaces }}"
|
||||
export: true
|
||||
export_as: "{{ export_type }}"
|
||||
register: interface_facts
|
||||
@@ -0,0 +1,61 @@
|
||||
---
|
||||
- name: parser meta data
|
||||
parser_metadata:
|
||||
version: 1.0
|
||||
command: show interface
|
||||
network_os: ios
|
||||
|
||||
- name: match sections
|
||||
pattern_match:
|
||||
regex: "^(\\S+) is up,"
|
||||
match_all: true
|
||||
match_greedy: true
|
||||
register: section
|
||||
|
||||
- name: match interface values
|
||||
pattern_group:
|
||||
- name: match name
|
||||
pattern_match:
|
||||
regex: "^(\\S+)"
|
||||
content: "{{ item }}"
|
||||
register: name
|
||||
|
||||
- name: match hardware
|
||||
pattern_match:
|
||||
regex: "Hardware is (\\S+),"
|
||||
content: "{{ item }}"
|
||||
register: type
|
||||
|
||||
- name: match mtu
|
||||
pattern_match:
|
||||
regex: "MTU (\\d+)"
|
||||
content: "{{ item }}"
|
||||
register: mtu
|
||||
|
||||
- name: match description
|
||||
pattern_match:
|
||||
regex: "Description: (.*)"
|
||||
content: "{{ item }}"
|
||||
register: description
|
||||
loop: "{{ section }}"
|
||||
register: interfaces
|
||||
|
||||
- name: generate json data structure
|
||||
json_template:
|
||||
template:
|
||||
- key: "{{ item.name.matches.0 }}"
|
||||
object:
|
||||
- key: config
|
||||
object:
|
||||
- key: name
|
||||
value: "{{ item.name.matches.0 }}"
|
||||
- key: type
|
||||
value: "{{ item.type.matches.0 }}"
|
||||
- key: mtu
|
||||
value: "{{ item.mtu.matches.0 }}"
|
||||
- key: description
|
||||
value: "{{ item.description.matches.0 }}"
|
||||
loop: "{{ interfaces }}"
|
||||
export: true
|
||||
register: interface_facts
|
||||
extend: test.extension
|
||||
@@ -0,0 +1,48 @@
|
||||
---
|
||||
- name: parser meta data
|
||||
parser_metadata:
|
||||
version: 1.0
|
||||
command: show version
|
||||
network_os: ios
|
||||
|
||||
- name: match version
|
||||
pattern_match:
|
||||
regex: "Version (\\S+),"
|
||||
register: version
|
||||
|
||||
- name: match model
|
||||
pattern_match:
|
||||
regex: "^Cisco (.+) \\(revision"
|
||||
register: model
|
||||
|
||||
- name: match image
|
||||
pattern_match:
|
||||
regex: "^System image file is (\\S+)"
|
||||
register: image
|
||||
|
||||
- name: match uptime
|
||||
pattern_match:
|
||||
regex: "uptime is (.+)"
|
||||
register: uptime
|
||||
|
||||
- name: match total memory
|
||||
pattern_match:
|
||||
regex: "with (\\S+)/(\\w*) bytes of memory"
|
||||
register: total_mem
|
||||
|
||||
- name: match free memory
|
||||
pattern_match:
|
||||
regex: "with \\w*/(\\S+) bytes of memory"
|
||||
register: free_mem
|
||||
|
||||
- name: export system facts to playbook
|
||||
set_vars:
|
||||
model: "{{ model.matches.0 }}"
|
||||
image_file: "{{ image.matches.0 }}"
|
||||
uptime: "{{ uptime.matches.0 }}"
|
||||
version: "{{ version.matches.0 }}"
|
||||
memory:
|
||||
total: "{{ total_mem.matches.0 }}"
|
||||
free: "{{ free_mem.matches.0 }}"
|
||||
export: true
|
||||
register: system_facts
|
||||
@@ -0,0 +1,49 @@
|
||||
---
|
||||
- name: parser meta data
|
||||
parser_metadata:
|
||||
version: 1.0
|
||||
command: show version
|
||||
network_os: ios
|
||||
|
||||
- name: match version
|
||||
pattern_match:
|
||||
regex: "Version (\\S+),"
|
||||
register: version
|
||||
|
||||
- name: match model
|
||||
pattern_match:
|
||||
regex: "^Cisco (.+) \\(revision"
|
||||
register: model
|
||||
|
||||
- name: match image
|
||||
pattern_match:
|
||||
regex: "^System image file is (\\S+)"
|
||||
register: image
|
||||
|
||||
- name: match uptime
|
||||
pattern_match:
|
||||
regex: "uptime is (.+)"
|
||||
register: uptime
|
||||
|
||||
- name: match total memory
|
||||
pattern_match:
|
||||
regex: "with (\\S+)/(\\w*) bytes of memory"
|
||||
register: total_mem
|
||||
|
||||
- name: match free memory
|
||||
pattern_match:
|
||||
regex: "with \\w*/(\\S+) bytes of memory"
|
||||
register: free_mem
|
||||
|
||||
- name: export system facts to playbook
|
||||
set_vars:
|
||||
model: "{{ model.matches.0 }}"
|
||||
image_file: "{{ image.matches.0 }}"
|
||||
uptime: "{{ uptime.matches.0 }}"
|
||||
version: "{{ version.matches.0 }}"
|
||||
memory:
|
||||
total: "{{ total_mem.matches.0 }}"
|
||||
free: "{{ free_mem.matches.0 }}"
|
||||
export: true
|
||||
register: system_facts
|
||||
extend: test.extension
|
||||
@@ -0,0 +1,79 @@
|
||||
---
|
||||
- name: "command_parser test for {{ ansible_network_os }} show_interface"
|
||||
command_parser:
|
||||
file: "{{ parser_path }}/show_interfaces.yaml"
|
||||
content: "{{ lookup('file', '{{ output_path }}/show_interfaces.txt') }}"
|
||||
register: result
|
||||
vars:
|
||||
- ansible_network_os: ios
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "'interface_facts' in result.ansible_facts"
|
||||
- "'GigabitEthernet0/0' in result.ansible_facts.interface_facts[0]"
|
||||
- "'GigabitEthernet0/1' in result.ansible_facts.interface_facts[1]"
|
||||
- "result.ansible_facts.interface_facts[0]['GigabitEthernet0/0']['config']['name'] == 'GigabitEthernet0/0'"
|
||||
- "result.ansible_facts.interface_facts[0]['GigabitEthernet0/0']['config']['description'] == 'OOB Management'"
|
||||
- "result.ansible_facts.interface_facts[1]['GigabitEthernet0/1']['config']['name'] == 'GigabitEthernet0/1'"
|
||||
- "result.ansible_facts.interface_facts[1]['GigabitEthernet0/1']['config']['description'] == 'test-interface'"
|
||||
|
||||
- name: "command_parser test for {{ ansible_network_os }} show_version"
|
||||
command_parser:
|
||||
file: "{{ parser_path }}/show_version.yaml"
|
||||
content: "{{ lookup('file', '{{ output_path }}/show_version.txt') }}"
|
||||
register: result
|
||||
vars:
|
||||
- ansible_network_os: ios
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "'system_facts' in result.ansible_facts"
|
||||
- "'flash0:/vios-adventerprisek9-m' in result.ansible_facts.system_facts['image_file']"
|
||||
- "'IOSv' in result.ansible_facts.system_facts['model']"
|
||||
- "'15.6(2)T' in result.ansible_facts.system_facts['version']"
|
||||
- "'10 weeks, 6 days, 22 hours, 30 minutes' in result.ansible_facts.system_facts['uptime']"
|
||||
- "'62464K' in result.ansible_facts.system_facts['memory']['free']"
|
||||
- "'460033K' in result.ansible_facts.system_facts['memory']['total']"
|
||||
|
||||
- name: "command_parser expansion test for {{ ansible_network_os }} show_version"
|
||||
command_parser:
|
||||
file: "{{ parser_path }}/show_version_expand.yaml"
|
||||
content: "{{ lookup('file', '{{ output_path }}/show_version.txt') }}"
|
||||
register: result
|
||||
vars:
|
||||
- ansible_network_os: ios
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "'system_facts' in result.ansible_facts.test.extension"
|
||||
- "'flash0:/vios-adventerprisek9-m' in result.ansible_facts.test.extension.system_facts['image_file']"
|
||||
- "'IOSv' in result.ansible_facts.test.extension.system_facts['model']"
|
||||
- "'15.6(2)T' in result.ansible_facts.test.extension.system_facts['version']"
|
||||
- "'10 weeks, 6 days, 22 hours, 30 minutes' in result.ansible_facts.test.extension.system_facts['uptime']"
|
||||
- "'62464K' in result.ansible_facts.test.extension.system_facts['memory']['free']"
|
||||
- "'460033K' in result.ansible_facts.test.extension.system_facts['memory']['total']"
|
||||
|
||||
- name: "command_parser expansion test for {{ ansible_network_os }} show_interface"
|
||||
command_parser:
|
||||
file: "{{ parser_path }}/show_interfaces_expand.yaml"
|
||||
content: "{{ lookup('file', '{{ output_path }}/show_interfaces.txt') }}"
|
||||
register: result
|
||||
vars:
|
||||
- ansible_network_os: ios
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "'system_facts' in result.ansible_facts.test.extension"
|
||||
- "'flash0:/vios-adventerprisek9-m' in result.ansible_facts.test.extension.system_facts['image_file']"
|
||||
- "'IOSv' in result.ansible_facts.test.extension.system_facts['model']"
|
||||
- "'15.6(2)T' in result.ansible_facts.test.extension.system_facts['version']"
|
||||
- "'10 weeks, 6 days, 22 hours, 30 minutes' in result.ansible_facts.test.extension.system_facts['uptime']"
|
||||
- "'62464K' in result.ansible_facts.test.extension.system_facts['memory']['free']"
|
||||
- "'460033K' in result.ansible_facts.test.extension.system_facts['memory']['total']"
|
||||
- "'interface_facts' in result.ansible_facts.test.extension"
|
||||
- "'GigabitEthernet0/0' in result.ansible_facts.test.extension.interface_facts[0]"
|
||||
- "'GigabitEthernet0/1' in result.ansible_facts.test.extension.interface_facts[1]"
|
||||
- "result.ansible_facts.test.extension.interface_facts[0]['GigabitEthernet0/0']['config']['name'] == 'GigabitEthernet0/0'"
|
||||
- "result.ansible_facts.test.extension.interface_facts[0]['GigabitEthernet0/0']['config']['description'] == 'OOB Management'"
|
||||
- "result.ansible_facts.test.extension.interface_facts[1]['GigabitEthernet0/1']['config']['name'] == 'GigabitEthernet0/1'"
|
||||
- "result.ansible_facts.test.extension.interface_facts[1]['GigabitEthernet0/1']['config']['description'] == 'test-interface'"
|
||||
@@ -0,0 +1,7 @@
|
||||
---
|
||||
- name: import dependency role for test
|
||||
import_role:
|
||||
name: "{{ role_path.split('/tests/command_parser/command_parser')[0] }}"
|
||||
|
||||
- name: ios command_parser test
|
||||
import_tasks: ios.yaml
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
- hosts: localhost
|
||||
connection: local
|
||||
roles:
|
||||
- command_parser
|
||||
@@ -0,0 +1,12 @@
|
||||
---
|
||||
- set_fact:
|
||||
test: string
|
||||
|
||||
- set_fact:
|
||||
test_pass: "{{ lookup('config_template', 'pass.j2') }}"
|
||||
test_fail: "{{ lookup('config_template', 'fail.j2') }}"
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "'test string' in test_pass"
|
||||
- "'test string' not in test_fail"
|
||||
@@ -0,0 +1,7 @@
|
||||
---
|
||||
- name: import dependency role for test
|
||||
import_role:
|
||||
name: "{{ role_path.split('/tests/config_template/config_template')[0] }}"
|
||||
|
||||
- name: config_template test
|
||||
import_tasks: config_template.yaml
|
||||
@@ -0,0 +1 @@
|
||||
test {{ bad | default(omit) }}
|
||||
@@ -0,0 +1 @@
|
||||
test {{ test }}
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
- hosts: localhost
|
||||
connection: local
|
||||
roles:
|
||||
- config_template
|
||||
@@ -0,0 +1,35 @@
|
||||
---
|
||||
- name: interface_range Ethernet1-3
|
||||
debug:
|
||||
msg: "{{ 'Ethernet1-3' | interface_range }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "'Ethernet1' in result.msg"
|
||||
- "'Ethernet2' in result.msg"
|
||||
- "'Ethernet3' in result.msg"
|
||||
|
||||
- name: interface_range Ethernet1,3-4,5
|
||||
debug:
|
||||
msg: "{{ 'Ethernet1,3-4,5' | interface_range }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "'Ethernet1' in result.msg"
|
||||
- "'Ethernet3' in result.msg"
|
||||
- "'Ethernet4' in result.msg"
|
||||
- "'Ethernet5' in result.msg"
|
||||
|
||||
- name: interface_range Ethernet1/3-5,8
|
||||
debug:
|
||||
msg: "{{ 'Ethernet1/3-5,8' | interface_range }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "'Ethernet1/3' in result.msg"
|
||||
- "'Ethernet1/4' in result.msg"
|
||||
- "'Ethernet1/5' in result.msg"
|
||||
- "'Ethernet1/8' in result.msg"
|
||||
@@ -0,0 +1,7 @@
|
||||
---
|
||||
- name: import dependency role for test
|
||||
import_role:
|
||||
name: "{{ role_path.split('/tests/interface_range/interface_range')[0] }}"
|
||||
|
||||
- name: interface_range test
|
||||
import_tasks: interface_range.yaml
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
- hosts: localhost
|
||||
connection: local
|
||||
roles:
|
||||
- interface_range
|
||||
@@ -0,0 +1,28 @@
|
||||
---
|
||||
- name: interface_split Ethernet1
|
||||
debug:
|
||||
msg: "{{ 'Ethernet1' | interface_split }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "'1' in result.msg.index"
|
||||
- "'Ethernet' in result.msg.name"
|
||||
|
||||
- name: interface_split Ethernet1 name
|
||||
debug:
|
||||
msg: "{{ 'Ethernet1' | interface_split('name') }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "'Ethernet' in result.msg"
|
||||
|
||||
- name: interface_split Ethernet1 index
|
||||
debug:
|
||||
msg: "{{ 'Ethernet1' | interface_split('index') }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "'1' in result.msg"
|
||||
@@ -0,0 +1,7 @@
|
||||
---
|
||||
- name: import dependency role for test
|
||||
import_role:
|
||||
name: "{{ role_path.split('/tests/interface_split/interface_split')[0] }}"
|
||||
|
||||
- name: interface_split test
|
||||
import_tasks: interface_split.yaml
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
- hosts: localhost
|
||||
connection: local
|
||||
roles:
|
||||
- interface_split
|
||||
2
roles/ansible-network.network-engine/tests/inventory
Normal file
2
roles/ansible-network.network-engine/tests/inventory
Normal file
@@ -0,0 +1,2 @@
|
||||
localhost
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user