diff --git a/README.md b/README.md index 77b0d7b7..672ae96d 100644 --- a/README.md +++ b/README.md @@ -1,232 +1,247 @@ # VyOS Collection -[![Codecov](https://codecov.io/gh/ansible-collections/vyos.vyos/branch/main/graph/badge.svg)](https://codecov.io/gh/ansible-collections/vyos.vyos) -[![CI](https://github.com/ansible-collections/vyos.vyos/actions/workflows/tests.yml/badge.svg?branch=main&event=schedule)](https://github.com/ansible-collections/vyos.vyos/actions/workflows/tests.yml) +[![Codecov](https://codecov.io/gh/vyos/vyos.vyos/branch/main/graph/badge.svg)](https://codecov.io/gh/ansible-collections/vyos.vyos) +[![CI](https://github.com/vyos/vyos.vyos/actions/workflows/tests.yml/badge.svg?branch=main&event=schedule)](https://github.com/vyos/vyos.vyos/actions/workflows/tests.yml) 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). +This collection has been tested against VyOS 1.3.8, 1.4.1 and the current rolling release for 1.5. Where possible, +compatibility with older versions of VyOS are maintained but not guaranteed. ## Communication -* Join the Ansible forum: - * [Get Help](https://forum.ansible.com/c/help/6): get help or help others. - * [Posts tagged with 'vyos'](https://forum.ansible.com/tag/vyos): subscribe to participate in collection-related conversations. - * [Social Spaces](https://forum.ansible.com/c/chat/4): gather and interact with fellow enthusiasts. - * [News & Announcements](https://forum.ansible.com/c/news/5): track project-wide announcements including social events. +* Join the VyOS forum: + * [FAQ](https://forum.vyos.io/faq): find answers to frequently asked questions. + * [Guides and How To](https://forum.vyos.io/c/howto-guies/27): find guides and how-to articles. + * [News & Announcements](https://forum.vyos.io/c/announcements/6): track project-wide announcements . -* The Ansible [Bullhorn newsletter](https://docs.ansible.com/ansible/devel/community/communication.html#the-bullhorn): used to announce releases and important changes. - -For more information about communication, see the [Ansible communication guide](https://docs.ansible.com/ansible/devel/community/communication.html). ## Ansible version compatibility This collection has been tested against following Ansible versions: **>=2.15.0**. For collections that support Ansible 2.9, please ensure you update your `network_os` to use the fully qualified collection name (for example, `cisco.ios.ios`). 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_hostname](https://github.com/ansible-collections/vyos.vyos/blob/main/docs/vyos.vyos.vyos_hostname_module.rst)|Manages hostname resource module [vyos.vyos.vyos_interfaces](https://github.com/ansible-collections/vyos.vyos/blob/main/docs/vyos.vyos.vyos_interfaces_module.rst)|Manages interface attributes of 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)|Layer 3 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_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_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_ntp_global](https://github.com/ansible-collections/vyos.vyos/blob/main/docs/vyos.vyos.vyos_ntp_global_module.rst)|NTP global 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_snmp_server](https://github.com/ansible-collections/vyos.vyos/blob/main/docs/vyos.vyos.vyos_snmp_server_module.rst)|Manages snmp_server resource module [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. +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/vyos/vyos.vyos). See [Contributing to VyOS](https://vyos.net/contribute/) 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 +- Forum - https://forum.vyos.io -See the [Ansible Community Guide](https://docs.ansible.com/ansible/latest/community/index.html) for details on contributing to Ansible. +See the [Contributing to VyOS](https://vyos.net/contribute/) 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. ### Updating from resource module models Some of our modules were templated using `resource_module_builder`, but some use the newer [`cli_rm_builder`](https://github.com/ansible-network/cli_rm_builder) which tempaltes baed on in-place device information, but also uses a new network parsing engine designed to simplify and standardize the parsing of network configuration. #### Using older *resource_module_builder* modules Last build was with a slightly-modified version of resource_module_builder. This changes the calling parameters for the resources. To update the collection from the resource module models, run the following command: ```bash ansible-playbook -e rm_dest=`pwd` \ -e structure=collection \ -e collection_org=vyos \ -e collection_name=vyos \ -e model=../../../resource_module_models/models/vyos/firewall_rules/vyos_firewall_rules.yaml \ ../../../resource_module_builder/site.yml ``` #### Using *cli_rm_builder* modules The newer `cli_rm_builder` works similarly to the older `resource_module_builder`, but pulls the information directly from the `DOCUMENTATION`, `EXAMPLES` and `RETURN` blocks in the module itself. To update the collection from the `cli_rm_builder` models, run the following command: ```bash ansible-playbook -e rm_dest=`pwd` \ -e collection_org=vyos \ -e collection_name=vyos \ -e resource=bgp_address_family \ ../../../cli_rm_builder/run.yml ``` Unlike the `resource_module_builder`, the `cli_rm_builder` does not require the `model` parameter. Instead, it uses the `resource` parameter to specify the resource to build. - - ### Testing playbooks You can use `ANSIBLE_COLLECTIONS_PATH` to test the collection locally. For example: ``` ANSIBLE_COLLECTIONS_PATHS=~/my_dev_path ansible-playbook -i inventory.network test.yml ``` ## Changelogs ## Release notes -Release notes are available [here](https://github.com/ansible-collections/vyos.vyos/blob/main/CHANGELOG.rst). +Release notes are available [here](https://github.com/vyos/vyos.vyos/blob/main/CHANGELOG.rst). ## Roadmap +Major Version | Ansible Support | VyOS Support | Details +--- | --- | --- | --- +4.1.0 | 2.15 | 1.1.2 | Final release for the 4.x series +5.0.0 | 2.16 | 1.1.2 | First relase under VyOS control as a separate collection +6.0.0 | 2.18 | 1.3.8 | *Planned* release for supporting VyOS 1.3.8+ +7.0.0 | x.xx | 1.4.x | *Prospective* release deprecating incompatible 1.3.x modules + +Note: +- Unreleased versions are not guaranteed to be released as described. +- Some modules may support a wider variety of versions depending upon the compatibility + with prior versions of VyOS. +- The roadmap is subject to change based on community feedback and contributions. + + ## More information +VyOS resources +- [Contributing to VyOS](https://vyos.net/contribute) +- [VyOS documentation](https://docs.vyos.io/en/latest/) +- [VyOS forum](https://forum.vyos.io) + + +Ansible Resources - [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/T6987-logging-changes.yml b/changelogs/fragments/T6987-logging-changes.yml new file mode 100644 index 00000000..c4b11da6 --- /dev/null +++ b/changelogs/fragments/T6987-logging-changes.yml @@ -0,0 +1,15 @@ +--- +minor_changes: + - deprecating items for 1.4+ that have moved locations + - For 1.4, `protocol` is an attribute of the syslog host, not the facility + - Fixed v1.3 and before when `protocol` and `level` were set for the same host + - Fixed integration test for `vyos_facts` which was brittle due to line dependencies in checks + - Fixed integration test for `vyos_config` due to bad commands. 1.3 frequently won't finish due + to timeouts or system failures during the tests, but 1.4 and 1.5 + +breaking_changes: + - none yet + +known_issues: + - existing code for 1.3 facility protocol and facility level are not compatible, + only one will be set and level is the priority. diff --git a/docs/vyos.vyos.vyos_logging_global_module.rst b/docs/vyos.vyos.vyos_logging_global_module.rst index 1111b6c1..6d8550a6 100644 --- a/docs/vyos.vyos.vyos_logging_global_module.rst +++ b/docs/vyos.vyos.vyos_logging_global_module.rst @@ -1,1649 +1,1670 @@ .. _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 + + + + + + +
Parameter Choices/Defaults Comments
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
+
syslog communication protocol. Version 1.3 and below.
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)
+
+ protocol + +
+ string +
+
+
    Choices: +
  • udp
  • +
  • tcp
  • +
