diff --git a/.gitignore b/.gitignore index 894a44c..c45c871 100644 --- a/.gitignore +++ b/.gitignore @@ -1,104 +1,107 @@ # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] *$py.class # C extensions *.so # Distribution / packaging .Python build/ develop-eggs/ dist/ downloads/ eggs/ .eggs/ lib/ lib64/ parts/ sdist/ var/ wheels/ *.egg-info/ .installed.cfg *.egg MANIFEST # PyInstaller # Usually these files are written by a python script from a template # before PyInstaller builds the exe, so as to inject date/other infos into it. *.manifest *.spec # Installer logs pip-log.txt pip-delete-this-directory.txt # Unit test / coverage reports htmlcov/ .tox/ .coverage .coverage.* .cache nosetests.xml coverage.xml *.cover .hypothesis/ .pytest_cache/ # Translations *.mo *.pot +#ide +.vscode + # Django stuff: *.log local_settings.py db.sqlite3 # Flask stuff: instance/ .webassets-cache # Scrapy stuff: .scrapy # Sphinx documentation docs/_build/ # PyBuilder target/ # Jupyter Notebook .ipynb_checkpoints # pyenv .python-version # celery beat schedule file celerybeat-schedule # SageMath parsed files *.sage.py # Environments .env .venv env/ venv/ ENV/ env.bak/ venv.bak/ # Spyder project settings .spyderproject .spyproject # Rope project settings .ropeproject # mkdocs documentation /site # mypy .mypy_cache/ diff --git a/README.md b/README.md index 4c8649b..6f28eb5 100644 --- a/README.md +++ b/README.md @@ -1,169 +1,170 @@ # VyOS Collection [![CI](https://zuul-ci.org/gated.svg)](https://dashboard.zuul.ansible.com/t/ansible/project/github.com/ansible-collections/vyos.vyos) The Ansible VyOS collection includes a variety of Ansible content to help automate the management of VyOS network appliances. This collection has been tested against VyOS 1.1.8 (helium). ## Ansible version compatibility This collection has been tested against following Ansible versions: **>=2.9.10**. Plugins and modules within a collection may be tested with only specific Ansible versions. A collection may contain metadata that identifies these versions. PEP440 is the schema used to describe the versions of Ansible. ### Supported connections The VyOS collection supports ``network_cli`` connections. ## Included content ### Cliconf plugins Name | Description --- | --- [vyos.vyos.vyos](https://github.com/ansible-collections/vyos.vyos/blob/main/docs/vyos.vyos.vyos_cliconf.rst)|Use vyos cliconf to run command on VyOS platform ### Modules Name | Description --- | --- [vyos.vyos.vyos_banner](https://github.com/ansible-collections/vyos.vyos/blob/main/docs/vyos.vyos.vyos_banner_module.rst)|Manage multiline banners on VyOS devices [vyos.vyos.vyos_bgp_address_family](https://github.com/ansible-collections/vyos.vyos/blob/main/docs/vyos.vyos.vyos_bgp_address_family_module.rst)|BGP Address Family Resource Module. [vyos.vyos.vyos_bgp_global](https://github.com/ansible-collections/vyos.vyos/blob/main/docs/vyos.vyos.vyos_bgp_global_module.rst)|BGP Global Resource Module. [vyos.vyos.vyos_command](https://github.com/ansible-collections/vyos.vyos/blob/main/docs/vyos.vyos.vyos_command_module.rst)|Run one or more commands on VyOS devices [vyos.vyos.vyos_config](https://github.com/ansible-collections/vyos.vyos/blob/main/docs/vyos.vyos.vyos_config_module.rst)|Manage VyOS configuration on remote device [vyos.vyos.vyos_facts](https://github.com/ansible-collections/vyos.vyos/blob/main/docs/vyos.vyos.vyos_facts_module.rst)|Get facts about vyos devices. [vyos.vyos.vyos_firewall_global](https://github.com/ansible-collections/vyos.vyos/blob/main/docs/vyos.vyos.vyos_firewall_global_module.rst)|FIREWALL global resource module [vyos.vyos.vyos_firewall_interfaces](https://github.com/ansible-collections/vyos.vyos/blob/main/docs/vyos.vyos.vyos_firewall_interfaces_module.rst)|FIREWALL interfaces resource module [vyos.vyos.vyos_firewall_rules](https://github.com/ansible-collections/vyos.vyos/blob/main/docs/vyos.vyos.vyos_firewall_rules_module.rst)|FIREWALL rules resource module [vyos.vyos.vyos_interface](https://github.com/ansible-collections/vyos.vyos/blob/main/docs/vyos.vyos.vyos_interface_module.rst)|(deprecated, removed after 2022-06-01) Manage Interface on VyOS network devices [vyos.vyos.vyos_interfaces](https://github.com/ansible-collections/vyos.vyos/blob/main/docs/vyos.vyos.vyos_interfaces_module.rst)|Interfaces resource module [vyos.vyos.vyos_l3_interface](https://github.com/ansible-collections/vyos.vyos/blob/main/docs/vyos.vyos.vyos_l3_interface_module.rst)|(deprecated, removed after 2022-06-01) Manage L3 interfaces on VyOS network devices [vyos.vyos.vyos_l3_interfaces](https://github.com/ansible-collections/vyos.vyos/blob/main/docs/vyos.vyos.vyos_l3_interfaces_module.rst)|L3 interfaces resource module [vyos.vyos.vyos_lag_interfaces](https://github.com/ansible-collections/vyos.vyos/blob/main/docs/vyos.vyos.vyos_lag_interfaces_module.rst)|LAG interfaces resource module [vyos.vyos.vyos_linkagg](https://github.com/ansible-collections/vyos.vyos/blob/main/docs/vyos.vyos.vyos_linkagg_module.rst)|(deprecated, removed after 2022-06-01) Manage link aggregation groups on VyOS network devices [vyos.vyos.vyos_lldp](https://github.com/ansible-collections/vyos.vyos/blob/main/docs/vyos.vyos.vyos_lldp_module.rst)|(deprecated, removed after 2022-06-01) Manage LLDP configuration on VyOS network devices [vyos.vyos.vyos_lldp_global](https://github.com/ansible-collections/vyos.vyos/blob/main/docs/vyos.vyos.vyos_lldp_global_module.rst)|LLDP global resource module [vyos.vyos.vyos_lldp_interface](https://github.com/ansible-collections/vyos.vyos/blob/main/docs/vyos.vyos.vyos_lldp_interface_module.rst)|(deprecated, removed after 2022-06-01) Manage LLDP interfaces configuration on VyOS network devices [vyos.vyos.vyos_lldp_interfaces](https://github.com/ansible-collections/vyos.vyos/blob/main/docs/vyos.vyos.vyos_lldp_interfaces_module.rst)|LLDP interfaces resource module [vyos.vyos.vyos_logging](https://github.com/ansible-collections/vyos.vyos/blob/main/docs/vyos.vyos.vyos_logging_module.rst)|Manage logging on network devices +[vyos.vyos.vyos_logging_global](https://github.com/ansible-collections/vyos.vyos/blob/main/docs/vyos.vyos.vyos_logging_global_module.rst)|Logging resource module [vyos.vyos.vyos_ospf_interfaces](https://github.com/ansible-collections/vyos.vyos/blob/main/docs/vyos.vyos.vyos_ospf_interfaces_module.rst)|OSPF Interfaces Resource Module. [vyos.vyos.vyos_ospfv2](https://github.com/ansible-collections/vyos.vyos/blob/main/docs/vyos.vyos.vyos_ospfv2_module.rst)|OSPFv2 resource module [vyos.vyos.vyos_ospfv3](https://github.com/ansible-collections/vyos.vyos/blob/main/docs/vyos.vyos.vyos_ospfv3_module.rst)|OSPFV3 resource module [vyos.vyos.vyos_ping](https://github.com/ansible-collections/vyos.vyos/blob/main/docs/vyos.vyos.vyos_ping_module.rst)|Tests reachability using ping from VyOS network devices [vyos.vyos.vyos_prefix_lists](https://github.com/ansible-collections/vyos.vyos/blob/main/docs/vyos.vyos.vyos_prefix_lists_module.rst)|Prefix-Lists resource module for VyOS [vyos.vyos.vyos_route_maps](https://github.com/ansible-collections/vyos.vyos/blob/main/docs/vyos.vyos.vyos_route_maps_module.rst)|Route Map Resource Module. [vyos.vyos.vyos_static_route](https://github.com/ansible-collections/vyos.vyos/blob/main/docs/vyos.vyos.vyos_static_route_module.rst)|(deprecated, removed after 2022-06-01) Manage static IP routes on Vyatta VyOS network devices [vyos.vyos.vyos_static_routes](https://github.com/ansible-collections/vyos.vyos/blob/main/docs/vyos.vyos.vyos_static_routes_module.rst)|Static routes resource module [vyos.vyos.vyos_system](https://github.com/ansible-collections/vyos.vyos/blob/main/docs/vyos.vyos.vyos_system_module.rst)|Run `set system` commands on VyOS devices [vyos.vyos.vyos_user](https://github.com/ansible-collections/vyos.vyos/blob/main/docs/vyos.vyos.vyos_user_module.rst)|Manage the collection of local users on VyOS device [vyos.vyos.vyos_vlan](https://github.com/ansible-collections/vyos.vyos/blob/main/docs/vyos.vyos.vyos_vlan_module.rst)|Manage VLANs on VyOS network devices Click the ``Content`` button to see the list of content included in this collection. ## Installing this collection You can install the VyOS collection with the Ansible Galaxy CLI: ansible-galaxy collection install vyos.vyos You can also include it in a `requirements.yml` file and install it with `ansible-galaxy collection install -r requirements.yml`, using the format: ```yaml --- collections: - name: vyos.vyos ``` ## Using this collection This collection includes [network resource modules](https://docs.ansible.com/ansible/latest/network/user_guide/network_resource_modules.html). ### Using modules from the VyOS collection in your playbooks You can call modules by their Fully Qualified Collection Namespace (FQCN), such as `vyos.vyos.vyos_static_routes`. The following example task replaces configuration changes in the existing configuration on a VyOS network device, using the FQCN: ```yaml --- - name: Replace device configurations of listed static routes with provided configurations register: result vyos.vyos.vyos_static_routes: &id001 config: - address_families: - afi: ipv4 routes: - dest: 192.0.2.32/28 blackhole_config: distance: 2 next_hops: - forward_router_address: 192.0.2.7 - forward_router_address: 192.0.2.8 - forward_router_address: 192.0.2.9 state: replaced ``` **NOTE**: For Ansible 2.9, you may not see deprecation warnings when you run your playbooks with this collection. Use this documentation to track when a module is deprecated. ### See Also: * [VyOS Platform Options](https://docs.ansible.com/ansible/latest/network/user_guide/platform_vyos.html) * [Ansible Using collections](https://docs.ansible.com/ansible/latest/user_guide/collections_using.html) for more details. ## Contributing to this collection We welcome community contributions to this collection. If you find problems, please open an issue or create a PR against the [VyOS collection repository](https://github.com/ansible-collections/vyos). See [Contributing to Ansible-maintained collections](https://docs.ansible.com/ansible/devel/community/contributing_maintained_collections.html#contributing-maintained-collections) for complete details. You can also join us on: - IRC - the ``#ansible-network`` [irc.libera.chat](https://libera.chat/) channel - Slack - https://ansiblenetwork.slack.com See the [Ansible Community Guide](https://docs.ansible.com/ansible/latest/community/index.html) for details on contributing to Ansible. ### Code of Conduct This collection follows the Ansible project's [Code of Conduct](https://docs.ansible.com/ansible/devel/community/code_of_conduct.html). Please read and familiarize yourself with this document. ## Changelogs ## Release notes Release notes are available [here](https://github.com/ansible-collections/vyos.vyos/blob/main/CHANGELOG.rst). ## Roadmap ## More information - [Ansible network resources](https://docs.ansible.com/ansible/latest/network/getting_started/network_resources.html) - [Ansible Collection overview](https://github.com/ansible-collections/overview) - [Ansible User guide](https://docs.ansible.com/ansible/latest/user_guide/index.html) - [Ansible Developer guide](https://docs.ansible.com/ansible/latest/dev_guide/index.html) - [Ansible Community code of conduct](https://docs.ansible.com/ansible/latest/community/code_of_conduct.html) ## Licensing GNU General Public License v3.0 or later. See [LICENSE](https://www.gnu.org/licenses/gpl-3.0.txt) to see the full text. diff --git a/changelogs/fragments/vyos_logging_global_module.yaml b/changelogs/fragments/vyos_logging_global_module.yaml new file mode 100644 index 0000000..d9f2c8f --- /dev/null +++ b/changelogs/fragments/vyos_logging_global_module.yaml @@ -0,0 +1,5 @@ +--- +minor_changes: + - vyos_logging_global logging resource module. +deprecated_features: + - The vyos_logging module has been deprecated in favor of the new vyos_logging_global resource module and will be removed in a release after "2023-08-01". diff --git a/docs/vyos.vyos.vyos_logging_global_module.rst b/docs/vyos.vyos.vyos_logging_global_module.rst new file mode 100644 index 0000000..0ee2505 --- /dev/null +++ b/docs/vyos.vyos.vyos_logging_global_module.rst @@ -0,0 +1,1648 @@ +.. _vyos.vyos.vyos_logging_global_module: + + +***************************** +vyos.vyos.vyos_logging_global +***************************** + +**Logging resource module** + + +Version added: 2.4.0 + +.. contents:: + :local: + :depth: 1 + + +Synopsis +-------- +- This module manages the logging attributes of Vyos network devices + + + + +Parameters +---------- + +.. raw:: html + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ParameterChoices/DefaultsComments
+
+ config + +
+ dictionary +
+
+ +
A list containing dictionary of logging options
+
+
+ console + +
+ dictionary +
+
+ +
logging to serial console
+
+
+ facilities + +
+ list + / elements=dictionary +
+
+ +
facility configurations for console
+
+
+ facility + +
+ string +
+
+
    Choices: +
  • all
  • +
  • auth
  • +
  • authpriv
  • +
  • cron
  • +
  • daemon
  • +
  • kern
  • +
  • lpr
  • +
  • mail
  • +
  • mark
  • +
  • news
  • +
  • protocols
  • +
  • security
  • +
  • syslog
  • +
  • user
  • +
  • uucp
  • +
  • local0
  • +
  • local1
  • +
  • local2
  • +
  • local3
  • +
  • local4
  • +
  • local5
  • +
  • local6
  • +
  • local7
  • +
+
+
Facility for logging
+
+
+ severity + +
+ string +
+
+
    Choices: +
  • emerg
  • +
  • alert
  • +
  • crit
  • +
  • err
  • +
  • warning
  • +
  • notice
  • +
  • info
  • +
  • debug
  • +
  • all
  • +
+
+
logging level
+
+
+ state + +
+ string +
+
+
    Choices: +
  • enabled
  • +
  • disabled
  • +
+
+
enable or disable the command
+
+
+ files + +
+ list + / elements=dictionary +
+
+ +
logging to file
+
+
+ archive + +
+ dictionary +
+
+ +
Log file size and rotation characteristics
+
+
+ file_num + +
+ integer +
+
+ +
Number of saved files (default is 5)
+
+
+ size + +
+ integer +
+
+ +
Size of log files (in kilobytes, default is 256)
+
+
+ state + +
+ string +
+
+
    Choices: +
  • enabled
  • +
  • disabled
  • +
+
+
enable or disable the command
+
+
+ facilities + +
+ list + / elements=dictionary +
+
+ +
facility configurations
+
+
+ facility + +
+ string +
+
+
    Choices: +
  • all
  • +
  • auth
  • +
  • authpriv
  • +
  • cron
  • +
  • daemon
  • +
  • kern
  • +
  • lpr
  • +
  • mail
  • +
  • mark
  • +
  • news
  • +
  • protocols
  • +
  • security
  • +
  • syslog
  • +
  • user
  • +
  • uucp
  • +
  • local0
  • +
  • local1
  • +
  • local2
  • +
  • local3
  • +
  • local4
  • +
  • local5
  • +
  • local6
  • +
  • local7
  • +
+
+
Facility for logging
+
+
+ severity + +
+ string +
+
+
    Choices: +
  • emerg
  • +
  • alert
  • +
  • crit
  • +
  • err
  • +
  • warning
  • +
  • notice
  • +
  • info
  • +
  • debug
  • +
  • all
  • +