+
+
syslog communication protocol. Version 1.4+
+
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 + - Tested against vyos 1.3.8+ - 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
Key Returned Description
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']
+
['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 debu']


Status ------ Authors ~~~~~~~ - Sagar Paul (@KB-perByte) 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 index 0be49e51..734d190e 100644 --- a/plugins/module_utils/network/vyos/argspec/logging_global/logging_global.py +++ b/plugins/module_utils/network/vyos/argspec/logging_global/logging_global.py @@ -1,371 +1,379 @@ # -*- coding: utf-8 -*- # Copyright 2024 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"}, }, + "removed_in_version": "7.0.0", + "removed_from_collection": "vyos.vyos", }, "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"], + "removed_in_version": "7.0.0", + "removed_from_collection": "vyos.vyos", }, }, }, "hostname": {"type": "str"}, + "protocol": { + "type": "str", + "choices": ["udp", "tcp"], + }, }, }, "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/logging_global.py b/plugins/module_utils/network/vyos/config/logging_global/logging_global.py index d8bfa182..f94c9195 100644 --- a/plugins/module_utils/network/vyos/config/logging_global/logging_global.py +++ b/plugins/module_utils/network/vyos/config/logging_global/logging_global.py @@ -1,221 +1,223 @@ # # -*- 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.rm_base.resource_module import ( ResourceModule, ) from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( dict_merge, get_from_dict, ) 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.facility.protocol", # 1.3 and below + "hosts.protocol", "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/rm_templates/logging_global.py b/plugins/module_utils/network/vyos/rm_templates/logging_global.py index 6c692cfd..516e270b 100644 --- a/plugins/module_utils/network/vyos/rm_templates/logging_global.py +++ b/plugins/module_utils/network/vyos/rm_templates/logging_global.py @@ -1,407 +1,455 @@ # -*- 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"): + elif 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"): + if ( + val.get("hostname") + and not val.get("archive") + and not val.get("port") + and not val.get("protocol") + ): 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.protocol", + "getval": re.compile( + r""" + ^set\ssystem\ssyslog\shost + (\s(?P\S+)) + (\sprotocol\s(?P'(udp|tcp)')) + $""", re.VERBOSE, + ), + "setval": "system syslog host {{ hosts.hostname }} protocol {{ hosts.protocol }}", + "result": { + "hosts": { + "{{ hostname }}": { + "hostname": "{{ hostname }}", + "protocol": "{{ protocol }}", + }, + }, + }, + }, + { + # Version 1.3 and below + "name": "hosts.facility.protocol", + "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])) + (\sprotocol\s(?P'(udp|tcp)')) + $""", re.VERBOSE, + ), + "setval": "system syslog host {{ hosts.hostname }} facility {{ hosts.facility }} protocol {{ hosts.protocol }}", + "remval": "system syslog host {{ hosts.hostname }} facility {{ hosts.facility }} protocol {{ hosts.protocol }}", + "result": { + "hosts": { + "{{ hostname }}": { + "hostname": "{{ hostname }}", + "facilities": [ + { + "facility": "{{ facility }}", + "protocol": "{{ protocol }}", + }, ], + }, + }, + }, + }, { "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_global.py b/plugins/modules/vyos_logging_global.py index 069d5080..9479e7b2 100644 --- a/plugins/modules/vyos_logging_global.py +++ b/plugins/modules/vyos_logging_global.py @@ -1,779 +1,785 @@ #!/usr/bin/python # -*- coding: utf-8 -*- # Copyright 2024 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 + - Tested against vyos 1.3.8+ - 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 + description: syslog communication protocol. Version 1.3 and below. type: str choices: - udp - tcp hostname: description: Remote host name or IP address type: str + protocol: + description: syslog communication protocol. Version 1.4+ + type: str + choices: + - udp + - tcp 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 I(state) is C(merged), C(replaced), C(overridden), C(deleted) or C(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 I(state) is C(merged), C(replaced), C(overridden), C(deleted) or C(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" + - 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 I(state) is C(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" + - 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 debu gathered: description: Facts about the network resource gathered from the remote device as structured data. returned: when I(state) is C(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 I(state) is C(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_config/tests/cli/check_config.yaml b/tests/integration/targets/vyos_config/tests/cli/check_config.yaml index 5e028549..8e2e8372 100644 --- a/tests/integration/targets/vyos_config/tests/cli/check_config.yaml +++ b/tests/integration/targets/vyos_config/tests/cli/check_config.yaml @@ -1,57 +1,57 @@ --- - debug: msg="START cli/config_check.yaml on connection={{ ansible_connection }}" - name: setup- ensure interface is not present vyos.vyos.vyos_config: lines: delete interfaces loopback lo - name: setup- create interface register: result vyos.vyos.vyos_config: lines: - interfaces - interfaces loopback lo - interfaces loopback lo description test - name: Check that multiple duplicate lines collapse into a single commands assert: that: - result.commands|length == 1 - name: Check that set is correctly prepended assert: that: - result.commands[0] == 'set interfaces loopback lo description test' - name: configure config_check config command register: result vyos.vyos.vyos_config: lines: delete interfaces loopback lo - assert: that: - result.changed == true - name: check config_check config command idempontent register: result vyos.vyos.vyos_config: lines: delete interfaces loopback lo - assert: that: - result.changed == false - name: check multiple line config filter is working register: result vyos.vyos.vyos_config: lines: - - set system login user esa level admin + - set system login user esa full-name 'ESA admin' - set system login user esa authentication encrypted-password '!abc!' - - set system login user vyos level admin + - set system login user vyos full-name 'VyOS admin' - set system login user vyos authentication encrypted-password 'abc' - assert: that: - result.filtered|length == 2 - debug: msg="END cli/config_check.yaml on connection={{ ansible_connection }}" diff --git a/tests/integration/targets/vyos_config/tests/redirection/cli/shortname.yaml b/tests/integration/targets/vyos_config/tests/redirection/cli/shortname.yaml index 33fb3be5..0d88d0cb 100644 --- a/tests/integration/targets/vyos_config/tests/redirection/cli/shortname.yaml +++ b/tests/integration/targets/vyos_config/tests/redirection/cli/shortname.yaml @@ -1,99 +1,99 @@ --- - debug: msg="START cli/shortname.yaml on connection={{ ansible_connection }}" - name: setup- ensure interface is not present vyos.vyos.config: lines: delete interfaces loopback lo - name: setup- create interface register: result vyos.vyos.config: lines: - interfaces - interfaces loopback lo - interfaces loopback lo description test - name: Check that multiple duplicate lines collapse into a single commands assert: that: - result.commands|length == 1 - name: Check that set is correctly prepended assert: that: - result.commands[0] == 'set interfaces loopback lo description test' - name: configure config_check config command register: result vyos.vyos.config: lines: delete interfaces loopback lo - assert: that: - result.changed == true - name: check config_check config command idempontent register: result vyos.vyos.config: lines: delete interfaces loopback lo - assert: that: - result.changed == false - name: check multiple line config filter is working register: result vyos.vyos.config: lines: - - set system login user esa level admin + - set system login user esa full-name 'ESA admin' - set system login user esa authentication encrypted-password '!abc!' - - set system login user vyos level admin + - set system login user vyos full-name 'VyOS admin' - set system login user vyos authentication encrypted-password 'abc' - assert: that: - result.filtered|length == 2 - name: Remove interface description and delete temp user vyos.vyos.config: &cleanup lines: - delete interfaces ethernet eth0 description TEST-INTF - delete system login user test_user - name: Use src with module alias register: result vyos.vyos.config: src: config.j2 - assert: that: - result.changed == true - '"set interfaces ethernet eth0 description TEST-INTF" in result.commands' - '"set system login user test_user" in result.commands' - name: Restore hostname to {{ inventory_hostname }} and delete temp user vyos.vyos.config: *cleanup - name: use module alias to take configuration backup register: result vyos.vyos.config: backup: true backup_options: filename: backup_with_alias.cfg dir_path: "{{ role_path }}/backup_test_dir/{{ inventory_hostname_short }}" - assert: that: - result.changed == true - name: check if the backup file-4 exist find: paths: "{{ role_path }}/backup_test_dir/{{ inventory_hostname_short }}/backup_with_alias.cfg" register: backup_file connection: local - assert: that: - backup_file.files is defined - debug: msg="END cli/shortname.yaml on connection={{ ansible_connection }}" diff --git a/tests/integration/targets/vyos_facts/tests/cli/basic_facts.yaml b/tests/integration/targets/vyos_facts/tests/cli/basic_facts.yaml index 232132e1..50e95889 100644 --- a/tests/integration/targets/vyos_facts/tests/cli/basic_facts.yaml +++ b/tests/integration/targets/vyos_facts/tests/cli/basic_facts.yaml @@ -1,77 +1,77 @@ --- - name: get host name register: vyos_host vyos.vyos.vyos_command: commands: - show host name - name: get version info register: vyos_version vyos.vyos.vyos_command: commands: - show version - name: collect all facts from the device register: result vyos.vyos.vyos_facts: gather_subset: all - name: check that hostname is present assert: that: - result.ansible_facts.ansible_net_hostname == vyos_host.stdout[0] - name: check that subsets are present assert: that: - "'neighbors' in result.ansible_facts.ansible_net_gather_subset" - "'default' in result.ansible_facts.ansible_net_gather_subset" - "'config' in result.ansible_facts.ansible_net_gather_subset" - name: check that version info is present assert: that: - - result.ansible_facts.ansible_net_version in vyos_version.stdout_lines[0][0] - - result.ansible_facts.ansible_net_model in vyos_version.stdout_lines[0][9] - - result.ansible_facts.ansible_net_serialnum in vyos_version.stdout_lines[0][10] + - result.ansible_facts.ansible_net_version in (vyos_version.stdout_lines[0] | select('search', 'Version:') | list | first) + - result.ansible_facts.ansible_net_model in (vyos_version.stdout_lines[0] | select('search', 'Hardware model:') | list | first) + - result.ansible_facts.ansible_net_serialnum in (vyos_version.stdout_lines[0] | select('search', 'Hardware S/N:') | list | first) - name: check that config info is present assert: that: - result.ansible_facts.ansible_net_commits is defined - result.ansible_facts.ansible_net_config is defined - name: Get list of avaliable network resources for VyOS register: result vyos.vyos.vyos_facts: available_network_resources: true gather_network_resources: all - name: Assert that correct available_resources_list returned assert: that: - result.changed == false - "{{ result['ansible_facts']['available_network_resources'] | symmetric_difference( result['ansible_facts']['ansible_net_gather_network_resources'] ) | length == 0 }}" - name: test getting default facts register: result vyos.vyos.vyos_facts: - assert: that: - result.changed == false - "'default' in result.ansible_facts.ansible_net_gather_subset" - "'config' not in result.ansible_facts.ansible_net_gather_subset" - result.ansible_facts.ansible_net_hostname is defined - result.ansible_facts.ansible_net_model is defined - result.ansible_facts.ansible_net_python_version is defined - result.ansible_facts.ansible_net_serialnum is defined - result.ansible_facts.ansible_net_system is defined - result.ansible_facts.ansible_net_version is defined - result.ansible_facts.ansible_network_resources == {} diff --git a/tests/integration/targets/vyos_facts/tests/redirection/cli/shortname.yaml b/tests/integration/targets/vyos_facts/tests/redirection/cli/shortname.yaml index 05399f1d..35233728 100644 --- a/tests/integration/targets/vyos_facts/tests/redirection/cli/shortname.yaml +++ b/tests/integration/targets/vyos_facts/tests/redirection/cli/shortname.yaml @@ -1,42 +1,42 @@ --- - name: get host name register: vyos_host vyos.vyos.command: commands: - show host name - name: get version info register: vyos_version vyos.vyos.command: commands: - show version - name: collect all facts from the device register: result vyos.vyos.facts: gather_subset: all - name: check that hostname is present assert: that: - result.ansible_facts.ansible_net_hostname == vyos_host.stdout[0] - name: check that subsets are present assert: that: - "'neighbors' in result.ansible_facts.ansible_net_gather_subset" - "'default' in result.ansible_facts.ansible_net_gather_subset" - "'config' in result.ansible_facts.ansible_net_gather_subset" - name: check that version info is present assert: that: - - result.ansible_facts.ansible_net_version in vyos_version.stdout_lines[0][0] - - result.ansible_facts.ansible_net_model in vyos_version.stdout_lines[0][9] - - result.ansible_facts.ansible_net_serialnum in vyos_version.stdout_lines[0][10] + - result.ansible_facts.ansible_net_version in (vyos_version.stdout_lines[0] | select('search', 'Version:') | list | first) + - result.ansible_facts.ansible_net_model in (vyos_version.stdout_lines[0] | select('search', 'Hardware model:') | list | first) + - result.ansible_facts.ansible_net_serialnum in (vyos_version.stdout_lines[0] | select('search', 'Hardware S/N:') | list | first) - name: check that config info is present assert: that: - result.ansible_facts.ansible_net_commits is defined - result.ansible_facts.ansible_net_config is defined diff --git a/tests/integration/targets/vyos_logging_global/tests/cli/_get_version.yaml b/tests/integration/targets/vyos_logging_global/tests/cli/_get_version.yaml new file mode 100644 index 00000000..2588b194 --- /dev/null +++ b/tests/integration/targets/vyos_logging_global/tests/cli/_get_version.yaml @@ -0,0 +1,28 @@ +- name: make sure to get facts + vyos.vyos.vyos_facts: + vars: + ansible_connection: ansible.netcommon.network_cli + register: vyos_facts + when: vyos_version is not defined + +- name: debug vyos_facts + debug: + var: vyos_facts + +- name: pull version from facts + set_fact: + vyos_version: "{{ vyos_facts.ansible_facts.ansible_net_version.split('-')[0].split(' ')[-1] }}" + when: vyos_version is not defined + +- name: fix '.0' versions + set_fact: + vyos_version: "{{ vyos_version }}.0" + when: vyos_version.count('.') == 1 + +- name: include correct vars + include_vars: pre-v1_4.yaml + when: vyos_version is version('1.4.0', '<', version_type='semver') + +- name: include correct vars + include_vars: v1_4.yaml + when: vyos_version is version('1.4.0', '>=', version_type='semver') diff --git a/tests/integration/targets/vyos_logging_global/tests/cli/_populate.yaml b/tests/integration/targets/vyos_logging_global/tests/cli/_populate.yaml index 516df94a..89fb8e51 100644 --- a/tests/integration/targets/vyos_logging_global/tests/cli/_populate.yaml +++ b/tests/integration/targets/vyos_logging_global/tests/cli/_populate.yaml @@ -1,55 +1,42 @@ --- - ansible.builtin.include_tasks: _remove_config.yaml - 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 + hosts: "{{ populate_logging_global_hosts }}" 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/merged.yaml b/tests/integration/targets/vyos_logging_global/tests/cli/merged.yaml index b4d38565..02c4c618 100644 --- a/tests/integration/targets/vyos_logging_global/tests/cli/merged.yaml +++ b/tests/integration/targets/vyos_logging_global/tests/cli/merged.yaml @@ -1,52 +1,30 @@ --- - debug: msg: START vyos_logging_global merged integration tests on connection={{ ansible_connection }} +- include_tasks: _get_version.yaml - 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 + config: "{{ merged.after }}" state: merged + - debug: + var: merged['commands'] | symmetric_difference(result['commands']) + - name: Assert that correct set of commands were generated assert: that: - "{{ merged['commands'] | symmetric_difference(result['commands']) |length == 0 }}" + - result.changed == true + - result.after == merged.after - 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 index eacdca22..b0ca2ffd 100644 --- a/tests/integration/targets/vyos_logging_global/tests/cli/overridden.yaml +++ b/tests/integration/targets/vyos_logging_global/tests/cli/overridden.yaml @@ -1,35 +1,32 @@ --- - debug: msg: START vyos_logging_global overridden integration tests on connection={{ ansible_connection }} - 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 }}" + - "result.changed == true" - 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/rendered.yaml b/tests/integration/targets/vyos_logging_global/tests/cli/rendered.yaml index 3746dd71..27d5d6e3 100644 --- a/tests/integration/targets/vyos_logging_global/tests/cli/rendered.yaml +++ b/tests/integration/targets/vyos_logging_global/tests/cli/rendered.yaml @@ -1,44 +1,41 @@ --- - debug: msg: START vyos_logging_global rendered integration tests on connection={{ ansible_connection }} - include_tasks: _populate.yaml - block: - name: Structure provided configuration into device specific commands register: result vyos.vyos.vyos_logging_global: 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 index 8d22af0b..13ca654f 100644 --- a/tests/integration/targets/vyos_logging_global/vars/main.yaml +++ b/tests/integration/targets/vyos_logging_global/vars/main.yaml @@ -1,94 +1,28 @@ --- -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/integration/targets/vyos_logging_global/vars/main.yaml b/tests/integration/targets/vyos_logging_global/vars/pre-v1_4.yaml similarity index 51% copy from tests/integration/targets/vyos_logging_global/vars/main.yaml copy to tests/integration/targets/vyos_logging_global/vars/pre-v1_4.yaml index 8d22af0b..6af72488 100644 --- a/tests/integration/targets/vyos_logging_global/vars/main.yaml +++ b/tests/integration/targets/vyos_logging_global/vars/pre-v1_4.yaml @@ -1,94 +1,68 @@ --- +host_172_16_2_15: &host_172_16_2_15 + - hostname: 172.16.2.15 + facilities: + - facility: all + severity: all + 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 + archive: + file_num: 2 + hosts: *host_172_16_2_15 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 +populate_logging_global_hosts: + - hostname: 172.16.2.15 + facilities: + - facility: all + protocol: udp + - hostname: 172.16.2.12 + facilities: + - facility: all + protocol: udp diff --git a/tests/integration/targets/vyos_logging_global/vars/main.yaml b/tests/integration/targets/vyos_logging_global/vars/v1_4.yaml similarity index 51% copy from tests/integration/targets/vyos_logging_global/vars/main.yaml copy to tests/integration/targets/vyos_logging_global/vars/v1_4.yaml index 8d22af0b..bfe5e12d 100644 --- a/tests/integration/targets/vyos_logging_global/vars/main.yaml +++ b/tests/integration/targets/vyos_logging_global/vars/v1_4.yaml @@ -1,94 +1,74 @@ --- +host_172_16_2_15: &host_172_16_2_15 + - hostname: 172.16.2.15 + facilities: + - facility: all + severity: all + protocol: tcp + merged: before: {} commands: - set system syslog host 172.16.2.15 facility all level all + - set system syslog host 172.16.2.15 protocol tcp - 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 + archive: + file_num: 2 + hosts: *host_172_16_2_15 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 protocol udp + - delete system syslog host 172.16.2.15 protocol udp - 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 +populate_logging_global_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