+
+
logging level
+
+
+ path + +
+ string +
+
+ +
file name or path
+
+
+ global_params + +
+ dictionary +
+
+ +
logging to serial console
+
+
+ archive + +
+ dictionary +
+
+ +
Log file size and rotation characteristics
+
+
+ file_num + +
+ integer +
+
+ +
Number of saved files (default is 5)
+
+
+ size + +
+ integer +
+
+ +
Size of log files (in kilobytes, default is 256)
+
+
+ state + +
+ string +
+
+
    Choices: +
  • enabled
  • +
  • disabled
  • +
+
+
enable or disable the command
+
+
+ facilities + +
+ list + / elements=dictionary +
+
+ +
facility configurations
+
+
+ facility + +
+ string +
+
+
    Choices: +
  • all
  • +
  • auth
  • +
  • authpriv
  • +
  • cron
  • +
  • daemon
  • +
  • kern
  • +
  • lpr
  • +
  • mail
  • +
  • mark
  • +
  • news
  • +
  • protocols
  • +
  • security
  • +
  • syslog
  • +
  • user
  • +
  • uucp
  • +
  • local0
  • +
  • local1
  • +
  • local2
  • +
  • local3
  • +
  • local4
  • +
  • local5
  • +
  • local6
  • +
  • local7
  • +
+
+
Facility for logging
+
+
+ severity + +
+ string +
+
+
    Choices: +
  • emerg
  • +
  • alert
  • +
  • crit
  • +
  • err
  • +
  • warning
  • +
  • notice
  • +
  • info
  • +
  • debug
  • +
  • all
  • +
+
+
logging level
+
+
+ marker_interval + +
+ integer +
+
+ +
time interval how often a mark message is being sent in seconds (default is 1200)
+
+
+ preserve_fqdn + +
+ boolean +
+
+
    Choices: +
  • no
  • +
  • yes
  • +
+
+
uses FQDN for logging
+
+
+ state + +
+ string +
+
+
    Choices: +
  • enabled
  • +
  • disabled
  • +
+
+
enable or disable the command
+
+
+ hosts + +
+ list + / elements=dictionary +
+
+ +
logging to serial console
+
+
+ facilities + +
+ list + / elements=dictionary +
+
+ +
facility configurations for host
+
+
+ facility + +
+ string +
+
+
    Choices: +
  • all
  • +
  • auth
  • +
  • authpriv
  • +
  • cron
  • +
  • daemon
  • +
  • kern
  • +
  • lpr
  • +
  • mail
  • +
  • mark
  • +
  • news
  • +
  • protocols
  • +
  • security
  • +
  • syslog
  • +
  • user
  • +
  • uucp
  • +
  • local0
  • +
  • local1
  • +
  • local2
  • +
  • local3
  • +
  • local4
  • +
  • local5
  • +
  • local6
  • +
  • local7
  • +
+
+
Facility for logging
+
+
+ protocol + +
+ string +
+
+
    Choices: +
  • udp
  • +
  • tcp
  • +
+
+
syslog communication protocol
+
+
+ severity + +
+ string +
+
+
    Choices: +
  • emerg
  • +
  • alert
  • +
  • crit
  • +
  • err
  • +
  • warning
  • +
  • notice
  • +
  • info
  • +
  • debug
  • +
  • all
  • +
+
+
logging level
+
+
+ hostname + +
+ string +
+
+ +
Remote host name or IP address
+
+
+ port + +
+ integer +
+
+ +
Destination port (1-65535)
+
+
+ syslog + +
+ dictionary +
+
+ +
logging syslog
+
+
+ state + +
+ string +
+
+
    Choices: +
  • enabled
  • +
  • disabled
  • +
+
+
enable or disable the command
+
+
+ users + +
+ list + / elements=dictionary +
+
+ +
logging to file
+
+
+ facilities + +
+ list + / elements=dictionary +
+
+ +
facility configurations
+
+
+ facility + +
+ string +
+
+
    Choices: +
  • all
  • +
  • auth
  • +
  • authpriv
  • +
  • cron
  • +
  • daemon
  • +
  • kern
  • +
  • lpr
  • +
  • mail
  • +
  • mark
  • +
  • news
  • +
  • protocols
  • +
  • security
  • +
  • syslog
  • +
  • user
  • +
  • uucp
  • +
  • local0
  • +
  • local1
  • +
  • local2
  • +
  • local3
  • +
  • local4
  • +
  • local5
  • +
  • local6
  • +
  • local7
  • +
+
+
Facility for logging
+
+
+ severity + +
+ string +
+
+
    Choices: +
  • emerg
  • +
  • alert
  • +
  • crit
  • +
  • err
  • +
  • warning
  • +
  • notice
  • +
  • info
  • +
  • debug
  • +
  • all
  • +
+
+
logging level
+
+
+ username + +
+ string +
+
+ +
user login name
+
+
+ running_config + +
+ string +
+
+ +
This option is used only with state parsed.
+
The value of this option should be the output received from the VYOS device by executing the command show configuration commands | grep syslog.
+
The state parsed reads the configuration from running_config option and transforms it into Ansible structured data as per the resource module's argspec and the value is then returned in the parsed key within the result.
+
+
+ state + +
+ string +
+
+
    Choices: +
  • merged ←
  • +
  • replaced
  • +
  • overridden
  • +
  • deleted
  • +
  • gathered
  • +
  • parsed
  • +
  • rendered
  • +
+
+
The state the configuration should be left in
+
The states replaced and overridden have identical behaviour for this module.
+
Refer to examples for more details.
+
+
+ + +Notes +----- + +.. note:: + - Tested against vyos 1.2 + - This module works with connection ``network_cli``. + - The Configuration defaults of the Vyos network devices are supposed to hinder idempotent behavior of plays + + + +Examples +-------- + +.. code-block:: yaml + + # Using state: merged + + # Before state: + # ------------- + + # vyos:~$show configuration commands | grep syslog + + - name: Apply the provided configuration + vyos.vyos.vyos_logging_global: + config: + console: + facilities: + - facility: local7 + severity: err + files: + - path: logFile + archive: + file_num: 2 + facilities: + - facility: local6 + severity: emerg + hosts: + - hostname: 172.16.0.1 + facilities: + - facility: local7 + severity: all + - facility: all + protocol: udp + port: 223 + users: + - username: vyos + facilities: + - facility: local7 + severity: debug + global_params: + archive: + file_num: 2 + size: 111 + facilities: + - facility: cron + severity: debug + marker_interval: 111 + preserve_fqdn: true + state: merged + + # Commands Fired: + # --------------- + + # "commands": [ + # "set system syslog console facility local7 level err", + # "set system syslog file logFile archive file 2", + # "set system syslog host 172.16.0.1 facility local7 level all", + # "set system syslog file logFile facility local6 level emerg", + # "set system syslog host 172.16.0.1 facility all protocol udp", + # "set system syslog user vyos facility local7 level debug", + # "set system syslog host 172.16.0.1 port 223", + # "set system syslog global facility cron level debug", + # "set system syslog global archive file 2", + # "set system syslog global archive size 111", + # "set system syslog global marker interval 111", + # "set system syslog global preserve-fqdn" + # ], + + # After state: + # ------------ + + # vyos:~$ show configuration commands | grep syslog + # set system syslog console facility local7 level 'err' + # set system syslog file logFile archive file '2' + # set system syslog file logFile facility local6 level 'emerg' + # set system syslog global archive file '2' + # set system syslog global archive size '111' + # set system syslog global facility cron level 'debug' + # set system syslog global marker interval '111' + # set system syslog global preserve-fqdn + # set system syslog host 172.16.0.1 facility all protocol 'udp' + # set system syslog host 172.16.0.1 facility local7 level 'all' + # set system syslog host 172.16.0.1 port '223' + # set system syslog user vyos facility local7 level 'debug' + + # Using state: deleted + + # Before state: + # ------------- + + # vyos:~$show configuration commands | grep syslog + # set system syslog console facility local7 level 'err' + # set system syslog file logFile archive file '2' + # set system syslog file logFile facility local6 level 'emerg' + # set system syslog global archive file '2' + # set system syslog global archive size '111' + # set system syslog global facility cron level 'debug' + # set system syslog global marker interval '111' + # set system syslog global preserve-fqdn + # set system syslog host 172.16.0.1 facility all protocol 'udp' + # set system syslog host 172.16.0.1 facility local7 level 'all' + # set system syslog host 172.16.0.1 port '223' + # set system syslog user vyos facility local7 level 'debug' + + - name: delete the existing configuration + vyos.vyos.vyos_logging_global: + state: deleted + + # Commands Fired: + # --------------- + + # "commands": [ + # "delete system syslog" + # ], + + # After state: + # ------------ + + # vyos:~$show configuration commands | grep syslog + + # Using state: overridden + + # Before state: + # ------------- + + # vyos:~$show configuration commands | grep syslog + # set system syslog console facility local7 level 'err' + # set system syslog file logFile archive file '2' + # set system syslog file logFile facility local6 level 'emerg' + # set system syslog global archive file '2' + # set system syslog global archive size '111' + # set system syslog global facility cron level 'debug' + # set system syslog global marker interval '111' + # set system syslog global preserve-fqdn + # set system syslog host 172.16.0.1 facility all protocol 'udp' + # set system syslog host 172.16.0.1 facility local7 level 'all' + # set system syslog host 172.16.0.1 port '223' + # set system syslog user vyos facility local7 level 'debug' + + - name: Override the current configuration + vyos.vyos.vyos_logging_global: + config: + console: + facilities: + - facility: all + - facility: local7 + severity: err + - facility: news + severity: debug + files: + - path: logFileNew + hosts: + - hostname: 172.16.0.2 + facilities: + - facility: local5 + severity: all + global_params: + archive: + file_num: 10 + state: overridden + + # Commands Fired: + # --------------- + + # "commands": [ + # "delete system syslog file logFile", + # "delete system syslog global facility cron", + # "delete system syslog host 172.16.0.1", + # "delete system syslog user vyos", + # "set system syslog console facility all", + # "set system syslog console facility news level debug", + # "set system syslog file logFileNew", + # "set system syslog host 172.16.0.2 facility local5 level all", + # "set system syslog global archive file 10", + # "delete system syslog global archive size 111", + # "delete system syslog global marker", + # "delete system syslog global preserve-fqdn" + # ], + + # After state: + # ------------ + + # vyos:~$show configuration commands | grep syslog + # set system syslog console facility all + # set system syslog console facility local7 level 'err' + # set system syslog console facility news level 'debug' + # set system syslog file logFileNew + # set system syslog global archive file '10' + # set system syslog host 172.16.0.2 facility local5 level 'all' + + # Using state: replaced + + # Before state: + # ------------- + + # vyos:~$show configuration commands | grep syslog + # set system syslog console facility all + # set system syslog console facility local7 level 'err' + # set system syslog console facility news level 'debug' + # set system syslog file logFileNew + # set system syslog global archive file '10' + # set system syslog host 172.16.0.2 facility local5 level 'all' + + - name: Replace with the provided configuration + register: result + vyos.vyos.vyos_logging_global: + config: + console: + facilities: + - facility: local6 + users: + - username: paul + facilities: + - facility: local7 + severity: err + state: replaced + + # Commands Fired: + # --------------- + + # "commands": [ + # "delete system syslog console facility all", + # "delete system syslog console facility local7", + # "delete system syslog console facility news", + # "delete system syslog file logFileNew", + # "delete system syslog global archive file 10", + # "delete system syslog host 172.16.0.2", + # "set system syslog console facility local6", + # "set system syslog user paul facility local7 level err" + # ], + + # After state: + # ------------ + + # vyos:~$show configuration commands | grep syslog + # set system syslog console facility local6 + # set system syslog user paul facility local7 level 'err' + + # Using state: gathered + + - name: Gather logging config + vyos.vyos.vyos_logging_global: + state: gathered + + # Module Execution Result: + # ------------------------ + + # "gathered": { + # "console": { + # "facilities": [ + # { + # "facility": "local6" + # }, + # { + # "facility": "local7", + # "severity": "err" + # } + # ] + # }, + # "files": [ + # { + # "archive": { + # "file_num": 2 + # }, + # "facilities": [ + # { + # "facility": "local6", + # "severity": "emerg" + # } + # ], + # "path": "logFile" + # } + # ], + # "global_params": { + # "archive": { + # "file_num": 2, + # "size": 111 + # }, + # "facilities": [ + # { + # "facility": "cron", + # "severity": "debug" + # } + # ], + # "marker_interval": 111, + # "preserve_fqdn": true + # }, + # "hosts": [ + # { + # "facilities": [ + # { + # "facility": "all", + # "protocol": "udp" + # }, + # { + # "facility": "local7", + # "severity": "all" + # } + # ], + # "hostname": "172.16.0.1", + # "port": 223 + # } + # ], + # "users": [ + # { + # "facilities": [ + # { + # "facility": "local7", + # "severity": "err" + # } + # ], + # "username": "paul" + # }, + # { + # "facilities": [ + # { + # "facility": "local7", + # "severity": "debug" + # } + # ], + # "username": "vyos" + # } + # ] + # }, + + # After state: + # ------------ + + # vyos:~$show configuration commands | grep syslog + # set system syslog console facility local6 + # set system syslog console facility local7 level 'err' + # set system syslog file logFile archive file '2' + # set system syslog file logFile facility local6 level 'emerg' + # set system syslog global archive file '2' + # set system syslog global archive size '111' + # set system syslog global facility cron level 'debug' + # set system syslog global marker interval '111' + # set system syslog global preserve-fqdn + # set system syslog host 172.16.0.1 facility all protocol 'udp' + # set system syslog host 172.16.0.1 facility local7 level 'all' + # set system syslog host 172.16.0.1 port '223' + # set system syslog user paul facility local7 level 'err' + # set system syslog user vyos facility local7 level 'debug' + + # Using state: rendered + + - name: Render the provided configuration + vyos.vyos.vyos_logging_global: + config: + console: + facilities: + - facility: local7 + severity: err + files: + - path: logFile + archive: + file_num: 2 + facilities: + - facility: local6 + severity: emerg + hosts: + - hostname: 172.16.0.1 + facilities: + - facility: local7 + severity: all + - facility: all + protocol: udp + port: 223 + users: + - username: vyos + facilities: + - facility: local7 + severity: debug + global_params: + archive: + file_num: 2 + size: 111 + facilities: + - facility: cron + severity: debug + marker_interval: 111 + preserve_fqdn: true + state: rendered + + # Module Execution Result: + # ------------------------ + + # "rendered": [ + # "set system syslog console facility local7 level err", + # "set system syslog file logFile facility local6 level emerg", + # "set system syslog file logFile archive file 2", + # "set system syslog host 172.16.0.1 facility local7 level all", + # "set system syslog host 172.16.0.1 facility all protocol udp", + # "set system syslog host 172.16.0.1 port 223", + # "set system syslog user vyos facility local7 level debug", + # "set system syslog global facility cron level debug", + # "set system syslog global archive file 2", + # "set system syslog global archive size 111", + # "set system syslog global marker interval 111", + # "set system syslog global preserve-fqdn" + # ] + + # Using state: parsed + + # File: parsed.cfg + # ---------------- + + # set system syslog console facility local6 + # set system syslog console facility local7 level 'err' + # set system syslog file logFile archive file '2' + # set system syslog file logFile facility local6 level 'emerg' + # set system syslog global archive file '2' + # set system syslog global archive size '111' + # set system syslog global facility cron level 'debug' + # set system syslog global marker interval '111' + # set system syslog global preserve-fqdn + # set system syslog host 172.16.0.1 facility all protocol 'udp' + # set system syslog host 172.16.0.1 facility local7 level 'all' + # set system syslog host 172.16.0.1 port '223' + # set system syslog user paul facility local7 level 'err' + # set system syslog user vyos facility local7 level 'debug' + + - name: Parse the provided configuration + vyos.vyos.vyos_logging_global: + running_config: "{{ lookup('file', 'parsed_vyos.cfg') }}" + state: parsed + + # Module Execution Result: + # ------------------------ + + # "parsed": { + # "console": { + # "facilities": [ + # { + # "facility": "local6" + # }, + # { + # "facility": "local7", + # "severity": "err" + # } + # ] + # }, + # "files": [ + # { + # "archive": { + # "file_num": 2 + # }, + # "facilities": [ + # { + # "facility": "local6", + # "severity": "emerg" + # } + # ], + # "path": "logFile" + # } + # ], + # "global_params": { + # "archive": { + # "file_num": 2, + # "size": 111 + # }, + # "facilities": [ + # { + # "facility": "cron", + # "severity": "debug" + # } + # ], + # "marker_interval": 111, + # "preserve_fqdn": true + # }, + # "hosts": [ + # { + # "facilities": [ + # { + # "facility": "all", + # "protocol": "udp" + # }, + # { + # "facility": "local7", + # "severity": "all" + # } + # ], + # "hostname": "172.16.0.1", + # "port": 223 + # } + # ], + # "users": [ + # { + # "facilities": [ + # { + # "facility": "local7", + # "severity": "err" + # } + # ], + # "username": "paul" + # }, + # { + # "facilities": [ + # { + # "facility": "local7", + # "severity": "debug" + # } + # ], + # "username": "vyos" + # } + # ] + # } + # } + + + +Return Values +------------- +Common return values are documented `here `_, the following are the fields unique to this module: + +.. raw:: html + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
KeyReturnedDescription
+
+ after + +
+ dictionary +
+
when changed +
The resulting configuration after module execution.
+
+
Sample:
+
This output will always be in the same format as the module argspec.
+
+
+ before + +
+ dictionary +
+
when state is merged, replaced, overridden, deleted or purged +
The configuration prior to the module execution.
+
+
Sample:
+
This output will always be in the same format as the module argspec.
+
+
+ commands + +
+ list +
+
when state is merged, replaced, overridden, deleted or purged +
The set of commands pushed to the remote device.
+
+
Sample:
+
['set system syslog console facility local7 level err', 'set system syslog host 172.16.0.1 port 223', 'set system syslog global archive size 111']
+
+
+ gathered + +
+ list +
+
when state is gathered +
Facts about the network resource gathered from the remote device as structured data.
+
+
Sample:
+
This output will always be in the same format as the module argspec.
+
+
+ parsed + +
+ list +
+
when state is parsed +
The device native config provided in running_config option parsed into structured data as per module argspec.
+
+
Sample:
+
This output will always be in the same format as the module argspec.
+
+
+ rendered + +
+ list +
+
when state is rendered +
The provided configuration in the task rendered in device-native format (offline).
+
+
Sample:
+
['set system syslog host 172.16.0.1 port 223', 'set system syslog user vyos facility local7 level debug', 'set system syslog global facility cron level debug']
+
+

+ + +Status +------ + + +Authors +~~~~~~~ + +- Sagar Paul (@KB-perByte) diff --git a/docs/vyos.vyos.vyos_logging_module.rst b/docs/vyos.vyos.vyos_logging_module.rst index 9cb024d..39f885e 100644 --- a/docs/vyos.vyos.vyos_logging_module.rst +++ b/docs/vyos.vyos.vyos_logging_module.rst @@ -1,440 +1,451 @@ .. _vyos.vyos.vyos_logging_module: ********************** vyos.vyos.vyos_logging ********************** **Manage logging on network devices** Version added: 1.0.0 .. contents:: :local: :depth: 1 +DEPRECATED +---------- +:Removed in collection release after 2023-08-01 +:Why: Updated module released with more functionality. +:Alternative: vyos_logging_global + + Synopsis -------- - This module provides declarative management of logging on Vyatta Vyos devices. Parameters ---------- .. raw:: html
Parameter Choices/Defaults Comments
aggregate
list / elements=dictionary
List of logging definitions.
dest
string
    Choices:
  • console
  • file
  • global
  • host
  • user
Destination of the logs.
facility
string
Set logging facility.
level
string
Set logging severity levels.
name
string
If value of dest is file it indicates file-name, for user it indicates username and for host indicates the host name to be notified.
state
string
    Choices:
  • present
  • absent
State of the logging configuration.
dest
string
    Choices:
  • console
  • file
  • global
  • host
  • user
Destination of the logs.
facility
string
Set logging facility.
level
string
Set logging severity levels.
name
string
If value of dest is file it indicates file-name, for user it indicates username and for host indicates the host name to be notified.
provider
dictionary
Deprecated
Starting with Ansible 2.5 we recommend using connection: network_cli.
For more information please see the Network Guide.

A dict object containing connection details.
host
string
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
password
string
Specifies the password to use to authenticate the connection to the remote device. This value is used to authenticate the SSH session. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
port
integer
Specifies the port to use when building the connection to the remote device.
ssh_keyfile
path
Specifies the SSH key to use to authenticate the connection to the remote device. This value is the path to the key used to authenticate the SSH session. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
timeout
integer
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error.
username
string
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate the SSH session. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.
state
string
    Choices:
  • present ←
  • absent
State of the logging configuration.

Notes ----- .. note:: - Tested against VyOS 1.1.8 (helium). - This module works with connection ``network_cli``. See `the VyOS OS Platform Options <../network/user_guide/platform_vyos.html>`_. - For more information on using Ansible to manage network devices see the :ref:`Ansible Network Guide ` Examples -------- .. code-block:: yaml - name: configure console logging vyos.vyos.vyos_logging: dest: console facility: all level: crit - name: remove console logging configuration vyos.vyos.vyos_logging: dest: console state: absent - name: configure file logging vyos.vyos.vyos_logging: dest: file name: test facility: local3 level: err - name: Add logging aggregate vyos.vyos.vyos_logging: aggregate: - {dest: file, name: test1, facility: all, level: info} - {dest: file, name: test2, facility: news, level: debug} state: present - name: Remove logging aggregate vyos.vyos.vyos_logging: aggregate: - {dest: console, facility: all, level: info} - {dest: console, facility: daemon, level: warning} - {dest: file, name: test2, facility: news, level: debug} state: absent Return Values ------------- Common return values are documented `here `_, the following are the fields unique to this module: .. raw:: html
Key Returned Description
commands
list
always
The list of configuration mode commands to send to the device

Sample:
['set system syslog global facility all level notice']


Status ------ +- This module will be removed in version . *[deprecated]* +- For more information see `DEPRECATED`_. + + Authors ~~~~~~~ - Trishna Guha (@trishnaguha) diff --git a/meta/runtime.yml b/meta/runtime.yml index 912c896..92cb260 100644 --- a/meta/runtime.yml +++ b/meta/runtime.yml @@ -1,227 +1,240 @@ --- requires_ansible: ">=2.9.10" plugin_routing: action: vyos_banner: redirect: vyos.vyos.vyos banner: redirect: vyos.vyos.vyos vyos_bgp_global: redirect: vyos.vyos.vyos bgp_global: redirect: vyos.vyos.vyos vyos_bgp_address_family: redirect: vyos.vyos.vyos bgp_address_family: redirect: vyos.vyos.vyos vyos_command: redirect: vyos.vyos.vyos command: redirect: vyos.vyos.vyos vyos_config: redirect: vyos.vyos.vyos config: redirect: vyos.vyos.vyos vyos_facts: redirect: vyos.vyos.vyos facts: redirect: vyos.vyos.vyos vyos_firewall_global: redirect: vyos.vyos.vyos firewall_global: redirect: vyos.vyos.vyos vyos_firewall_interfaces: redirect: vyos.vyos.vyos firewall_interfaces: redirect: vyos.vyos.vyos vyos_firewall_rules: redirect: vyos.vyos.vyos firewall_rules: redirect: vyos.vyos.vyos vyos_interface: redirect: vyos.vyos.vyos interface: redirect: vyos.vyos.vyos vyos_interfaces: redirect: vyos.vyos.vyos interfaces: redirect: vyos.vyos.vyos vyos_l3_interface: redirect: vyos.vyos.vyos l3_interface: redirect: vyos.vyos.vyos vyos_l3_interfaces: redirect: vyos.vyos.vyos l3_interfaces: redirect: vyos.vyos.vyos vyos_lag_interfaces: redirect: vyos.vyos.vyos lag_interfaces: redirect: vyos.vyos.vyos vyos_linkagg: redirect: vyos.vyos.vyos linkagg: redirect: vyos.vyos.vyos vyos_lldp: redirect: vyos.vyos.vyos lldp: redirect: vyos.vyos.vyos vyos_lldp_global: redirect: vyos.vyos.vyos lldp_global: redirect: vyos.vyos.vyos vyos_lldp_interface: redirect: vyos.vyos.vyos lldp_interface: redirect: vyos.vyos.vyos vyos_lldp_interfaces: redirect: vyos.vyos.vyos lldp_interfaces: redirect: vyos.vyos.vyos vyos_logging: redirect: vyos.vyos.vyos + vyos_logging_global: + redirect: vyos.vyos.vyos + logging_global: + redirect: vyos.vyos.vyos logging: redirect: vyos.vyos.vyos vyos_ospfv2: redirect: vyos.vyos.vyos ospfv2: redirect: vyos.vyos.vyos vyos_ospfv3: redirect: vyos.vyos.vyos ospfv3: redirect: vyos.vyos.vyos vyos_ospf_interfaces: redirect: vyos.vyos.vyos ospf_interfaces: redirect: vyos.vyos.vyos vyos_ping: redirect: vyos.vyos.vyos ping: redirect: vyos.vyos.vyos vyos_prefix_lists: redirect: vyos.vyos.vyos prefix_lists: redirect: vyos.vyos.vyos vyos_static_route: redirect: vyos.vyos.vyos static_route: redirect: vyos.vyos.vyos vyos_static_routes: redirect: vyos.vyos.vyos static_routes: redirect: vyos.vyos.vyos vyos_system: redirect: vyos.vyos.vyos system: redirect: vyos.vyos.vyos vyos_user: redirect: vyos.vyos.vyos user: redirect: vyos.vyos.vyos vyos_vlan: redirect: vyos.vyos.vyos vlan: redirect: vyos.vyos.vyos modules: banner: redirect: vyos.vyos.vyos_banner bgp_global: redirect: vyos.vyos.vyos_bgp_global bgp_address_family: redirect: vyos.vyos.vyos_bgp_address_family command: redirect: vyos.vyos.vyos_command config: redirect: vyos.vyos.vyos_config facts: redirect: vyos.vyos.vyos_facts firewall_global: redirect: vyos.vyos.vyos_firewall_global firewall_interfaces: redirect: vyos.vyos.vyos_firewall_interfaces firewall_rules: redirect: vyos.vyos.vyos_firewall_rules interface: redirect: vyos.vyos.vyos_interface deprecation: removal_date: "2022-06-01" warning_text: See the plugin documentation for more details vyos_interface: deprecation: removal_date: "2022-06-01" warning_text: See the plugin documentation for more details interfaces: redirect: vyos.vyos.vyos_interfaces l3_interface: redirect: vyos.vyos.vyos_l3_interface deprecation: removal_date: "2022-06-01" warning_text: See the plugin documentation for more details vyos_l3_interface: deprecation: removal_date: "2022-06-01" warning_text: See the plugin documentation for more details l3_interfaces: redirect: vyos.vyos.vyos_l3_interfaces lag_interfaces: redirect: vyos.vyos.vyos_lag_interfaces linkagg: redirect: vyos.vyos.vyos_linkagg deprecation: removal_date: "2022-06-01" warning_text: See the plugin documentation for more details vyos_linkagg: deprecation: removal_date: "2022-06-01" warning_text: See the plugin documentation for more details lldp: redirect: vyos.vyos.vyos_lldp deprecation: removal_date: "2022-06-01" warning_text: See the plugin documentation for more details vyos_lldp: deprecation: removal_date: "2022-06-01" warning_text: See the plugin documentation for more details lldp_global: redirect: vyos.vyos.vyos_lldp_global lldp_interface: redirect: vyos.vyos.vyos_lldp_interface deprecation: removal_date: "2022-06-01" warning_text: See the plugin documentation for more details vyos_lldp_interface: deprecation: removal_date: "2022-06-01" warning_text: See the plugin documentation for more details lldp_interfaces: redirect: vyos.vyos.vyos_lldp_interfaces logging: redirect: vyos.vyos.vyos_logging + deprecation: + removal_date: '2023-08-01' + warning_text: See the plugin documentation for more details + vyos_logging: + deprecation: + removal_date: '2023-08-01' + warning_text: See the plugin documentation for more details + logging_global: + redirect: vyos.vyos.vyos_logging_global ospfv2: redirect: vyos.vyos.vyos_ospfv2 ospfv3: redirect: vyos.vyos.vyos_ospfv3 ospf_interfaces: redirect: vyos.vyos.vyos_ospf_interfaces ping: redirect: vyos.vyos.vyos_ping prefix_lists: redirect: vyos.vyos.vyos_prefix_lists static_route: redirect: vyos.vyos.vyos_static_route deprecation: removal_date: "2022-06-01" warning_text: See the plugin documentation for more details vyos_static_route: deprecation: removal_date: "2022-06-01" warning_text: See the plugin documentation for more details static_routes: redirect: vyos.vyos.vyos_static_routes system: redirect: vyos.vyos.vyos_system user: redirect: vyos.vyos.vyos_user vlan: redirect: vyos.vyos.vyos_vlan diff --git a/plugins/module_utils/network/vyos/argspec/logging_global/__init__.py b/plugins/module_utils/network/vyos/argspec/logging_global/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/plugins/module_utils/network/vyos/argspec/logging_global/logging_global.py b/plugins/module_utils/network/vyos/argspec/logging_global/logging_global.py new file mode 100644 index 0000000..503f723 --- /dev/null +++ b/plugins/module_utils/network/vyos/argspec/logging_global/logging_global.py @@ -0,0 +1,370 @@ +# -*- coding: utf-8 -*- +# Copyright 2021 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 + +############################################# +# WARNING # +############################################# +# +# This file is auto generated by the +# cli_rm_builder. +# +# Manually editing this file is not advised. +# +# To update the argspec make the desired changes +# in the module docstring and re-run +# cli_rm_builder. +# +############################################# + +""" +The arg spec for the vyos_logging_global module +""" + + +class Logging_globalArgs(object): # pylint: disable=R0903 + """The arg spec for the vyos_logging_global module""" + + argument_spec = { + "config": { + "type": "dict", + "options": { + "console": { + "type": "dict", + "options": { + "state": { + "type": "str", + "choices": ["enabled", "disabled"], + }, + "facilities": { + "type": "list", + "elements": "dict", + "options": { + "facility": { + "type": "str", + "choices": [ + "all", + "auth", + "authpriv", + "cron", + "daemon", + "kern", + "lpr", + "mail", + "mark", + "news", + "protocols", + "security", + "syslog", + "user", + "uucp", + "local0", + "local1", + "local2", + "local3", + "local4", + "local5", + "local6", + "local7", + ], + }, + "severity": { + "type": "str", + "choices": [ + "emerg", + "alert", + "crit", + "err", + "warning", + "notice", + "info", + "debug", + "all", + ], + }, + }, + }, + }, + }, + "files": { + "type": "list", + "elements": "dict", + "options": { + "path": {"type": "str"}, + "archive": { + "type": "dict", + "options": { + "state": { + "type": "str", + "choices": ["enabled", "disabled"], + }, + "file_num": {"type": "int"}, + "size": {"type": "int"}, + }, + }, + "facilities": { + "type": "list", + "elements": "dict", + "options": { + "facility": { + "type": "str", + "choices": [ + "all", + "auth", + "authpriv", + "cron", + "daemon", + "kern", + "lpr", + "mail", + "mark", + "news", + "protocols", + "security", + "syslog", + "user", + "uucp", + "local0", + "local1", + "local2", + "local3", + "local4", + "local5", + "local6", + "local7", + ], + }, + "severity": { + "type": "str", + "choices": [ + "emerg", + "alert", + "crit", + "err", + "warning", + "notice", + "info", + "debug", + "all", + ], + }, + }, + }, + }, + }, + "global_params": { + "type": "dict", + "options": { + "state": { + "type": "str", + "choices": ["enabled", "disabled"], + }, + "archive": { + "type": "dict", + "options": { + "state": { + "type": "str", + "choices": ["enabled", "disabled"], + }, + "file_num": {"type": "int"}, + "size": {"type": "int"}, + }, + }, + "facilities": { + "type": "list", + "elements": "dict", + "options": { + "facility": { + "type": "str", + "choices": [ + "all", + "auth", + "authpriv", + "cron", + "daemon", + "kern", + "lpr", + "mail", + "mark", + "news", + "protocols", + "security", + "syslog", + "user", + "uucp", + "local0", + "local1", + "local2", + "local3", + "local4", + "local5", + "local6", + "local7", + ], + }, + "severity": { + "type": "str", + "choices": [ + "emerg", + "alert", + "crit", + "err", + "warning", + "notice", + "info", + "debug", + "all", + ], + }, + }, + }, + "marker_interval": {"type": "int"}, + "preserve_fqdn": {"type": "bool"}, + }, + }, + "hosts": { + "type": "list", + "elements": "dict", + "options": { + "port": {"type": "int"}, + "facilities": { + "type": "list", + "elements": "dict", + "options": { + "facility": { + "type": "str", + "choices": [ + "all", + "auth", + "authpriv", + "cron", + "daemon", + "kern", + "lpr", + "mail", + "mark", + "news", + "protocols", + "security", + "syslog", + "user", + "uucp", + "local0", + "local1", + "local2", + "local3", + "local4", + "local5", + "local6", + "local7", + ], + }, + "severity": { + "type": "str", + "choices": [ + "emerg", + "alert", + "crit", + "err", + "warning", + "notice", + "info", + "debug", + "all", + ], + }, + "protocol": { + "type": "str", + "choices": ["udp", "tcp"], + }, + }, + }, + "hostname": {"type": "str"}, + }, + }, + "syslog": { + "type": "dict", + "options": { + "state": { + "type": "str", + "choices": ["enabled", "disabled"], + } + }, + }, + "users": { + "type": "list", + "elements": "dict", + "options": { + "username": {"type": "str"}, + "facilities": { + "type": "list", + "elements": "dict", + "options": { + "facility": { + "type": "str", + "choices": [ + "all", + "auth", + "authpriv", + "cron", + "daemon", + "kern", + "lpr", + "mail", + "mark", + "news", + "protocols", + "security", + "syslog", + "user", + "uucp", + "local0", + "local1", + "local2", + "local3", + "local4", + "local5", + "local6", + "local7", + ], + }, + "severity": { + "type": "str", + "choices": [ + "emerg", + "alert", + "crit", + "err", + "warning", + "notice", + "info", + "debug", + "all", + ], + }, + }, + }, + }, + }, + }, + }, + "running_config": {"type": "str"}, + "state": { + "choices": [ + "merged", + "replaced", + "overridden", + "deleted", + "gathered", + "parsed", + "rendered", + ], + "default": "merged", + "type": "str", + }, + } # pylint: disable=C0301 diff --git a/plugins/module_utils/network/vyos/config/logging_global/__init__.py b/plugins/module_utils/network/vyos/config/logging_global/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/plugins/module_utils/network/vyos/config/logging_global/logging_global.py b/plugins/module_utils/network/vyos/config/logging_global/logging_global.py new file mode 100644 index 0000000..696090d --- /dev/null +++ b/plugins/module_utils/network/vyos/config/logging_global/logging_global.py @@ -0,0 +1,237 @@ +# +# -*- coding: utf-8 -*- +# Copyright 2021 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 + +""" +The vyos_logging_global config file. +It is in this file where the current configuration (as dict) +is compared to the provided configuration (as dict) and the command set +necessary to bring the current configuration to its desired end-state is +created. +""" + +from copy import deepcopy + +from ansible.module_utils.six import iteritems +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( + dict_merge, + get_from_dict, +) +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module import ( + ResourceModule, +) +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import ( + Facts, +) +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.logging_global import ( + Logging_globalTemplate, +) + + +class Logging_global(ResourceModule): + """ + The vyos_logging_global config class + """ + + def __init__(self, module): + super(Logging_global, self).__init__( + empty_fact_val={}, + facts_module=Facts(module), + module=module, + resource="logging_global", + tmplt=Logging_globalTemplate(), + ) + self.parsers = [ + "console.facilities", + "global_params.archive.file_num", + "global_params.archive.size", + "global_params.marker_interval", + "global_params.preserve_fqdn", + "global_params.facilities", + "files.archive.size", + "files.archive.file_num", + "files", + "hosts.port", + "hosts", + "users", + ] + + def execute_module(self): + """Execute the module + + :rtype: A dictionary + :returns: The result from module execution + """ + if self.state not in ["parsed", "gathered"]: + self.generate_commands() + self.run_commands() + return self.result + + def generate_commands(self): + """Generate configuration commands to send based on + want, have and desired state. + """ + if self.want: + wantd = self.list_to_dict(self.want, "want") + else: + wantd = dict() + if self.have: + haved = self.list_to_dict(self.have, "have") + else: + haved = dict() + + if self.state in ["overridden", "replaced"]: + if wantd != haved: + wantx, havex = self.call_op(wantd, haved, "overridden") + for k, have in iteritems(havex): + if k not in wantx: + self._compare(want={}, have=have) + + if not self.state == "deleted": + wantd, haved = self.call_op(wantd, haved) + + if self.state == "merged": + wantd = dict_merge(haved, wantd) + + for k, want in iteritems(wantd): + self._compare(want=want, have=haved.pop(k, {})) + + def _compare(self, want, have): + """Leverages the base class `compare()` method and + populates the list of commands to be run by comparing + the `want` and `have` data with the `parsers` defined + for the Logging_global network resource. + """ + self.compare(parsers=self.parsers, want=want, have=have) + self.handleStates(want=want, have=have) + + def operation_rep(self, params): + op_val = dict() + for k, val in iteritems(params): + if k in ["console", "global_params"]: + mod_val = deepcopy(val) + op_val.update(self.flatten_facility({k: mod_val})) + elif k in ["files", "hosts", "users"]: + for m, n in iteritems(val): + mod_n = deepcopy(n) + if mod_n.get("archive"): + del mod_n["archive"] + if mod_n.get("facilities"): + del mod_n["facilities"] + if mod_n.get("port"): + del mod_n["port"] + tm = self.flatten_facility({k: {m: mod_n}}) + op_val.update(tm) + return op_val + + def call_op(self, _want, _have, mode=None): + if mode == "overridden": + w = self.operation_rep(_want) + h = self.operation_rep(_have) + else: + w = self.flatten_facility(_want) + h = self.flatten_facility(_have) + return w, h + + def handleStates(self, want=None, have=None): + stateparsers = [ + "syslog.state", + "console.state", + "global_params.state", + "global_params.archive.state", + "files.archive.state", + ] + for par in stateparsers: + op = get_from_dict(want, par) + if op == "enabled": + self.addcmd(want, par) + elif op == "disabled": + self.addcmd(want, par, True) + break + + def flatten_facility(self, param): + temp_param = dict() + for element, val in iteritems(param): + if element in ["console", "global_params", "syslog"]: + if element != "syslog" and val.get("facilities"): + for k, v in iteritems(val.get("facilities")): + temp_param[k + element] = {element: {"facilities": v}} + del val["facilities"] + if val: + temp_param[element] = {element: val} + if element in ["files", "hosts", "users"]: + for k, v in iteritems(val): + if v.get("facilities"): + for pk, dat in iteritems(v.get("facilities")): + temp_param[pk + k] = { + element: { + "facilities": dat, + self.pkey.get(element): v.get( + self.pkey.get(element) + ), + } + } + del v["facilities"] + if len(list(v.keys())) > 1: + temp_param[k] = {element: v} + else: + temp_param[k] = {element: v} + return temp_param + + def list_to_dict(self, param, op=None): + updated_param = dict() + if self.state == "deleted": + if op == "have" and param: + self.handleStates({"syslog": {"state": "disabled"}}) + updated_param == {} + else: + self.pkey = { + "files": "path", + "hosts": "hostname", + "users": "username", + } + for element, val in iteritems(param): + if element == "facilities": # only with recursion call + _tem_par = {} + for par in val: + if par.get("facility") and par.get("severity"): + _tem_par.update( + { + par.get("facility") + + par.get("severity"): par + } + ) + elif par.get("facility") and par.get("protocol"): + _tem_par.update( + { + par.get("facility") + + par.get("protocol"): par + } + ) + else: + _tem_par.update({par.get("facility"): par}) + return _tem_par + elif element in ["console", "global_params", "syslog"]: + if element != "syslog" and val.get("facilities"): + val["facilities"] = self.list_to_dict(val) + updated_param[element] = val + elif element in ["hosts", "users", "files"]: + for v in val: + if v.get("facilities"): + v["facilities"] = self.list_to_dict(v) + if updated_param.get(element): + updated_param[element].update( + {v.get(self.pkey.get(element)): v} + ) + else: + updated_param[element] = { + v.get(self.pkey.get(element)): v + } + return updated_param diff --git a/plugins/module_utils/network/vyos/facts/facts.py b/plugins/module_utils/network/vyos/facts/facts.py index 90ee03c..ab074b0 100644 --- a/plugins/module_utils/network/vyos/facts/facts.py +++ b/plugins/module_utils/network/vyos/facts/facts.py @@ -1,119 +1,123 @@ # Copyright 2019 Red Hat # GNU General Public License v3.0+ # (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) """ The facts class for vyos this file validates each subset of facts and selectively calls the appropriate facts gathering function """ from __future__ import absolute_import, division, print_function __metaclass__ = type from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.facts.facts import ( FactsBase, ) from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.interfaces.interfaces import ( InterfacesFacts, ) from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.l3_interfaces.l3_interfaces import ( L3_interfacesFacts, ) from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.lag_interfaces.lag_interfaces import ( Lag_interfacesFacts, ) from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.lldp_global.lldp_global import ( Lldp_globalFacts, ) from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.lldp_interfaces.lldp_interfaces import ( Lldp_interfacesFacts, ) from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.firewall_rules.firewall_rules import ( Firewall_rulesFacts, ) from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.static_routes.static_routes import ( Static_routesFacts, ) from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.firewall_global.firewall_global import ( Firewall_globalFacts, ) from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.firewall_interfaces.firewall_interfaces import ( Firewall_interfacesFacts, ) from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.ospfv3.ospfv3 import ( Ospfv3Facts, ) from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.ospfv2.ospfv2 import ( Ospfv2Facts, ) from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.ospf_interfaces.ospf_interfaces import ( Ospf_interfacesFacts, ) from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.bgp_global.bgp_global import ( Bgp_globalFacts, ) from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.bgp_address_family.bgp_address_family import ( Bgp_address_familyFacts, ) from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.route_maps.route_maps import ( Route_mapsFacts, ) from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.prefix_lists.prefix_lists import ( Prefix_listsFacts, ) +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.logging_global.logging_global import ( + Logging_globalFacts, +) from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.legacy.base import ( Default, Neighbors, Config, ) FACT_LEGACY_SUBSETS = dict(default=Default, neighbors=Neighbors, config=Config) FACT_RESOURCE_SUBSETS = dict( interfaces=InterfacesFacts, l3_interfaces=L3_interfacesFacts, lag_interfaces=Lag_interfacesFacts, lldp_global=Lldp_globalFacts, lldp_interfaces=Lldp_interfacesFacts, static_routes=Static_routesFacts, firewall_rules=Firewall_rulesFacts, firewall_global=Firewall_globalFacts, firewall_interfaces=Firewall_interfacesFacts, ospfv3=Ospfv3Facts, ospfv2=Ospfv2Facts, ospf_interfaces=Ospf_interfacesFacts, bgp_global=Bgp_globalFacts, bgp_address_family=Bgp_address_familyFacts, route_maps=Route_mapsFacts, prefix_lists=Prefix_listsFacts, + logging_global=Logging_globalFacts, ) class Facts(FactsBase): """The fact class for vyos""" VALID_LEGACY_GATHER_SUBSETS = frozenset(FACT_LEGACY_SUBSETS.keys()) VALID_RESOURCE_SUBSETS = frozenset(FACT_RESOURCE_SUBSETS.keys()) def __init__(self, module): super(Facts, self).__init__(module) def get_facts( self, legacy_facts_type=None, resource_facts_type=None, data=None ): """Collect the facts for vyos :param legacy_facts_type: List of legacy facts types :param resource_facts_type: List of resource fact types :param data: previously collected conf :rtype: dict :return: the facts gathered """ if self.VALID_RESOURCE_SUBSETS: self.get_network_resources_facts( FACT_RESOURCE_SUBSETS, resource_facts_type, data ) if self.VALID_LEGACY_GATHER_SUBSETS: self.get_network_legacy_facts( FACT_LEGACY_SUBSETS, legacy_facts_type ) return self.ansible_facts, self._warnings diff --git a/plugins/module_utils/network/vyos/facts/logging_global/__init__.py b/plugins/module_utils/network/vyos/facts/logging_global/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/plugins/module_utils/network/vyos/facts/logging_global/logging_global.py b/plugins/module_utils/network/vyos/facts/logging_global/logging_global.py new file mode 100644 index 0000000..5f9d65d --- /dev/null +++ b/plugins/module_utils/network/vyos/facts/logging_global/logging_global.py @@ -0,0 +1,107 @@ +# -*- coding: utf-8 -*- +# Copyright 2021 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 + +""" +The vyos logging_global fact class +It is in this file the configuration is collected from the device +for a given resource, parsed, and the facts tree is populated +based on the configuration. +""" + +from ansible.module_utils.six import iteritems +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import ( + utils, +) +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.logging_global import ( + Logging_globalTemplate, +) +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.logging_global.logging_global import ( + Logging_globalArgs, +) + + +class Logging_globalFacts(object): + """The vyos logging_global facts class""" + + def __init__(self, module, subspec="config", options="options"): + self._module = module + self.argument_spec = Logging_globalArgs.argument_spec + + def get_logging_data(self, connection): + return connection.get("show configuration commands | grep syslog") + + def process_facts(self, objFinal): + if objFinal: + for ke, vl in iteritems(objFinal): + if ke == "files": + _files = [] + for k, v in vl.items(): + _files.append(v) + objFinal[ke] = _files + objFinal[ke] = sorted( + objFinal[ke], key=lambda item: item["path"] + ) + elif ke == "hosts": + _hosts = [] + for k, v in vl.items(): + _hosts.append(v) + objFinal[ke] = _hosts + objFinal[ke] = sorted( + objFinal[ke], key=lambda item: item["hostname"] + ) + elif ke == "users": + _users = [] + for k, v in vl.items(): + _users.append(v) + objFinal[ke] = _users + objFinal[ke] = sorted( + objFinal[ke], key=lambda item: item["username"] + ) + elif ke == "console" or ke == "global_params": + if objFinal[ke].get("facilities"): + objFinal[ke]["facilities"] = sorted( + objFinal[ke]["facilities"], + key=lambda item: item["facility"], + ) + return objFinal + + def populate_facts(self, connection, ansible_facts, data=None): + """Populate the facts for Logging_global network resource + + :param connection: the device connection + :param ansible_facts: Facts dictionary + :param data: previously collected conf + + :rtype: dictionary + :returns: facts + """ + facts = {} + objs = [] + + if not data: + data = self.get_logging_data(connection) + + # parse native config using the Logging_global template + logging_global_parser = Logging_globalTemplate( + lines=data.splitlines(), module=self._module + ) + objs = logging_global_parser.parse() + ansible_facts["ansible_network_resources"].pop("logging_global", None) + objs = self.process_facts(objs) + + params = utils.remove_empties( + logging_global_parser.validate_config( + self.argument_spec, {"config": objs}, redact=True + ) + ) + + facts["logging_global"] = params.get("config", {}) + ansible_facts["ansible_network_resources"].update(facts) + + return ansible_facts diff --git a/plugins/module_utils/network/vyos/rm_templates/logging_global.py b/plugins/module_utils/network/vyos/rm_templates/logging_global.py new file mode 100644 index 0000000..8cfe7a6 --- /dev/null +++ b/plugins/module_utils/network/vyos/rm_templates/logging_global.py @@ -0,0 +1,388 @@ +# -*- coding: utf-8 -*- +# Copyright 2021 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 + +""" +The Logging_global parser templates file. This contains +a list of parser definitions and associated functions that +facilitates both facts gathering and native command generation for +the given network resource. +""" + +import re +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.network_template import ( + NetworkTemplate, +) + + +def tmplt_params(config_data): + def templt_common(val, tmplt): + if val.get("facility"): + tmplt += " facility {facility}".format(facility=val["facility"]) + if val.get("severity"): + tmplt += " level {level}".format(level=val["severity"]) + if val.get("protocol"): + tmplt += " protocol {protocol}".format(protocol=val["protocol"]) + return tmplt + + tmplt = "" + if config_data.get("global_params"): + val = config_data.get("global_params") + if not val.get("archive"): + tmplt += "system syslog global" + tmplt = templt_common(val.get("facilities"), tmplt) + elif config_data.get("console"): + val = config_data.get("console") + tmplt += "system syslog console" + tmplt = templt_common(val.get("facilities"), tmplt) + elif config_data.get("users"): + val = config_data.get("users") + if val.get("username") and not val.get("archive"): + tmplt += "system syslog user {username}".format( + username=val["username"] + ) + if val.get("facilities"): + tmplt = templt_common(val.get("facilities"), tmplt) + elif config_data.get("hosts"): + val = config_data.get("hosts") + if ( + val.get("hostname") + and not val.get("archive") + and not val.get("port") + ): + tmplt += "system syslog host {hostname}".format( + hostname=val["hostname"] + ) + if val.get("facilities"): + tmplt = templt_common(val.get("facilities"), tmplt) + elif config_data.get("files"): + val = config_data.get("files") + if val.get("path") and not val.get("archive"): + tmplt += "system syslog file {path}".format(path=val["path"]) + if val.get("facilities"): + tmplt = templt_common(val.get("facilities"), tmplt) + return tmplt + + +class Logging_globalTemplate(NetworkTemplate): + def __init__(self, lines=None, module=None): + prefix = {"set": "set", "remove": "delete"} + super(Logging_globalTemplate, self).__init__( + lines=lines, tmplt=self, prefix=prefix, module=module + ) + + # fmt: off + PARSERS = [ + { + "name": "syslog.state", + "getval": re.compile( + r""" + ^set\ssystem + (\s(?Psyslog)) + $""", re.VERBOSE), + "setval": "system syslog", + "result": { + "syslog": { + "state": "{{ 'enabled' if syslog is defined else 'disabled' }}", + } + } + }, + { + "name": "console.facilities", + "getval": re.compile( + r""" + ^set\ssystem\ssyslog\sconsole\sfacility + (\s(?Pall|auth|authpriv|cron|daemon|kern|lpr|mail|mark|news|protocols|security|syslog|user|uucp|local[0-7]))? + (\slevel\s(?P'(emerg|alert|crit|err|warning|notice|info|debug|all)'))? + $""", re.VERBOSE), + "setval": tmplt_params, + "remval": "system syslog console facility {{ console.facilities.facility }}", + "result": { + "console": { + "facilities": [{ + "facility": "{{ facility }}", + "severity": "{{ level }}", + }, ] + } + } + }, + { + "name": "console.state", + "getval": re.compile( + r""" + ^set\ssystem\ssyslog + (\s(?Pconsole)) + $""", re.VERBOSE), + "setval": "system syslog console", + "result": { + "console": { + "state": "{{ 'enabled' if console is defined else 'disabled' }}", + } + } + }, + { + "name": "files.archive.state", + "getval": re.compile( + r""" + ^set\ssystem\ssyslog\sfile + (\s(?P\S+))? + (\s(?Parchive)) + $""", re.VERBOSE), + "setval": "system syslog file {{ files.path }} archive", + "result": { + "files": { + "{{ path }}": { + "path": "{{ path }}", + "archive": { + "state": "{{ 'enabled' if archive is defined else 'disabled' }}", + }, + }, + } + } + }, + { + "name": "files.archive.size", + "getval": re.compile( + r""" + ^set\ssystem\ssyslog\sfile + (\s(?P\S+))? + (\sarchive\ssize\s(?P'(\d+)'))? + $""", re.VERBOSE), + "setval": "system syslog file {{ files.path }} archive size {{ files.archive.size }}", + "result": { + "files": { + "{{ path }}": { + "path": "{{ path }}", + "archive": { + "size": "{{ size }}", + }, + }, + } + } + }, + { + "name": "files.archive.file_num", + "getval": re.compile( + r""" + ^set\ssystem\ssyslog\sfile + (\s(?P\S+))? + (\sarchive\sfile\s(?P'(\d+)'))? + $""", re.VERBOSE), + "setval": "system syslog file {{ files.path }} archive file {{ files.archive.file_num }}", + "result": { + "files": { + "{{ path }}": { + "path": "{{ path }}", + "archive": { + "file_num": "{{ file_num }}", + }, + }, + } + } + }, + { + "name": "files", + "getval": re.compile( + r""" + ^set\ssystem\ssyslog\sfile + (\s(?P\S+))? + (\sfacility\s(?Pall|auth|authpriv|cron|daemon|kern|lpr|mail|mark|news|protocols|security|syslog|user|uucp|local[0-7]))? + (\slevel\s(?P'(emerg|alert|crit|err|warning|notice|info|debug|all)'))? + $""", re.VERBOSE), + "setval": tmplt_params, + "remval": "system syslog file{{ (' ' + files.path) if files.path|d('') is defined else '' }}", + "result": { + "files": { + "{{ path }}": { + "path": "{{ path }}", + "facilities": [{ + "facility": "{{ facility }}", + "severity": "{{ level }}", + }, ] + }, + } + } + }, + { + "name": "global_params.state", + "getval": re.compile( + r""" + ^set\ssystem\ssyslog + (\s(?Pglobal)) + $""", re.VERBOSE), + "setval": "system syslog global", + "result": { + "global_params": { + "state": "{{ 'enabled' if global is defined else 'disabled' }}", + } + } + }, + { + "name": "global_params.archive.state", + "getval": re.compile( + r""" + ^set\ssystem\ssyslog\sglobal + (\s(?Parchive)) + $""", re.VERBOSE), + "setval": "system syslog global archive", + "result": { + "global_params": { + "archive": { + "state": "{{ 'enabled' if archive is defined else 'disabled' }}", + }, + } + } + }, + { + "name": "global_params.archive.file_num", + "getval": re.compile( + r""" + ^set\ssystem\ssyslog\sglobal\sarchive\sfile + (\s(?P'(\d+)'))? + $""", re.VERBOSE), + "setval": "system syslog global archive file {{ global_params.archive.file_num }}", + "result": { + "global_params": { + "archive": { + "file_num": "{{ file_num }}", + }, + } + } + }, + { + "name": "global_params.archive.size", + "getval": re.compile( + r""" + ^set\ssystem\ssyslog\sglobal\sarchive\ssize + (\s(?P'(\d+)'))? + $""", re.VERBOSE), + "setval": "system syslog global archive size {{ global_params.archive.size }}", + "result": { + "global_params": { + "archive": { + "size": "{{ size }}", + }, + } + } + }, + { + "name": "global_params.marker_interval", + "getval": re.compile( + r""" + ^set\ssystem\ssyslog\sglobal\smarker\sinterval + (\s(?P'(\d+)'))? + $""", re.VERBOSE), + "setval": "system syslog global marker interval {{ global_params.marker_interval }}", + "remval": "system syslog global marker", + "result": { + "global_params": { + "marker_interval": "{{ marker_interval }}", + } + } + }, + { + "name": "global_params.preserve_fqdn", + "getval": re.compile( + r""" + ^set\ssystem\ssyslog\sglobal + (\s(?Ppreserve-fqdn)) + $""", re.VERBOSE), + "setval": "system syslog global preserve-fqdn", + "result": { + "global_params": { + "preserve_fqdn": "{{ True if preserve_fqdn is defined }}", + } + } + }, + { + "name": "global_params.facilities", + "getval": re.compile( + r""" + ^set\ssystem\ssyslog\sglobal\sfacility + (\s(?Pall|auth|authpriv|cron|daemon|kern|lpr|mail|mark|news|protocols|security|syslog|user|uucp|local[0-7]))? + (\slevel\s(?P'(emerg|alert|crit|err|warning|notice|info|debug|all)'))? + $""", re.VERBOSE), + "setval": tmplt_params, + "remval": "system syslog global facility {{ global_params.facilities.facility }}", + "result": { + "global_params": { + "facilities": [{ + "facility": "{{ facility }}", + "severity": "{{ level }}", + }, ], + } + } + }, + { + "name": "hosts.port", + "getval": re.compile( + r""" + ^set\ssystem\ssyslog\shost + (\s(?P\S+)) + (\sport\s(?P'(\d+)')) + $""", re.VERBOSE), + "setval": "system syslog host {{ hosts.hostname }} port {{ hosts.port }}", + "result": { + "hosts": { + "{{ hostname }}": { + "hostname": "{{ hostname }}", + "port": "{{ port }}", + }, + } + } + }, + { + "name": "hosts", + "getval": re.compile( + r""" + ^set\ssystem\ssyslog\shost + (\s(?P\S+)) + (\sfacility\s(?Pall|auth|authpriv|cron|daemon|kern|lpr|mail|mark|news|protocols|security|syslog|user|uucp|local[0-7])) + (\slevel\s(?P'(emerg|alert|crit|err|warning|notice|info|debug|all)'))? + (\sprotocol\s(?P'(udp|tcp)'))? + $""", re.VERBOSE), + "setval": tmplt_params, + "remval": "system syslog host {{ hosts.hostname }}", + "result": { + "hosts": { + "{{ hostname }}": { + "hostname": "{{ hostname }}", + "facilities": [{ + "facility": "{{ facility }}", + "severity": "{{ level }}", + "protocol": "{{ protocol }}", + }, ] + }, + } + } + }, + { + "name": "users", + "getval": re.compile( + r""" + ^set\ssystem\ssyslog\suser + (\s(?P\S+))? + (\sfacility\s(?Pall|auth|authpriv|cron|daemon|kern|lpr|mail|mark|news|protocols|security|syslog|user|uucp|local[0-7]))? + (\slevel\s(?P'(emerg|alert|crit|err|warning|notice|info|debug|all)'))? + $""", re.VERBOSE), + "setval": tmplt_params, + "remval": "system syslog user {{ users.username }}", + "result": { + "users": { + "{{ username }}": { + "username": "{{ username }}", + "facilities": [{ + "facility": "{{ facility }}", + "severity": "{{ level }}", + }, ] + } + } + } + }, + ] + # fmt: on diff --git a/plugins/modules/vyos_logging.py b/plugins/modules/vyos_logging.py index d4f0cfc..44238f4 100644 --- a/plugins/modules/vyos_logging.py +++ b/plugins/modules/vyos_logging.py @@ -1,342 +1,346 @@ #!/usr/bin/python # -*- coding: utf-8 -*- from __future__ import absolute_import, division, print_function __metaclass__ = type # (c) 2017, Ansible by Red Hat, inc # # This file is part of Ansible by Red Hat # # 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 . # DOCUMENTATION = """ module: vyos_logging author: Trishna Guha (@trishnaguha) short_description: Manage logging on network devices description: - This module provides declarative management of logging on Vyatta Vyos devices. version_added: 1.0.0 +deprecated: + alternative: vyos_logging_global + why: Updated module released with more functionality. + removed_at_date: '2023-08-01' notes: - Tested against VyOS 1.1.8 (helium). - This module works with connection C(network_cli). See L(the VyOS OS Platform Options,../network/user_guide/platform_vyos.html). options: dest: description: - Destination of the logs. type: str choices: - console - file - global - host - user name: description: - If value of C(dest) is I(file) it indicates file-name, for I(user) it indicates username and for I(host) indicates the host name to be notified. type: str facility: description: - Set logging facility. type: str level: description: - Set logging severity levels. type: str aggregate: description: List of logging definitions. type: list elements: dict suboptions: dest: description: - Destination of the logs. type: str choices: - console - file - global - host - user name: description: - If value of C(dest) is I(file) it indicates file-name, for I(user) it indicates username and for I(host) indicates the host name to be notified. type: str facility: description: - Set logging facility. type: str level: description: - Set logging severity levels. type: str state: description: - State of the logging configuration. type: str choices: - present - absent state: description: - State of the logging configuration. type: str default: present choices: - present - absent extends_documentation_fragment: - vyos.vyos.vyos """ EXAMPLES = """ - name: configure console logging vyos.vyos.vyos_logging: dest: console facility: all level: crit - name: remove console logging configuration vyos.vyos.vyos_logging: dest: console state: absent - name: configure file logging vyos.vyos.vyos_logging: dest: file name: test facility: local3 level: err - name: Add logging aggregate vyos.vyos.vyos_logging: aggregate: - {dest: file, name: test1, facility: all, level: info} - {dest: file, name: test2, facility: news, level: debug} state: present - name: Remove logging aggregate vyos.vyos.vyos_logging: aggregate: - {dest: console, facility: all, level: info} - {dest: console, facility: daemon, level: warning} - {dest: file, name: test2, facility: news, level: debug} state: absent """ RETURN = """ commands: description: The list of configuration mode commands to send to the device returned: always type: list sample: - set system syslog global facility all level notice """ import re from copy import deepcopy from ansible.module_utils._text import to_text from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.common.validation import check_required_if from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( remove_default_spec, ) from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import ( get_config, load_config, ) from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import ( vyos_argument_spec, ) def spec_to_commands(updates, module): commands = list() want, have = updates for w in want: dest = w["dest"] name = w["name"] facility = w["facility"] level = w["level"] state = w["state"] del w["state"] if state == "absent" and w in have: if w["name"]: commands.append( "delete system syslog {0} {1} facility {2} level {3}".format( dest, name, facility, level ) ) else: commands.append( "delete system syslog {0} facility {1} level {2}".format( dest, facility, level ) ) elif state == "present" and w not in have: if w["name"]: commands.append( "set system syslog {0} {1} facility {2} level {3}".format( dest, name, facility, level ) ) else: commands.append( "set system syslog {0} facility {1} level {2}".format( dest, facility, level ) ) return commands def config_to_dict(module): data = get_config(module) obj = [] for line in data.split("\n"): if line.startswith("set system syslog"): match = re.search(r"set system syslog (\S+)", line, re.M) dest = match.group(1) if dest == "host": match = re.search(r"host (\S+)", line, re.M) name = match.group(1) elif dest == "file": match = re.search(r"file (\S+)", line, re.M) name = match.group(1) elif dest == "user": match = re.search(r"user (\S+)", line, re.M) name = match.group(1) else: name = None if "facility" in line: match = re.search(r"facility (\S+)", line, re.M) facility = match.group(1) if "level" in line: match = re.search(r"level (\S+)", line, re.M) level = match.group(1).strip("'") obj.append( { "dest": dest, "name": name, "facility": facility, "level": level, } ) return obj def map_params_to_obj(module, required_if=None): obj = [] aggregate = module.params.get("aggregate") if aggregate: for item in aggregate: for key in item: if item.get(key) is None: item[key] = module.params[key] try: check_required_if(required_if, item) except TypeError as exc: module.fail_json(to_text(exc)) obj.append(item.copy()) else: if module.params["dest"] not in ("host", "file", "user"): module.params["name"] = None obj.append( { "dest": module.params["dest"], "name": module.params["name"], "facility": module.params["facility"], "level": module.params["level"], "state": module.params["state"], } ) return obj def main(): """main entry point for module execution""" element_spec = dict( dest=dict( type="str", choices=["console", "file", "global", "host", "user"] ), name=dict(type="str"), facility=dict(type="str"), level=dict(type="str"), state=dict(default="present", choices=["present", "absent"]), ) aggregate_spec = deepcopy(element_spec) # remove default in aggregate spec, to handle common arguments remove_default_spec(aggregate_spec) argument_spec = dict( aggregate=dict(type="list", elements="dict", options=aggregate_spec) ) argument_spec.update(element_spec) argument_spec.update(vyos_argument_spec) required_if = [ ("dest", "host", ["name", "facility", "level"]), ("dest", "file", ["name", "facility", "level"]), ("dest", "user", ["name", "facility", "level"]), ("dest", "console", ["facility", "level"]), ("dest", "global", ["facility", "level"]), ] module = AnsibleModule( argument_spec=argument_spec, required_if=required_if, supports_check_mode=True, ) warnings = list() result = {"changed": False} if warnings: result["warnings"] = warnings want = map_params_to_obj(module, required_if=required_if) have = config_to_dict(module) commands = spec_to_commands((want, have), module) result["commands"] = commands if commands: commit = not module.check_mode load_config(module, commands, commit=commit) result["changed"] = True module.exit_json(**result) if __name__ == "__main__": main() diff --git a/plugins/modules/vyos_logging_global.py b/plugins/modules/vyos_logging_global.py new file mode 100644 index 0000000..6a4e2dd --- /dev/null +++ b/plugins/modules/vyos_logging_global.py @@ -0,0 +1,776 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# Copyright 2021 Red Hat +# GNU General Public License v3.0+ +# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +""" +The module file for vyos_logging_global +""" + +from __future__ import absolute_import, division, print_function + +__metaclass__ = type + +DOCUMENTATION = """ +module: vyos_logging_global +version_added: 2.4.0 +short_description: Logging resource module +description: This module manages the logging attributes of Vyos network devices +author: Sagar Paul (@KB-perByte) +notes: + - Tested against vyos 1.2 + - This module works with connection C(network_cli). + - The Configuration defaults of the Vyos network devices + are supposed to hinder idempotent behavior of plays +options: + config: + description: A list containing dictionary of logging options + type: dict + suboptions: + console: + description: logging to serial console + type: dict + suboptions: + state: &state_config + description: enable or disable the command + type: str + choices: + - enabled + - disabled + facilities: + description: facility configurations for console + type: list + elements: dict + suboptions: + facility: &facility + description: Facility for logging + type: str + choices: + - all + - auth + - authpriv + - cron + - daemon + - kern + - lpr + - mail + - mark + - news + - protocols + - security + - syslog + - user + - uucp + - local0 + - local1 + - local2 + - local3 + - local4 + - local5 + - local6 + - local7 + severity: &severity + description: logging level + type: str + choices: + - emerg + - alert + - crit + - err + - warning + - notice + - info + - debug + - all + files: + description: logging to file + type: list + elements: dict + suboptions: + path: + description: file name or path + type: str + archive: &archive + description: Log file size and rotation characteristics + type: dict + suboptions: + state: *state_config + file_num: + description: Number of saved files (default is 5) + type: int + size: + description: Size of log files (in kilobytes, default is 256) + type: int + facilities: ¶ms + description: facility configurations + type: list + elements: dict + suboptions: + facility: *facility + severity: *severity + global_params: + description: logging to serial console + type: dict + suboptions: + state: *state_config + archive: *archive + facilities: *params + marker_interval: + description: time interval how often a mark message is being sent in seconds (default is 1200) + type: int + preserve_fqdn: + description: uses FQDN for logging + type: bool + hosts: + description: logging to serial console + type: list + elements: dict + suboptions: + port: + description: Destination port (1-65535) + type: int + facilities: + description: facility configurations for host + type: list + elements: dict + suboptions: + facility: *facility + severity: *severity + protocol: + description: syslog communication protocol + type: str + choices: + - udp + - tcp + hostname: + description: Remote host name or IP address + type: str + syslog: + description: logging syslog + type: dict + suboptions: + state: *state_config + users: + description: logging to file + type: list + elements: dict + suboptions: + username: + description: user login name + type: str + facilities: *params + running_config: + description: + - This option is used only with state I(parsed). + - The value of this option should be the output received from the VYOS device by + executing the command B(show configuration commands | grep syslog). + - The state I(parsed) reads the configuration from C(running_config) option and + transforms it into Ansible structured data as per the resource module's argspec + and the value is then returned in the I(parsed) key within the result. + type: str + state: + choices: + - merged + - replaced + - overridden + - deleted + - gathered + - parsed + - rendered + default: merged + description: + - The state the configuration should be left in + - The states I(replaced) and I(overridden) have identical + behaviour for this module. + - Refer to examples for more details. + type: str +""" + +EXAMPLES = """ +# Using state: merged + +# Before state: +# ------------- + +# vyos:~$show configuration commands | grep syslog + +- name: Apply the provided configuration + vyos.vyos.vyos_logging_global: + config: + console: + facilities: + - facility: local7 + severity: err + files: + - path: logFile + archive: + file_num: 2 + facilities: + - facility: local6 + severity: emerg + hosts: + - hostname: 172.16.0.1 + facilities: + - facility: local7 + severity: all + - facility: all + protocol: udp + port: 223 + users: + - username: vyos + facilities: + - facility: local7 + severity: debug + global_params: + archive: + file_num: 2 + size: 111 + facilities: + - facility: cron + severity: debug + marker_interval: 111 + preserve_fqdn: true + state: merged + +# Commands Fired: +# --------------- + +# "commands": [ +# "set system syslog console facility local7 level err", +# "set system syslog file logFile archive file 2", +# "set system syslog host 172.16.0.1 facility local7 level all", +# "set system syslog file logFile facility local6 level emerg", +# "set system syslog host 172.16.0.1 facility all protocol udp", +# "set system syslog user vyos facility local7 level debug", +# "set system syslog host 172.16.0.1 port 223", +# "set system syslog global facility cron level debug", +# "set system syslog global archive file 2", +# "set system syslog global archive size 111", +# "set system syslog global marker interval 111", +# "set system syslog global preserve-fqdn" +# ], + +# After state: +# ------------ + +# vyos:~$ show configuration commands | grep syslog +# set system syslog console facility local7 level 'err' +# set system syslog file logFile archive file '2' +# set system syslog file logFile facility local6 level 'emerg' +# set system syslog global archive file '2' +# set system syslog global archive size '111' +# set system syslog global facility cron level 'debug' +# set system syslog global marker interval '111' +# set system syslog global preserve-fqdn +# set system syslog host 172.16.0.1 facility all protocol 'udp' +# set system syslog host 172.16.0.1 facility local7 level 'all' +# set system syslog host 172.16.0.1 port '223' +# set system syslog user vyos facility local7 level 'debug' + +# Using state: deleted + +# Before state: +# ------------- + +# vyos:~$show configuration commands | grep syslog +# set system syslog console facility local7 level 'err' +# set system syslog file logFile archive file '2' +# set system syslog file logFile facility local6 level 'emerg' +# set system syslog global archive file '2' +# set system syslog global archive size '111' +# set system syslog global facility cron level 'debug' +# set system syslog global marker interval '111' +# set system syslog global preserve-fqdn +# set system syslog host 172.16.0.1 facility all protocol 'udp' +# set system syslog host 172.16.0.1 facility local7 level 'all' +# set system syslog host 172.16.0.1 port '223' +# set system syslog user vyos facility local7 level 'debug' + +- name: delete the existing configuration + vyos.vyos.vyos_logging_global: + state: deleted + +# Commands Fired: +# --------------- + +# "commands": [ +# "delete system syslog" +# ], + +# After state: +# ------------ + +# vyos:~$show configuration commands | grep syslog + +# Using state: overridden + +# Before state: +# ------------- + +# vyos:~$show configuration commands | grep syslog +# set system syslog console facility local7 level 'err' +# set system syslog file logFile archive file '2' +# set system syslog file logFile facility local6 level 'emerg' +# set system syslog global archive file '2' +# set system syslog global archive size '111' +# set system syslog global facility cron level 'debug' +# set system syslog global marker interval '111' +# set system syslog global preserve-fqdn +# set system syslog host 172.16.0.1 facility all protocol 'udp' +# set system syslog host 172.16.0.1 facility local7 level 'all' +# set system syslog host 172.16.0.1 port '223' +# set system syslog user vyos facility local7 level 'debug' + +- name: Override the current configuration + vyos.vyos.vyos_logging_global: + config: + console: + facilities: + - facility: all + - facility: local7 + severity: err + - facility: news + severity: debug + files: + - path: logFileNew + hosts: + - hostname: 172.16.0.2 + facilities: + - facility: local5 + severity: all + global_params: + archive: + file_num: 10 + state: overridden + +# Commands Fired: +# --------------- + +# "commands": [ +# "delete system syslog file logFile", +# "delete system syslog global facility cron", +# "delete system syslog host 172.16.0.1", +# "delete system syslog user vyos", +# "set system syslog console facility all", +# "set system syslog console facility news level debug", +# "set system syslog file logFileNew", +# "set system syslog host 172.16.0.2 facility local5 level all", +# "set system syslog global archive file 10", +# "delete system syslog global archive size 111", +# "delete system syslog global marker", +# "delete system syslog global preserve-fqdn" +# ], + +# After state: +# ------------ + +# vyos:~$show configuration commands | grep syslog +# set system syslog console facility all +# set system syslog console facility local7 level 'err' +# set system syslog console facility news level 'debug' +# set system syslog file logFileNew +# set system syslog global archive file '10' +# set system syslog host 172.16.0.2 facility local5 level 'all' + +# Using state: replaced + +# Before state: +# ------------- + +# vyos:~$show configuration commands | grep syslog +# set system syslog console facility all +# set system syslog console facility local7 level 'err' +# set system syslog console facility news level 'debug' +# set system syslog file logFileNew +# set system syslog global archive file '10' +# set system syslog host 172.16.0.2 facility local5 level 'all' + +- name: Replace with the provided configuration + register: result + vyos.vyos.vyos_logging_global: + config: + console: + facilities: + - facility: local6 + users: + - username: paul + facilities: + - facility: local7 + severity: err + state: replaced + +# Commands Fired: +# --------------- + +# "commands": [ +# "delete system syslog console facility all", +# "delete system syslog console facility local7", +# "delete system syslog console facility news", +# "delete system syslog file logFileNew", +# "delete system syslog global archive file 10", +# "delete system syslog host 172.16.0.2", +# "set system syslog console facility local6", +# "set system syslog user paul facility local7 level err" +# ], + +# After state: +# ------------ + +# vyos:~$show configuration commands | grep syslog +# set system syslog console facility local6 +# set system syslog user paul facility local7 level 'err' + +# Using state: gathered + +- name: Gather logging config + vyos.vyos.vyos_logging_global: + state: gathered + +# Module Execution Result: +# ------------------------ + +# "gathered": { +# "console": { +# "facilities": [ +# { +# "facility": "local6" +# }, +# { +# "facility": "local7", +# "severity": "err" +# } +# ] +# }, +# "files": [ +# { +# "archive": { +# "file_num": 2 +# }, +# "facilities": [ +# { +# "facility": "local6", +# "severity": "emerg" +# } +# ], +# "path": "logFile" +# } +# ], +# "global_params": { +# "archive": { +# "file_num": 2, +# "size": 111 +# }, +# "facilities": [ +# { +# "facility": "cron", +# "severity": "debug" +# } +# ], +# "marker_interval": 111, +# "preserve_fqdn": true +# }, +# "hosts": [ +# { +# "facilities": [ +# { +# "facility": "all", +# "protocol": "udp" +# }, +# { +# "facility": "local7", +# "severity": "all" +# } +# ], +# "hostname": "172.16.0.1", +# "port": 223 +# } +# ], +# "users": [ +# { +# "facilities": [ +# { +# "facility": "local7", +# "severity": "err" +# } +# ], +# "username": "paul" +# }, +# { +# "facilities": [ +# { +# "facility": "local7", +# "severity": "debug" +# } +# ], +# "username": "vyos" +# } +# ] +# }, + +# After state: +# ------------ + +# vyos:~$show configuration commands | grep syslog +# set system syslog console facility local6 +# set system syslog console facility local7 level 'err' +# set system syslog file logFile archive file '2' +# set system syslog file logFile facility local6 level 'emerg' +# set system syslog global archive file '2' +# set system syslog global archive size '111' +# set system syslog global facility cron level 'debug' +# set system syslog global marker interval '111' +# set system syslog global preserve-fqdn +# set system syslog host 172.16.0.1 facility all protocol 'udp' +# set system syslog host 172.16.0.1 facility local7 level 'all' +# set system syslog host 172.16.0.1 port '223' +# set system syslog user paul facility local7 level 'err' +# set system syslog user vyos facility local7 level 'debug' + +# Using state: rendered + +- name: Render the provided configuration + vyos.vyos.vyos_logging_global: + config: + console: + facilities: + - facility: local7 + severity: err + files: + - path: logFile + archive: + file_num: 2 + facilities: + - facility: local6 + severity: emerg + hosts: + - hostname: 172.16.0.1 + facilities: + - facility: local7 + severity: all + - facility: all + protocol: udp + port: 223 + users: + - username: vyos + facilities: + - facility: local7 + severity: debug + global_params: + archive: + file_num: 2 + size: 111 + facilities: + - facility: cron + severity: debug + marker_interval: 111 + preserve_fqdn: true + state: rendered + +# Module Execution Result: +# ------------------------ + +# "rendered": [ +# "set system syslog console facility local7 level err", +# "set system syslog file logFile facility local6 level emerg", +# "set system syslog file logFile archive file 2", +# "set system syslog host 172.16.0.1 facility local7 level all", +# "set system syslog host 172.16.0.1 facility all protocol udp", +# "set system syslog host 172.16.0.1 port 223", +# "set system syslog user vyos facility local7 level debug", +# "set system syslog global facility cron level debug", +# "set system syslog global archive file 2", +# "set system syslog global archive size 111", +# "set system syslog global marker interval 111", +# "set system syslog global preserve-fqdn" +# ] + +# Using state: parsed + +# File: parsed.cfg +# ---------------- + +# set system syslog console facility local6 +# set system syslog console facility local7 level 'err' +# set system syslog file logFile archive file '2' +# set system syslog file logFile facility local6 level 'emerg' +# set system syslog global archive file '2' +# set system syslog global archive size '111' +# set system syslog global facility cron level 'debug' +# set system syslog global marker interval '111' +# set system syslog global preserve-fqdn +# set system syslog host 172.16.0.1 facility all protocol 'udp' +# set system syslog host 172.16.0.1 facility local7 level 'all' +# set system syslog host 172.16.0.1 port '223' +# set system syslog user paul facility local7 level 'err' +# set system syslog user vyos facility local7 level 'debug' + +- name: Parse the provided configuration + vyos.vyos.vyos_logging_global: + running_config: "{{ lookup('file', 'parsed_vyos.cfg') }}" + state: parsed + +# Module Execution Result: +# ------------------------ + +# "parsed": { +# "console": { +# "facilities": [ +# { +# "facility": "local6" +# }, +# { +# "facility": "local7", +# "severity": "err" +# } +# ] +# }, +# "files": [ +# { +# "archive": { +# "file_num": 2 +# }, +# "facilities": [ +# { +# "facility": "local6", +# "severity": "emerg" +# } +# ], +# "path": "logFile" +# } +# ], +# "global_params": { +# "archive": { +# "file_num": 2, +# "size": 111 +# }, +# "facilities": [ +# { +# "facility": "cron", +# "severity": "debug" +# } +# ], +# "marker_interval": 111, +# "preserve_fqdn": true +# }, +# "hosts": [ +# { +# "facilities": [ +# { +# "facility": "all", +# "protocol": "udp" +# }, +# { +# "facility": "local7", +# "severity": "all" +# } +# ], +# "hostname": "172.16.0.1", +# "port": 223 +# } +# ], +# "users": [ +# { +# "facilities": [ +# { +# "facility": "local7", +# "severity": "err" +# } +# ], +# "username": "paul" +# }, +# { +# "facilities": [ +# { +# "facility": "local7", +# "severity": "debug" +# } +# ], +# "username": "vyos" +# } +# ] +# } +# } +""" + +RETURN = """ +before: + description: The configuration prior to the module execution. + returned: when state is I(merged), I(replaced), I(overridden), I(deleted) or I(purged) + type: dict + sample: > + This output will always be in the same format as the + module argspec. +after: + description: The resulting configuration after module execution. + returned: when changed + type: dict + sample: > + This output will always be in the same format as the + module argspec. +commands: + description: The set of commands pushed to the remote device. + returned: when state is I(merged), I(replaced), I(overridden), I(deleted) or I(purged) + type: list + sample: + - "set system syslog console facility local7 level err" + - "set system syslog host 172.16.0.1 port 223" + - "set system syslog global archive size 111" +rendered: + description: The provided configuration in the task rendered in device-native format (offline). + returned: when state is I(rendered) + type: list + sample: + - "set system syslog host 172.16.0.1 port 223" + - "set system syslog user vyos facility local7 level debug" + - "set system syslog global facility cron level debug" +gathered: + description: Facts about the network resource gathered from the remote device as structured data. + returned: when state is I(gathered) + type: list + sample: > + This output will always be in the same format as the + module argspec. +parsed: + description: The device native config provided in I(running_config) option parsed into structured data as per module argspec. + returned: when state is I(parsed) + type: list + sample: > + This output will always be in the same format as the + module argspec. +""" + +from ansible.module_utils.basic import AnsibleModule +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.logging_global.logging_global import ( + Logging_globalArgs, +) +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.config.logging_global.logging_global import ( + Logging_global, +) + + +def main(): + """ + Main entry point for module execution + + :returns: the result form module invocation + """ + module = AnsibleModule( + argument_spec=Logging_globalArgs.argument_spec, + mutually_exclusive=[["config", "running_config"]], + required_if=[ + ["state", "merged", ["config"]], + ["state", "replaced", ["config"]], + ["state", "overridden", ["config"]], + ["state", "rendered", ["config"]], + ["state", "parsed", ["running_config"]], + ], + supports_check_mode=True, + ) + + result = Logging_global(module).execute_module() + module.exit_json(**result) + + +if __name__ == "__main__": + main() diff --git a/tests/integration/targets/vyos_logging_global/defaults/main.yaml b/tests/integration/targets/vyos_logging_global/defaults/main.yaml new file mode 100644 index 0000000..852a6be --- /dev/null +++ b/tests/integration/targets/vyos_logging_global/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: '[^_].*' +test_items: [] diff --git a/tests/integration/targets/vyos_logging_global/meta/main.yaml b/tests/integration/targets/vyos_logging_global/meta/main.yaml new file mode 100644 index 0000000..91da2a7 --- /dev/null +++ b/tests/integration/targets/vyos_logging_global/meta/main.yaml @@ -0,0 +1,2 @@ +--- +... diff --git a/tests/integration/targets/vyos_logging_global/tasks/cli.yaml b/tests/integration/targets/vyos_logging_global/tasks/cli.yaml new file mode 100644 index 0000000..93eb2fe --- /dev/null +++ b/tests/integration/targets/vyos_logging_global/tasks/cli.yaml @@ -0,0 +1,19 @@ +--- +- name: Collect all cli test cases + find: + paths: '{{ role_path }}/tests/cli' + patterns: '{{ testcase }}.yaml' + use_regex: true + register: test_cases + delegate_to: localhost + +- name: Set test_items + set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + +- name: Run test case (connection=ansible.netcommon.network_cli) + include: '{{ test_case_to_run }}' + vars: + ansible_connection: ansible.netcommon.network_cli + with_items: '{{ test_items }}' + loop_control: + loop_var: test_case_to_run diff --git a/tests/integration/targets/vyos_logging_global/tasks/main.yaml b/tests/integration/targets/vyos_logging_global/tasks/main.yaml new file mode 100644 index 0000000..b957d2f --- /dev/null +++ b/tests/integration/targets/vyos_logging_global/tasks/main.yaml @@ -0,0 +1,4 @@ +--- +- include: cli.yaml + tags: + - network_cli diff --git a/tests/integration/targets/vyos_logging_global/tests/cli/_parsed.cfg b/tests/integration/targets/vyos_logging_global/tests/cli/_parsed.cfg new file mode 100644 index 0000000..fb2c3dc --- /dev/null +++ b/tests/integration/targets/vyos_logging_global/tests/cli/_parsed.cfg @@ -0,0 +1,3 @@ +set system syslog console facility news level 'debug' +set system syslog file def facility local7 level 'emerg' +set system syslog global facility local7 level 'debug' diff --git a/tests/integration/targets/vyos_logging_global/tests/cli/_populate.yaml b/tests/integration/targets/vyos_logging_global/tests/cli/_populate.yaml new file mode 100644 index 0000000..2f3828f --- /dev/null +++ b/tests/integration/targets/vyos_logging_global/tests/cli/_populate.yaml @@ -0,0 +1,53 @@ +--- +- name: POPULATE Apply the provided configuration + register: result + vyos.vyos.vyos_logging_global: + config: + console: + facilities: + - facility: all + - facility: local7 + severity: err + - facility: news + severity: debug + files: + - path: def + archive: + file_num: 2 + facilities: + - facility: local6 + severity: emerg + - facility: local7 + severity: emerg + hosts: + - hostname: 172.16.2.15 + facilities: + - facility: all + severity: all + - facility: all + protocol: udp + - hostname: 172.16.2.12 + facilities: + - facility: all + protocol: udp + users: + - username: vyos + facilities: + - facility: local7 + severity: debug + - facility: local6 + severity: alert + - username: paul + facilities: + - facility: local7 + severity: err + global_params: + archive: + file_num: 2 + size: 111 + facilities: + - facility: cron + severity: debug + - facility: local7 + severity: debug + state: merged diff --git a/tests/integration/targets/vyos_logging_global/tests/cli/_remove_config.yaml b/tests/integration/targets/vyos_logging_global/tests/cli/_remove_config.yaml new file mode 100644 index 0000000..1c2187b --- /dev/null +++ b/tests/integration/targets/vyos_logging_global/tests/cli/_remove_config.yaml @@ -0,0 +1,4 @@ +--- +- name: delete the provided configuration + vyos.vyos.vyos_logging_global: + state: deleted diff --git a/tests/integration/targets/vyos_logging_global/tests/cli/deleted.yaml b/tests/integration/targets/vyos_logging_global/tests/cli/deleted.yaml new file mode 100644 index 0000000..2a0a355 --- /dev/null +++ b/tests/integration/targets/vyos_logging_global/tests/cli/deleted.yaml @@ -0,0 +1,22 @@ +--- +- debug: + msg: Start Deleted integration state for vyos_logging ansible_connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml +- include_tasks: _populate.yaml + +- block: + - name: TEST - [deleted] Remove all configuration + vyos.vyos.vyos_logging_global: + state: deleted + register: result + + - name: TEST - [deleted] Assert that correct set of commands were generated + assert: + that: + - "{{ deleted['commands'] | symmetric_difference(result['commands']) |\ + \ length == 0 }}" + + always: + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_logging_global/tests/cli/empty_config.yaml b/tests/integration/targets/vyos_logging_global/tests/cli/empty_config.yaml new file mode 100644 index 0000000..f70fff1 --- /dev/null +++ b/tests/integration/targets/vyos_logging_global/tests/cli/empty_config.yaml @@ -0,0 +1,60 @@ +--- +- debug: + msg: START vyos_logging_global empty_config integration tests on connection={{ + ansible_connection }} + +- name: Merged with empty config should give appropriate error message + register: result + ignore_errors: true + vyos.vyos.vyos_logging_global: + config: + state: merged + +- assert: + that: + - result.msg == 'value of config parameter must not be empty for state merged' + +- name: Replaced with empty config should give appropriate error message + register: result + ignore_errors: true + vyos.vyos.vyos_logging_global: + config: + state: replaced + +- assert: + that: + - result.msg == 'value of config parameter must not be empty for state replaced' + +- name: Overridden with empty config should give appropriate error message + register: result + ignore_errors: true + vyos.vyos.vyos_logging_global: + config: + state: overridden + +- assert: + that: + - result.msg == 'value of config parameter must not be empty for state overridden' + +- name: Parsed with empty running_config should give appropriate error message + register: result + ignore_errors: true + vyos.vyos.vyos_logging_global: + running_config: + state: parsed + +- assert: + that: + - result.msg == 'value of running_config parameter must not be empty for state + parsed' + +- name: Rendered with empty config should give appropriate error message + register: result + ignore_errors: true + vyos.vyos.vyos_logging_global: + config: + state: rendered + +- assert: + that: + - result.msg == 'value of config parameter must not be empty for state rendered' diff --git a/tests/integration/targets/vyos_logging_global/tests/cli/gathered.yaml b/tests/integration/targets/vyos_logging_global/tests/cli/gathered.yaml new file mode 100644 index 0000000..af1fa52 --- /dev/null +++ b/tests/integration/targets/vyos_logging_global/tests/cli/gathered.yaml @@ -0,0 +1,22 @@ +--- +- debug: + msg: START vyos_logging_global gathered integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate.yaml + +- block: + - name: TEST - [gathered] Gather the provided configuration with the existing running configuration + register: result + vyos.vyos.vyos_logging_global: + config: + state: gathered + + - name: TEST - [gathered] Assert + assert: + that: + - result.changed == false + always: + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_logging_global/tests/cli/merged.yaml b/tests/integration/targets/vyos_logging_global/tests/cli/merged.yaml new file mode 100644 index 0000000..d47d309 --- /dev/null +++ b/tests/integration/targets/vyos_logging_global/tests/cli/merged.yaml @@ -0,0 +1,56 @@ +--- +- debug: + msg: + START vyos_logging_global merged integration tests on connection={{ ansible_connection + }} + +- include_tasks: _remove_config.yaml + +- block: # no after state match because 1.1.8 vyos does show all commands on show command + - name: Merge the provided configuration with the existing running configuration + register: result + vyos.vyos.vyos_logging_global: &id001 + config: + console: + facilities: + - facility: all + files: + - path: def + archive: + file_num: 2 + facilities: + - facility: local6 + severity: emerg + hosts: + - hostname: 172.16.2.15 + facilities: + - facility: all + severity: all + users: + - username: vyos + facilities: + - facility: local7 + severity: debug + global_params: + archive: + file_num: 2 + size: 111 + facilities: + - facility: cron + severity: debug + state: merged + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ merged['commands'] | symmetric_difference(result['commands']) |length\ + \ == 0 }}" + + - name: + Merge the provided configuration with the existing running configuration + (IDEMPOTENT) + register: result + vyos.vyos.vyos_logging_global: *id001 + + always: + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_logging_global/tests/cli/overridden.yaml b/tests/integration/targets/vyos_logging_global/tests/cli/overridden.yaml new file mode 100644 index 0000000..1df1a8d --- /dev/null +++ b/tests/integration/targets/vyos_logging_global/tests/cli/overridden.yaml @@ -0,0 +1,39 @@ +--- +- debug: + msg: START vyos_logging_global overridden integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate.yaml + +- block: # no after state match because 1.1.8 vyos does show all commands on show command + - name: Overrides all device configuration with provided configuration + register: result + vyos.vyos.vyos_logging_global: &id001 + config: + console: + facilities: + - facility: all + - facility: local7 + severity: err + - facility: news + severity: debug + global_params: + archive: + file_num: 2 + state: overridden + + - name: Assert that correct commands were generated + assert: + that: + - "{{ overridden['commands'] | symmetric_difference(result['commands'])\ + \ |length == 0 }}" + + - name: Overrides all device configuration with provided configurations (IDEMPOTENT) + register: result + vyos.vyos.vyos_logging_global: *id001 + + always: + + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_logging_global/tests/cli/parsed.yaml b/tests/integration/targets/vyos_logging_global/tests/cli/parsed.yaml new file mode 100644 index 0000000..40a14f6 --- /dev/null +++ b/tests/integration/targets/vyos_logging_global/tests/cli/parsed.yaml @@ -0,0 +1,14 @@ +--- +- debug: + msg: START vyos_logging_global parsed integration tests on connection={{ ansible_connection }} + +- name: TEST - [parsed] Parse the commands for provided configuration + register: result + vyos.vyos.vyos_logging_global: + running_config: "{{ lookup('file', '_parsed.cfg') }}" + state: parsed + +- assert: + that: + - result.changed == false + - parsed['after'] == result.parsed diff --git a/tests/integration/targets/vyos_logging_global/tests/cli/rendered.yaml b/tests/integration/targets/vyos_logging_global/tests/cli/rendered.yaml new file mode 100644 index 0000000..366f889 --- /dev/null +++ b/tests/integration/targets/vyos_logging_global/tests/cli/rendered.yaml @@ -0,0 +1,50 @@ +--- +- debug: + msg: START vyos_logging_global rendered integration tests on connection={{ ansible_connection + }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate.yaml + +- block: + + - name: Structure provided configuration into device specific commands + register: result + vyos.vyos.vyos_logging_global: &id001 + config: + console: + facilities: + - facility: all + files: + - path: abc + archive: + size: 125 + hosts: + - hostname: 172.16.2.15 + facilities: + - facility: all + severity: all + users: + - username: vyos + facilities: + - facility: local7 + severity: debug + global_params: + archive: + file_num: 2 + size: 111 + facilities: + - facility: cron + severity: debug + state: rendered + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ rendered['commands'] | symmetric_difference(result['rendered'])\ + \ |length == 0 }}" + + always: + + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_logging_global/vars/main.yaml b/tests/integration/targets/vyos_logging_global/vars/main.yaml new file mode 100644 index 0000000..ae8b853 --- /dev/null +++ b/tests/integration/targets/vyos_logging_global/vars/main.yaml @@ -0,0 +1,95 @@ +--- +merged: + before: {} + commands: + - set system syslog host 172.16.2.15 facility all level all + - set system syslog console facility all + - set system syslog user vyos facility local7 level debug + - set system syslog global facility cron level debug + - set system syslog global archive file 2 + - set system syslog global archive size 111 + - set system syslog file def archive file 2 + - set system syslog file def facility local6 level emerg + after: + console: + facilities: + - facility: all + files: + - path: def + facilities: + - facility: local6 + severity: emerg + hosts: + - hostname: 172.16.2.15 + facilities: + - facility: all + severity: all + users: + - username: vyos + facilities: + - facility: local7 + severity: debug + global_params: + archive: + size: 111 + facilities: + - facility: cron + severity: debug + +overridden: + commands: + - delete system syslog file def + - delete system syslog global facility cron + - delete system syslog global facility local7 + - delete system syslog host 172.16.2.12 + - delete system syslog host 172.16.2.15 + - delete system syslog user paul + - delete system syslog user vyos + - set system syslog console facility all + - set system syslog global archive file 2 + - delete system syslog global archive size 111 + + after: + console: + facilities: + - facility: all + - facility: local7 + severity: err + - facility: news + severity: debug + files: + - path: Myfile + global_params: + archive: + file_num: 2 + +rendered: + commands: + - set system syslog console facility all + - set system syslog file abc archive size 125 + - set system syslog host 172.16.2.15 facility all level all + - set system syslog user vyos facility local7 level debug + - set system syslog global facility cron level debug + - set system syslog global archive file 2 + - set system syslog global archive size 111 + +deleted: + commands: + - delete system syslog + after: {} + +parsed: + after: + console: + facilities: + - facility: news + severity: debug + files: + - path: def + facilities: + - facility: local7 + severity: emerg + global_params: + facilities: + - facility: local7 + severity: debug diff --git a/tests/sanity/ignore-2.10.txt b/tests/sanity/ignore-2.10.txt index 967e336..d753480 100644 --- a/tests/sanity/ignore-2.10.txt +++ b/tests/sanity/ignore-2.10.txt @@ -1,9 +1,12 @@ plugins/action/vyos.py action-plugin-docs # base class for deprecated network platform modules using `connection: local` plugins/module_utils/network/vyos/config/ospf_interfaces/ospf_interfaces.py compile-2.6!skip plugins/module_utils/network/vyos/config/ospf_interfaces/ospf_interfaces.py import-2.6!skip plugins/module_utils/network/vyos/config/route_maps/route_maps.py compile-2.6!skip plugins/module_utils/network/vyos/config/route_maps/route_maps.py import-2.6!skip plugins/modules/vyos_route_maps.py import-2.6!skip plugins/modules/vyos_prefix_lists.py import-2.6!skip plugins/module_utils/network/vyos/config/prefix_lists/prefix_lists.py import-2.6!skip plugins/module_utils/network/vyos/config/prefix_lists/prefix_lists.py compile-2.6!skip +plugins/modules/vyos_logging_global.py import-2.6!skip +plugins/module_utils/network/vyos/config/logging_global/logging_global.py import-2.6!skip +plugins/module_utils/network/vyos/config/logging_global/logging_global.py compile-2.6!skip \ No newline at end of file diff --git a/tests/sanity/ignore-2.11.txt b/tests/sanity/ignore-2.11.txt index 967e336..d753480 100644 --- a/tests/sanity/ignore-2.11.txt +++ b/tests/sanity/ignore-2.11.txt @@ -1,9 +1,12 @@ plugins/action/vyos.py action-plugin-docs # base class for deprecated network platform modules using `connection: local` plugins/module_utils/network/vyos/config/ospf_interfaces/ospf_interfaces.py compile-2.6!skip plugins/module_utils/network/vyos/config/ospf_interfaces/ospf_interfaces.py import-2.6!skip plugins/module_utils/network/vyos/config/route_maps/route_maps.py compile-2.6!skip plugins/module_utils/network/vyos/config/route_maps/route_maps.py import-2.6!skip plugins/modules/vyos_route_maps.py import-2.6!skip plugins/modules/vyos_prefix_lists.py import-2.6!skip plugins/module_utils/network/vyos/config/prefix_lists/prefix_lists.py import-2.6!skip plugins/module_utils/network/vyos/config/prefix_lists/prefix_lists.py compile-2.6!skip +plugins/modules/vyos_logging_global.py import-2.6!skip +plugins/module_utils/network/vyos/config/logging_global/logging_global.py import-2.6!skip +plugins/module_utils/network/vyos/config/logging_global/logging_global.py compile-2.6!skip \ No newline at end of file diff --git a/tests/sanity/ignore-2.12.txt b/tests/sanity/ignore-2.12.txt index 967e336..d753480 100644 --- a/tests/sanity/ignore-2.12.txt +++ b/tests/sanity/ignore-2.12.txt @@ -1,9 +1,12 @@ plugins/action/vyos.py action-plugin-docs # base class for deprecated network platform modules using `connection: local` plugins/module_utils/network/vyos/config/ospf_interfaces/ospf_interfaces.py compile-2.6!skip plugins/module_utils/network/vyos/config/ospf_interfaces/ospf_interfaces.py import-2.6!skip plugins/module_utils/network/vyos/config/route_maps/route_maps.py compile-2.6!skip plugins/module_utils/network/vyos/config/route_maps/route_maps.py import-2.6!skip plugins/modules/vyos_route_maps.py import-2.6!skip plugins/modules/vyos_prefix_lists.py import-2.6!skip plugins/module_utils/network/vyos/config/prefix_lists/prefix_lists.py import-2.6!skip plugins/module_utils/network/vyos/config/prefix_lists/prefix_lists.py compile-2.6!skip +plugins/modules/vyos_logging_global.py import-2.6!skip +plugins/module_utils/network/vyos/config/logging_global/logging_global.py import-2.6!skip +plugins/module_utils/network/vyos/config/logging_global/logging_global.py compile-2.6!skip \ No newline at end of file diff --git a/tests/sanity/ignore-2.9.txt b/tests/sanity/ignore-2.9.txt index aa3ef3f..83e9150 100644 --- a/tests/sanity/ignore-2.9.txt +++ b/tests/sanity/ignore-2.9.txt @@ -1,21 +1,26 @@ plugins/modules/vyos_interface.py validate-modules:deprecation-mismatch # 2.9 expects METADATA plugins/modules/vyos_interface.py validate-modules:invalid-documentation # removed_at_date not supported in `deprecated` dict plugins/modules/vyos_l3_interface.py validate-modules:deprecation-mismatch # 2.9 expects METADATA plugins/modules/vyos_l3_interface.py validate-modules:invalid-documentation # removed_at_date not supported in `deprecated` dict plugins/modules/vyos_linkagg.py validate-modules:deprecation-mismatch # 2.9 expects METADATA plugins/modules/vyos_linkagg.py validate-modules:invalid-documentation # removed_at_date not supported in `deprecated` dict plugins/modules/vyos_static_route.py validate-modules:deprecation-mismatch # 2.9 expects METADATA plugins/modules/vyos_static_route.py validate-modules:invalid-documentation # removed_at_date not supported in `deprecated` dict plugins/modules/vyos_lldp.py validate-modules:deprecation-mismatch # 2.9 expects METADATA plugins/modules/vyos_lldp.py validate-modules:invalid-documentation # removed_at_date not supported in `deprecated` dict plugins/modules/vyos_lldp_interface.py validate-modules:deprecation-mismatch # 2.9 expects METADATA plugins/modules/vyos_lldp_interface.py validate-modules:invalid-documentation # removed_at_date not supported in `deprecated` dict +plugins/modules/vyos_logging.py validate-modules:deprecation-mismatch # 2.9 expects METADATA +plugins/modules/vyos_logging.py validate-modules:invalid-documentation # removed_at_date not supported in `deprecated` dict plugins/action/vyos.py action-plugin-docs # base class for deprecated network platform modules using `connection: local` plugins/module_utils/network/vyos/config/ospf_interfaces/ospf_interfaces.py compile-2.6!skip plugins/module_utils/network/vyos/config/ospf_interfaces/ospf_interfaces.py import-2.6!skip plugins/module_utils/network/vyos/config/route_maps/route_maps.py compile-2.6!skip plugins/module_utils/network/vyos/config/route_maps/route_maps.py import-2.6!skip plugins/modules/vyos_route_maps.py import-2.6!skip plugins/modules/vyos_prefix_lists.py import-2.6!skip plugins/module_utils/network/vyos/config/prefix_lists/prefix_lists.py import-2.6!skip plugins/module_utils/network/vyos/config/prefix_lists/prefix_lists.py compile-2.6!skip +plugins/modules/vyos_logging_global.py import-2.6!skip +plugins/module_utils/network/vyos/config/logging_global/logging_global.py import-2.6!skip +plugins/module_utils/network/vyos/config/logging_global/logging_global.py compile-2.6!skip \ No newline at end of file diff --git a/tests/unit/modules/network/vyos/test_vyos_logging_global.py b/tests/unit/modules/network/vyos/test_vyos_logging_global.py new file mode 100644 index 0000000..0f72aeb --- /dev/null +++ b/tests/unit/modules/network/vyos/test_vyos_logging_global.py @@ -0,0 +1,464 @@ +# +# (c) 2021, Ansible by 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 + +from textwrap import dedent +from ansible_collections.vyos.vyos.tests.unit.compat.mock import patch +from ansible_collections.vyos.vyos.plugins.modules import vyos_logging_global +from ansible_collections.vyos.vyos.tests.unit.modules.utils import ( + set_module_args, +) +from .vyos_module import TestVyosModule + + +class TestVyosLoggingGlobalModule(TestVyosModule): + + module = vyos_logging_global + + def setUp(self): + super(TestVyosLoggingGlobalModule, self).setUp() + + self.mock_get_resource_connection_config = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base.get_resource_connection" + ) + self.get_resource_connection_config = ( + self.mock_get_resource_connection_config.start() + ) + + self.mock_get_resource_connection_facts = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.facts.facts.get_resource_connection" + ) + self.get_resource_connection_facts = ( + self.mock_get_resource_connection_facts.start() + ) + + self.mock_execute_show_command = patch( + "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.logging_global.logging_global.Logging_globalFacts.get_logging_data" + ) + + self.execute_show_command = self.mock_execute_show_command.start() + + def tearDown(self): + super(TestVyosLoggingGlobalModule, self).tearDown() + self.mock_get_resource_connection_config.stop() + self.mock_get_resource_connection_facts.stop() + self.mock_execute_show_command.stop() + + def test_vyos_logging_global_merged_idempotent(self): + self.execute_show_command.return_value = dedent( + """\ + set system syslog console facility all + set system syslog console facility local7 level 'err' + set system syslog console facility news level 'debug' + set system syslog file xyz + set system syslog file abc archive size '125' + set system syslog file def archive file '2' + set system syslog file def facility local6 level 'emerg' + set system syslog file def facility local7 level 'emerg' + set system syslog global archive file '2' + set system syslog global archive size '111' + set system syslog global facility cron level 'debug' + set system syslog global facility local7 level 'debug' + set system syslog global marker interval '111' + set system syslog global preserve-fqdn + set system syslog host 10.0.2.12 facility all protocol 'udp' + set system syslog host 10.0.2.15 facility all level 'all' + set system syslog host 10.0.2.15 facility all protocol 'udp' + set system syslog host 10.0.2.15 port '122' + set system syslog user paul facility local7 level 'err' + set system syslog user vyos facility local6 level 'alert' + set system syslog user vyos facility local7 level 'debug' + """ + ) + playbook = dict( + config=dict( + console=dict( + facilities=[ + dict(facility="all"), + dict(facility="local7", severity="err"), + dict(facility="news", severity="debug"), + ] + ), + files=[ + dict(path="xyz"), + dict(path="abc", archive=dict(size=125)), + dict( + path="def", + archive=dict(file_num=2), + facilities=[ + dict(facility="local6", severity="emerg"), + dict(facility="local7", severity="emerg"), + ], + ), + ], + hosts=[ + dict( + hostname="10.0.2.15", + port=122, + facilities=[ + dict(facility="all", severity="all"), + dict(facility="all", protocol="udp"), + ], + ), + dict( + hostname="10.0.2.12", + facilities=[dict(facility="all", protocol="udp")], + ), + ], + users=[ + dict( + username="vyos", + facilities=[ + dict(facility="local7", severity="debug"), + dict(facility="local6", severity="alert"), + ], + ), + dict( + username="paul", + facilities=[dict(facility="local7", severity="err")], + ), + ], + global_params=dict( + archive=dict(size=111, file_num=2), + marker_interval=111, + preserve_fqdn="True", + facilities=[ + dict(facility="cron", severity="debug"), + dict(facility="local7", severity="debug"), + ], + ), + ) + ) + compare_cmds = [] + playbook["state"] = "merged" + set_module_args(playbook) + result = self.execute_module() + + self.maxDiff = None + self.assertEqual(sorted(result["commands"]), sorted(compare_cmds)) + + def test_vyos_logging_global_merged(self): + self.execute_show_command.return_value = dedent( + """\ + """ + ) + playbook = dict( + config=dict( + console=dict( + facilities=[ + dict(facility="all"), + dict(facility="local7", severity="err"), + dict(facility="news", severity="debug"), + ] + ), + files=[ + dict(path="xyz"), + dict(path="abc", archive=dict(size=125)), + dict( + path="def", + archive=dict(file_num=2), + facilities=[ + dict(facility="local6", severity="emerg"), + dict(facility="local7", severity="emerg"), + ], + ), + ], + hosts=[ + dict( + hostname="10.0.2.15", + port=122, + facilities=[ + dict(facility="all", severity="all"), + dict(facility="all", protocol="udp"), + ], + ), + dict( + hostname="10.0.2.12", + facilities=[dict(facility="all", protocol="udp")], + ), + ], + users=[ + dict( + username="vyos", + facilities=[ + dict(facility="local7", severity="debug"), + dict(facility="local6", severity="alert"), + ], + ), + dict( + username="paul", + facilities=[dict(facility="local7", severity="err")], + ), + ], + global_params=dict( + archive=dict(size=111, file_num=2), + marker_interval=111, + preserve_fqdn="True", + facilities=[ + dict(facility="cron", severity="debug"), + dict(facility="local7", severity="debug"), + ], + ), + ) + ) + compare_cmds = [ + "set system syslog user paul facility local7 level err", + "set system syslog host 10.0.2.15 facility all protocol udp", + "set system syslog global marker interval 111", + "set system syslog file def archive file 2", + "set system syslog file abc archive size 125", + "set system syslog console facility local7 level err", + "set system syslog host 10.0.2.12 facility all protocol udp", + "set system syslog global facility local7 level debug", + "set system syslog host 10.0.2.15 facility all level all", + "set system syslog global preserve-fqdn", + "set system syslog global archive file 2", + "set system syslog console facility all", + "set system syslog file xyz", + "set system syslog file def facility local7 level emerg", + "set system syslog console facility news level debug", + "set system syslog user vyos facility local6 level alert", + "set system syslog global facility cron level debug", + "set system syslog file def facility local6 level emerg", + "set system syslog global archive size 111", + "set system syslog host 10.0.2.15 port 122", + "set system syslog user vyos facility local7 level debug", + ] + playbook["state"] = "merged" + set_module_args(playbook) + result = self.execute_module(changed=True) + self.maxDiff = None + self.assertEqual(sorted(result["commands"]), sorted(compare_cmds)) + + def test_vyos_logging_global_deleted(self): + self.execute_show_command.return_value = dedent( + """\ + set system syslog console facility all + set system syslog console facility local7 level 'err' + set system syslog console facility news level 'debug' + set system syslog file xyz + set system syslog file abc archive size '125' + set system syslog file def archive file '2' + set system syslog file def facility local6 level 'emerg' + set system syslog file def facility local7 level 'emerg' + set system syslog global archive file '2' + set system syslog global archive size '111' + set system syslog global facility cron level 'debug' + set system syslog global facility local7 level 'debug' + set system syslog global marker interval '111' + set system syslog global preserve-fqdn + set system syslog host 10.0.2.12 facility all protocol 'udp' + set system syslog host 10.0.2.15 facility all level 'all' + set system syslog host 10.0.2.15 facility all protocol 'udp' + set system syslog host 10.0.2.15 port '122' + set system syslog user paul facility local7 level 'err' + set system syslog user vyos facility local6 level 'alert' + set system syslog user vyos facility local7 level 'debug' + """ + ) + playbook = dict(config=dict()) + compare_cmds = ["delete system syslog"] + playbook["state"] = "deleted" + set_module_args(playbook) + result = self.execute_module(changed=True) + self.maxDiff = None + self.assertEqual(sorted(result["commands"]), sorted(compare_cmds)) + + def test_vyos_logging_global_replaced(self): + """ + passing all commands as have and expecting [] commands + """ + self.execute_show_command.return_value = dedent( + """\ + set system syslog console facility all + set system syslog console facility local7 level 'err' + set system syslog console facility news level 'debug' + set system syslog file xyz + set system syslog file abc archive size '125' + set system syslog file def archive file '2' + set system syslog file def facility local6 level 'emerg' + set system syslog file def facility local7 level 'emerg' + set system syslog global archive file '2' + set system syslog global archive size '111' + set system syslog global facility cron level 'debug' + set system syslog global facility local7 level 'debug' + set system syslog global marker interval '111' + set system syslog global preserve-fqdn + set system syslog host 10.0.2.12 facility all protocol 'udp' + set system syslog host 10.0.2.15 facility all level 'all' + set system syslog host 10.0.2.15 facility all protocol 'udp' + set system syslog host 10.0.2.15 port '122' + set system syslog user paul facility local7 level 'err' + set system syslog user vyos facility local6 level 'alert' + set system syslog user vyos facility local7 level 'debug' + """ + ) + playbook = dict( + config=dict( + console=dict( + facilities=[dict(facility="local7", severity="emerg")] + ), + files=[ + dict( + path="abc", + archive=dict(file_num=2), + facilities=[ + dict(facility="local6", severity="err"), + dict(facility="local7", severity="emerg"), + ], + ) + ], + ) + ) + compare_cmds = [ + "delete system syslog console facility all", + "delete system syslog console facility local7", + "delete system syslog console facility news", + "delete system syslog file def", + "delete system syslog file xyz", + "delete system syslog global facility cron", + "delete system syslog global facility local7", + "delete system syslog global archive file 2", + "delete system syslog global archive size 111", + "delete system syslog global marker", + "delete system syslog global preserve-fqdn", + "delete system syslog host 10.0.2.12", + "delete system syslog host 10.0.2.15", + "delete system syslog user paul", + "delete system syslog user vyos", + "set system syslog console facility local7 level emerg", + "set system syslog file abc facility local6 level err", + "set system syslog file abc facility local7 level emerg", + "delete system syslog file abc archive size 125", + "set system syslog file abc archive file 2", + ] + + playbook["state"] = "replaced" + set_module_args(playbook) + result = self.execute_module(changed=True) + self.maxDiff = None + self.assertEqual(sorted(result["commands"]), sorted(compare_cmds)) + + def test_vyos_logging_global_replaced_idempotent(self): + """ + passing all commands as have and expecting [] commands + """ + self.execute_show_command.return_value = dedent( + """\ + set system syslog console facility local6 + """ + ) + playbook = dict( + config=dict(console=dict(facilities=[dict(facility="local6")])) + ) + compare_cmds = [] + playbook["state"] = "replaced" + set_module_args(playbook) + result = self.execute_module(changed=False) + self.maxDiff = None + self.assertEqual(sorted(result["commands"]), sorted(compare_cmds)) + + def test_vyos_logging_global_overridden(self): + self.execute_show_command.return_value = dedent( + """\ + set system syslog console + set system syslog global + """ + ) + playbook = dict( + config=dict( + console=dict( + facilities=[dict(facility="local7", severity="emerg")] + ), + files=[ + dict( + path="abc", + archive=dict(file_num=2), + facilities=[ + dict(facility="local6", severity="err"), + dict(facility="local7", severity="emerg"), + ], + ) + ], + ) + ) + compare_cmds = [ + "set system syslog console facility local7 level emerg", + "set system syslog file abc facility local6 level err", + "set system syslog file abc facility local7 level emerg", + "set system syslog file abc archive file 2", + ] + playbook["state"] = "overridden" + set_module_args(playbook) + result = self.execute_module(changed=True) + print(result["commands"]) + self.maxDiff = None + self.assertEqual(sorted(result["commands"]), sorted(compare_cmds)) + + def test_vyos_logging_global_rendered(self): + playbook = dict( + config=dict( + console=dict(facilities=[dict(facility="all")]), + hosts=[ + dict( + hostname="10.0.2.16", + facilities=[dict(facility="local6")], + ) + ], + users=[ + dict(username="vyos"), + dict( + username="paul", facilities=[dict(facility="local7")] + ), + ], + ) + ) + compare_cmds = [ + "set system syslog console facility all", + "set system syslog host 10.0.2.16 facility local6", + "set system syslog user vyos", + "set system syslog user paul facility local7", + ] + playbook["state"] = "rendered" + set_module_args(playbook) + result = self.execute_module() + self.maxDiff = None + self.assertEqual(sorted(result["rendered"]), sorted(compare_cmds)) + + def test_vyos_logging_global_parsed(self): + set_module_args( + dict( + running_config=dedent( + """\ + set system syslog console facility all + set system syslog file xyz + """ + ), + state="parsed", + ) + ) + parsed = dict( + console=dict(facilities=[dict(facility="all")]), + files=[dict(path="xyz")], + ) + result = self.execute_module(changed=False) + self.maxDiff = None + self.assertEqual(sorted(result["parsed"]), sorted(parsed)) + + def test_vyos_logging_global_gathered(self): + self.execute_show_command.return_value = dedent( + """\ + set system syslog console facility all + """ + ) + set_module_args(dict(state="gathered")) + gathered = dict(console=dict(facilities=[dict(facility="all")])) + result = self.execute_module(changed=False) + + self.maxDiff = None + self.assertEqual(sorted(result["gathered"]), sorted(gathered))