diff options
Diffstat (limited to 'plugins/modules')
| -rw-r--r-- | plugins/modules/vyos_firewall_rules.py | 164 | ||||
| -rw-r--r-- | plugins/modules/vyos_interfaces.py | 264 | ||||
| -rw-r--r-- | plugins/modules/vyos_l3_interfaces.py | 215 | ||||
| -rw-r--r-- | plugins/modules/vyos_lag_interfaces.py | 230 | ||||
| -rw-r--r-- | plugins/modules/vyos_lldp_global.py | 191 | ||||
| -rw-r--r-- | plugins/modules/vyos_lldp_interfaces.py | 187 | ||||
| -rw-r--r-- | plugins/modules/vyos_static_routes.py | 257 | 
7 files changed, 1113 insertions, 395 deletions
| diff --git a/plugins/modules/vyos_firewall_rules.py b/plugins/modules/vyos_firewall_rules.py index a9e676b6..9c2e832d 100644 --- a/plugins/modules/vyos_firewall_rules.py +++ b/plugins/modules/vyos_firewall_rules.py @@ -37,8 +37,9 @@ ANSIBLE_METADATA = {  }  DOCUMENTATION = """module: vyos_firewall_rules -short_description: Manage firewall rule-set attributes on VyOS devices +short_description: Firewall rules resource module  description: This module manages firewall rule-set attributes on VyOS devices +version_added: "1.0.0"  notes:  - Tested against VyOS 1.1.8 (helium).  - This module works with connection C(network_cli). See L(the VyOS OS Platform Options,../network/user_guide/platform_vyos.html). @@ -397,13 +398,12 @@ options:                      type: str    running_config:      description: -    - The module, by default, will connect to the remote device and retrieve the current -      running-config to use as a base for comparing against the contents of source. -      There are times when it is not desirable to have the task get the current running-config -      for every task in a playbook.  The I(running_config) argument allows the implementer -      to pass in the configuration to use as the base config for comparison. This -      value of this option should be the output received from device by executing -      command C(show configuration commands | grep 'firewall' +      - 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 firewall). +      - 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:      description: @@ -437,7 +437,7 @@ EXAMPLES = """  # set firewall name Downlink rule 502 ipsec 'match-ipsec'  #  - name: Delete attributes of given firewall rules. -  vyos_firewall_rules: +  vyos.vyos.vyos_firewall_rules:      config:        - afi: ipv4          rule_sets: @@ -486,12 +486,22 @@ EXAMPLES = """  # set firewall group address-group 'inbound' -# Using deleted to delete all the the firewall rules when provided config is empty +# Using deleted to delete firewall rules based on afi  #  # Before state  # -------------  #  # vyos@vyos:~$ show configuration commands| grep firewall +# set firewall ipv6-name UPLINK default-action 'accept' +# set firewall ipv6-name UPLINK description 'This is ipv6 specific rule-set' +# set firewall ipv6-name UPLINK rule 1 action 'accept' +# set firewall ipv6-name UPLINK rule 1 +# set firewall ipv6-name UPLINK rule 1 description 'Fwipv6-Rule 1 is configured by Ansible' +# set firewall ipv6-name UPLINK rule 1 ipsec 'match-ipsec' +# set firewall ipv6-name UPLINK rule 2 action 'accept' +# set firewall ipv6-name UPLINK rule 2 +# set firewall ipv6-name UPLINK rule 2 description 'Fwipv6-Rule 2 is configured by Ansible' +# set firewall ipv6-name UPLINK rule 2 ipsec 'match-ipsec'  # set firewall group address-group 'inbound'  # set firewall name Downlink default-action 'accept'  # set firewall name Downlink description 'IPv4 INBOUND rule set' @@ -501,10 +511,12 @@ EXAMPLES = """  # set firewall name Downlink rule 502 action 'reject'  # set firewall name Downlink rule 502 description 'Rule 502 is configured by Ansible'  # set firewall name Downlink rule 502 ipsec 'match-ipsec' +  #  - name: Delete attributes of given firewall rules. -  vyos_firewall_rules: +  vyos.vyos.vyos_firewall_rules:      config: +      - afi: ipv4      state: deleted  #  # @@ -514,69 +526,29 @@ EXAMPLES = """  #  #    "before": [  #        { -#            "afi": "ipv4", +#            "afi": "ipv6",  #            "rule_sets": [  #                {  #                    "default_action": "accept", -#                    "description": "IPv4 INBOUND rule set", -#                    "name": "Downlink", +#                    "description": "This is ipv6 specific rule-set", +#                    "name": "UPLINK",  #                    "rules": [  #                        {  #                            "action": "accept", -#                            "description": "Rule 501 is configured by Ansible", +#                            "description": "Fwipv6-Rule 1 is configured by Ansible",  #                            "ipsec": "match-ipsec", -#                            "number": 501 +#                            "number": 1  #                        },  #                        { -#                            "action": "reject", -#                            "description": "Rule 502 is configured by Ansible", +#                            "action": "accept", +#                            "description": "Fwipv6-Rule 2 is configured by Ansible",  #                            "ipsec": "match-ipsec", -#                            "number": 502 +#                            "number": 2  #                        }  #                    ] -#               } +#                }  #            ] -#        } -#    ] -#    "commands": [ -#        "delete firewall name" -#    ] -# -# "after": [] -# After state -# ------------ -# vyos@vyos# run show configuration commands | grep firewall -# set firewall group address-group 'inbound' - - -# Using deleted to delete the the firewall rules based on afi -# -# Before state -# ------------- -# -# vyos@vyos:~$ show configuration commands| grep firewall -# set firewall group address-group 'inbound' -# set firewall name Downlink default-action 'accept' -# set firewall name Downlink description 'IPv4 INBOUND rule set' -# set firewall name Downlink rule 501 action 'accept' -# set firewall name Downlink rule 501 description 'Rule 501 is configured by Ansible' -# set firewall name Downlink rule 501 ipsec 'match-ipsec' -# set firewall name Downlink rule 502 action 'reject' -# set firewall name Downlink rule 502 description 'Rule 502 is configured by Ansible' -# set firewall name Downlink rule 502 ipsec 'match-ipsec' -# -- name: Delete attributes of given firewall rules. -  vyos_firewall_rules: -    config: -      - afi: ipv4 -    state: deleted -# -# -# ------------------------ -# Module Execution Results -# ------------------------ -# -#    "before": [ +#        },  #        {  #            "afi": "ipv4",  #            "rule_sets": [ @@ -603,18 +575,26 @@ EXAMPLES = """  #        }  #    ]  #    "commands": [ -#        "delete firewall name", +#        "delete firewall name"  #    ]  #  # "after": []  # After state  # ------------ -# vyos@vyos# run show configuration commands | grep firewall -# set firewall group address-group 'inbound' - +# vyos@vyos:~$ show configuration commands| grep firewall +# set firewall ipv6-name UPLINK default-action 'accept' +# set firewall ipv6-name UPLINK description 'This is ipv6 specific rule-set' +# set firewall ipv6-name UPLINK rule 1 action 'accept' +# set firewall ipv6-name UPLINK rule 1 +# set firewall ipv6-name UPLINK rule 1 description 'Fwipv6-Rule 1 is configured by Ansible' +# set firewall ipv6-name UPLINK rule 1 ipsec 'match-ipsec' +# set firewall ipv6-name UPLINK rule 2 action 'accept' +# set firewall ipv6-name UPLINK rule 2 +# set firewall ipv6-name UPLINK rule 2 description 'Fwipv6-Rule 2 is configured by Ansible' +# set firewall ipv6-name UPLINK rule 2 ipsec 'match-ipsec' -# Using deleted to delete the the firewall rules based on rule number/id +# Using deleted to delete all the the firewall rules when provided config is empty  #  # Before state  # ------------- @@ -631,13 +611,8 @@ EXAMPLES = """  # set firewall name Downlink rule 502 ipsec 'match-ipsec'  #  - name: Delete attributes of given firewall rules. -  vyos_firewall_rules: +  vyos.vyos.vyos_firewall_rules:      config: -      - afi: ipv4 -        rule_sets: -          - name: 'Downlink' -            rules: -              - number: 501      state: deleted  #  # @@ -672,38 +647,14 @@ EXAMPLES = """  #        }  #    ]  #    "commands": [ -#        "delete firewall ipv6-name Downlink rule 501" +#        "delete firewall name"  #    ]  # -#    "after": [ -#        { -#            "afi": "ipv4", -#            "rule_sets": [ -#                { -#                    "default_action": "accept", -#                    "description": "IPv4 INBOUND rule set", -#                    "name": "Downlink", -#                    "rules": [ -#                        { -#                            "action": "reject", -#                            "description": "Rule 502 is configured by Ansible", -#                            "ipsec": "match-ipsec", -#                            "number": 502 -#                        } -#                    ] -#               } -#            ] -#        } -#    ] +# "after": []  # After state  # ------------ -# vyos@vyos:~$ show configuration commands| grep firewall +# vyos@vyos# run show configuration commands | grep firewall  # set firewall group address-group 'inbound' -# set firewall name Downlink default-action 'accept' -# set firewall name Downlink description 'IPv4 INBOUND rule set' -# set firewall name Downlink rule 502 action 'reject' -# set firewall name Downlink rule 502 description 'Rule 502 is configured by Ansible' -# set firewall name Downlink rule 502 ipsec 'match-ipsec'  # Using merged @@ -715,7 +666,7 @@ EXAMPLES = """  # set firewall group address-group 'inbound'  #  - name: Merge the provided configuration with the exisiting running configuration -  vyos_firewall_rules: +  vyos.vyos.vyos_firewall_rules:      config:        - afi: 'ipv6'          rule_sets: @@ -934,7 +885,7 @@ EXAMPLES = """  # set firewall name INBOUND rule 103 state related 'enable'  #  - name: Replace device configurations of listed firewall rules with provided configurations -  vyos_firewall_rules: +  vyos.vyos.vyos_firewall_rules:      config:        - afi: 'ipv6'          rule_sets: @@ -1116,7 +1067,7 @@ EXAMPLES = """  # set firewall name INBOUND rule 104 ipsec 'match-none'  #  - name: Overrides all device configuration with provided configuration -  vyos_firewall_rules: +  vyos.vyos.vyos_firewall_rules:      config:        - afi: 'ipv4'          rule_sets: @@ -1267,7 +1218,7 @@ EXAMPLES = """  # set firewall name INBOUND rule 103 state related 'enable'  #  - name: Gather listed firewall rules with provided configurations -  vyos_firewall_rules: +  vyos.vyos.vyos_firewall_rules:      config:      state: gathered  # @@ -1382,7 +1333,7 @@ EXAMPLES = """  #  #  - name: Render the commands for provided  configuration -  vyos_firewall_rules: +  vyos.vyos.vyos_firewall_rules:      config:        - afi: 'ipv6'          rule_sets: @@ -1452,8 +1403,8 @@ EXAMPLES = """  # Using parsed  #  # -- name: Render the commands for provided  configuration -  vyos_firewall_rules: +- name: Parsed the provided input commands. +  vyos.vyos.vyos_firewall_rules:      running_config:        "set firewall group address-group 'inbound'   set firewall name Downlink default-action 'accept' @@ -1546,6 +1497,7 @@ def main():      required_if = [          ("state", "merged", ("config",)),          ("state", "replaced", ("config",)), +        ("state", "rendered", ("config",)),          ("state", "overridden", ("config",)),          ("state", "parsed", ("running_config",)),      ] diff --git a/plugins/modules/vyos_interfaces.py b/plugins/modules/vyos_interfaces.py index 93df4e46..6730e306 100644 --- a/plugins/modules/vyos_interfaces.py +++ b/plugins/modules/vyos_interfaces.py @@ -30,14 +30,10 @@ from __future__ import absolute_import, division, print_function  __metaclass__ = type -ANSIBLE_METADATA = { -    "metadata_version": "1.1", -    "status": ["preview"], -    "supported_by": "network", -} +ANSIBLE_METADATA = {"metadata_version": "1.1", "supported_by": "Ansible"}  DOCUMENTATION = """module: vyos_interfaces -short_description: Manages interface attributes of VyOS network devices. +short_description: Interfaces resource module  description:  - This module manages the interface attributes on VyOS network devices.  - This module supports managing base attributes of Ethernet, Bonding, VXLAN, Loopback @@ -45,7 +41,10 @@ description:  notes:  - Tested against VyOS 1.1.8 (helium).  - This module works with connection C(network_cli). See L(the VyOS OS Platform Options,../network/user_guide/platform_vyos.html). -author: Nilashish Chakraborty (@nilashishc) +version_added: "1.0.0" +author: +- Nilashish Chakraborty (@nilashishc) +- Rohit Thakur (@rohitthakur2590)  options:    config:      description: The provided interfaces configuration. @@ -119,6 +118,15 @@ options:              - MTU for the virtual sub-interface.              - Refer to vendor documentation for valid values.              type: int +  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 interfaces). +      - 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:      description:      - The state of the configuration after module completion. @@ -128,6 +136,9 @@ options:      - replaced      - overridden      - deleted +    - rendered +    - gathered +    - parsed      default: merged  """  EXAMPLES = """ @@ -152,7 +163,7 @@ EXAMPLES = """  # set interfaces loopback lo  - name: Merge provided configuration with device configuration -  vyos_interfaces: +  vyos.vyos.vyos_interfaces:      config:        - name: eth2          description: 'Configured by Ansible' @@ -330,7 +341,7 @@ EXAMPLES = """  #  #  - name: Replace device configurations of listed interfaces with provided configurations -  vyos_interfaces: +  vyos.vyos.vyos_interfaces:      config:        - name: eth2          description: "Replaced by Ansible" @@ -515,7 +526,7 @@ EXAMPLES = """  #  #  - name: Overrides all device configuration with provided configuration -  vyos_interfaces: +  vyos.vyos.vyos_interfaces:      config:        - name: eth0          description: Outbound Interface For The Appliance @@ -700,7 +711,7 @@ EXAMPLES = """  #  #  - name: Delete attributes of given interfaces (Note - This won't delete the interfaces themselves) -  vyos_interfaces: +  vyos.vyos.vyos_interfaces:      config:        - name: bond1 @@ -838,6 +849,224 @@ EXAMPLES = """  # set interfaces loopback lo  #  # + + +# Using gathered +# +# Before state: +# ------------- +# +# vyos@192# run show configuration commands | grep interfaces +# set interfaces ethernet eth0 address 'dhcp' +# set interfaces ethernet eth0 duplex 'auto' +# set interfaces ethernet eth0 hw-id '08:00:27:50:5e:19' +# set interfaces ethernet eth0 smp_affinity 'auto' +# set interfaces ethernet eth0 speed 'auto' +# set interfaces ethernet eth1 description 'Configured by Ansible' +# set interfaces ethernet eth1 duplex 'auto' +# set interfaces ethernet eth1 mtu '1500' +# set interfaces ethernet eth1 speed 'auto' +# set interfaces ethernet eth1 vif 200 description 'VIF - 200' +# set interfaces ethernet eth2 description 'Configured by Ansible' +# set interfaces ethernet eth2 duplex 'auto' +# set interfaces ethernet eth2 mtu '1500' +# set interfaces ethernet eth2 speed 'auto' +# set interfaces ethernet eth2 vif 200 description 'VIF - 200' +# +- name: Gather listed interfaces with provided configurations +  vyos.vyos.vyos_interfaces: +    config: +    state: gathered +# +# +# ------------------------- +# Module Execution Result +# ------------------------- +# +#    "gathered": [ +#         { +#             "description": "Configured by Ansible", +#             "duplex": "auto", +#             "enabled": true, +#             "mtu": 1500, +#             "name": "eth2", +#             "speed": "auto", +#             "vifs": [ +#                 { +#                     "description": "VIF - 200", +#                     "enabled": true, +#                     "vlan_id": 200 +#                 } +#             ] +#         }, +#         { +#             "description": "Configured by Ansible", +#             "duplex": "auto", +#             "enabled": true, +#             "mtu": 1500, +#             "name": "eth1", +#             "speed": "auto", +#             "vifs": [ +#                 { +#                     "description": "VIF - 200", +#                     "enabled": true, +#                     "vlan_id": 200 +#                 } +#             ] +#         }, +#         { +#             "duplex": "auto", +#             "enabled": true, +#             "name": "eth0", +#             "speed": "auto" +#         } +#     ] +# +# +# After state: +# ------------- +# +# vyos@192# run show configuration commands | grep interfaces +# set interfaces ethernet eth0 address 'dhcp' +# set interfaces ethernet eth0 duplex 'auto' +# set interfaces ethernet eth0 hw-id '08:00:27:50:5e:19' +# set interfaces ethernet eth0 smp_affinity 'auto' +# set interfaces ethernet eth0 speed 'auto' +# set interfaces ethernet eth1 description 'Configured by Ansible' +# set interfaces ethernet eth1 duplex 'auto' +# set interfaces ethernet eth1 mtu '1500' +# set interfaces ethernet eth1 speed 'auto' +# set interfaces ethernet eth1 vif 200 description 'VIF - 200' +# set interfaces ethernet eth2 description 'Configured by Ansible' +# set interfaces ethernet eth2 duplex 'auto' +# set interfaces ethernet eth2 mtu '1500' +# set interfaces ethernet eth2 speed 'auto' +# set interfaces ethernet eth2 vif 200 description 'VIF - 200' + + +# Using rendered +# +# +- name: Render the commands for provided  configuration +  vyos.vyos.vyos_interfaces: +    config: +      - name: eth0 +        enabled: true +        duplex: auto +        speed: auto +      - name: eth1 +        description: Configured by Ansible - Interface 1 +        mtu: 1500 +        speed: auto +        duplex: auto +        enabled: true +        vifs: +          - vlan_id: 100 +            description: Eth1 - VIF 100 +            mtu: 400 +            enabled: true +          - vlan_id: 101 +            description: Eth1 - VIF 101 +            enabled: true +      - name: eth2 +        description: Configured by Ansible - Interface 2 (ADMIN DOWN) +        mtu: 600 +        enabled: false +    state: rendered +# +# +# ------------------------- +# Module Execution Result +# ------------------------- +# +# +# "rendered": [ +#         "set interfaces ethernet eth0 duplex 'auto'", +#         "set interfaces ethernet eth0 speed 'auto'", +#         "delete interfaces ethernet eth0 disable", +#         "set interfaces ethernet eth1 duplex 'auto'", +#         "delete interfaces ethernet eth1 disable", +#         "set interfaces ethernet eth1 speed 'auto'", +#         "set interfaces ethernet eth1 description 'Configured by Ansible - Interface 1'", +#         "set interfaces ethernet eth1 mtu '1500'", +#         "set interfaces ethernet eth1 vif 100 description 'Eth1 - VIF 100'", +#         "set interfaces ethernet eth1 vif 100 mtu '400'", +#         "set interfaces ethernet eth1 vif 101 description 'Eth1 - VIF 101'", +#         "set interfaces ethernet eth2 disable", +#         "set interfaces ethernet eth2 description 'Configured by Ansible - Interface 2 (ADMIN DOWN)'", +#         "set interfaces ethernet eth2 mtu '600'" +#     ] + + +# Using parsed +# +# +- name: Parse the configuration. +  vyos.vyos.vyos_interfaces: +    running_config: +      "set interfaces ethernet eth0 address 'dhcp' + set interfaces ethernet eth0 duplex 'auto' + set interfaces ethernet eth0 hw-id '08:00:27:50:5e:19' + set interfaces ethernet eth0 smp_affinity 'auto' + set interfaces ethernet eth0 speed 'auto' + set interfaces ethernet eth1 description 'Configured by Ansible' + set interfaces ethernet eth1 duplex 'auto' + set interfaces ethernet eth1 mtu '1500' + set interfaces ethernet eth1 speed 'auto' + set interfaces ethernet eth1 vif 200 description 'VIF - 200' + set interfaces ethernet eth2 description 'Configured by Ansible' + set interfaces ethernet eth2 duplex 'auto' + set interfaces ethernet eth2 mtu '1500' + set interfaces ethernet eth2 speed 'auto' + set interfaces ethernet eth2 vif 200 description 'VIF - 200'" +    state: parsed +# +# +# ------------------------- +# Module Execution Result +# ------------------------- +# +# +# "parsed": [ +#         { +#             "description": "Configured by Ansible", +#             "duplex": "auto", +#             "enabled": true, +#             "mtu": 1500, +#             "name": "eth2", +#             "speed": "auto", +#             "vifs": [ +#                 { +#                     "description": "VIF - 200", +#                     "enabled": true, +#                     "vlan_id": 200 +#                 } +#             ] +#         }, +#         { +#             "description": "Configured by Ansible", +#             "duplex": "auto", +#             "enabled": true, +#             "mtu": 1500, +#             "name": "eth1", +#             "speed": "auto", +#             "vifs": [ +#                 { +#                     "description": "VIF - 200", +#                     "enabled": true, +#                     "vlan_id": 200 +#                 } +#             ] +#         }, +#         { +#             "duplex": "auto", +#             "enabled": true, +#             "name": "eth0", +#             "speed": "auto" +#         } +#     ] + +  """  RETURN = """  before: @@ -879,8 +1108,19 @@ def main():      :returns: the result form module invocation      """ +    required_if = [ +        ("state", "merged", ("config",)), +        ("state", "replaced", ("config",)), +        ("state", "rendered", ("config",)), +        ("state", "overridden", ("config",)), +        ("state", "parsed", ("running_config",)), +    ] +    mutually_exclusive = [("config", "running_config")]      module = AnsibleModule( -        argument_spec=InterfacesArgs.argument_spec, supports_check_mode=True +        argument_spec=InterfacesArgs.argument_spec, +        required_if=required_if, +        supports_check_mode=True, +        mutually_exclusive=mutually_exclusive,      )      result = Interfaces(module).execute_module() diff --git a/plugins/modules/vyos_l3_interfaces.py b/plugins/modules/vyos_l3_interfaces.py index a77ecaf7..47242405 100644 --- a/plugins/modules/vyos_l3_interfaces.py +++ b/plugins/modules/vyos_l3_interfaces.py @@ -37,12 +37,14 @@ ANSIBLE_METADATA = {  }  DOCUMENTATION = """module: vyos_l3_interfaces -short_description: Manages L3 interface attributes of VyOS network devices. +short_description: L3 interfaces resource module  description: This module manages the L3 interface attributes on VyOS network devices.  notes:  - Tested against VyOS 1.1.8 (helium).  - This module works with connection C(network_cli). See L(the VyOS OS Platform Options,../network/user_guide/platform_vyos.html). -author: Nilashish Chakraborty (@NilashishC) +author: +- Nilashish Chakraborty (@NilashishC) +- Rohit Thakur (@rohitthakur2590)  options:    config:      description: The provided L3 interfaces configuration. @@ -104,6 +106,16 @@ options:                  description:                  - IPv6 address of the virtual interface.                  type: str +  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 -e eth[2,3]). +      - 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 +    version_added: "1.0.0"    state:      description:      - The state of the configuration after module completion. @@ -113,6 +125,9 @@ options:      - replaced      - overridden      - deleted +    - parsed +    - gathered +    - rendered      default: merged  """  EXAMPLES = """ @@ -128,7 +143,7 @@ EXAMPLES = """  # set interfaces ethernet eth3 vif 102  - name: Merge provided configuration with device configuration -  vyos_l3_interfaces: +  vyos.vyos.vyos_l3_interfaces:      config:        - name: eth2          ipv4: @@ -196,7 +211,7 @@ EXAMPLES = """  # set interfaces ethernet eth3 vif 102 address '2001:db8:4000::2/34'  #  - name: Replace device configurations of listed interfaces with provided configurations -  vyos_l3_interfaces: +  vyos.vyos.vyos_l3_interfaces:      config:        - name: eth2          ipv4: @@ -252,7 +267,7 @@ EXAMPLES = """  # set interfaces ethernet eth3 vif 102 address '2001:db8:4000::2/34'  - name: Overrides all device configuration with provided configuration -  vyos_l3_interfaces: +  vyos.vyos.vyos_l3_interfaces:      config:        - name: eth0          ipv4: @@ -303,7 +318,7 @@ EXAMPLES = """  # set interfaces ethernet eth3 vif 102 address '2001:db8:4000::2/34'  - name: Delete L3 attributes of given interfaces (Note - This won't delete the interface itself) -  vyos_l3_interfaces: +  vyos.vyos.vyos_l3_interfaces:      config:        - name: eth1        - name: eth2 @@ -326,6 +341,180 @@ EXAMPLES = """  # set interfaces ethernet eth3 smp_affinity 'auto' +# Using gathered +# +# Before state: +# ------------- +# +# vyos:~$ show configuration commands | grep -e eth[2,3,0] +# set interfaces ethernet eth0 address 'dhcp' +# set interfaces ethernet eth0 duplex 'auto' +# set interfaces ethernet eth0 hw-id '08:00:27:50:5e:19' +# set interfaces ethernet eth0 smp_affinity 'auto' +# set interfaces ethernet eth0 speed 'auto' +# set interfaces ethernet eth1 address '192.0.2.14/24' +# set interfaces ethernet eth2 address '192.0.2.11/24' +# set interfaces ethernet eth2 address '192.0.2.10/24' +# set interfaces ethernet eth2 address '2001:db8::10/32' +# set interfaces ethernet eth2 address '2001:db8::12/32' +# +- name: Gather listed l3 interfaces with provided configurations +  vyos.vyos.vyos_l3_interfaces: +    config: +    state: gathered +# +# +# ------------------------- +# Module Execution Result +# ------------------------- +# +#    "gathered": [ +#         { +#             "ipv4": [ +#                 { +#                     "address": "192.0.2.11/24" +#                 }, +#                 { +#                     "address": "192.0.2.10/24" +#                 } +#             ], +#             "ipv6": [ +#                 { +#                     "address": "2001:db8::10/32" +#                 }, +#                 { +#                     "address": "2001:db8::12/32" +#                 } +#             ], +#             "name": "eth2" +#         }, +#         { +#             "ipv4": [ +#                 { +#                     "address": "192.0.2.14/24" +#                 } +#             ], +#             "name": "eth1" +#         }, +#         { +#             "ipv4": [ +#                 { +#                     "address": "dhcp" +#                 } +#             ], +#             "name": "eth0" +#         } +#     ] +# +# +# After state: +# ------------- +# +# vyos:~$ show configuration commands | grep -e eth[2,3] +# set interfaces ethernet eth0 address 'dhcp' +# set interfaces ethernet eth0 duplex 'auto' +# set interfaces ethernet eth0 hw-id '08:00:27:50:5e:19' +# set interfaces ethernet eth0 smp_affinity 'auto' +# set interfaces ethernet eth0 speed 'auto' +# set interfaces ethernet eth1 address '192.0.2.14/24' +# set interfaces ethernet eth2 address '192.0.2.11/24' +# set interfaces ethernet eth2 address '192.0.2.10/24' +# set interfaces ethernet eth2 address '2001:db8::10/32' +# set interfaces ethernet eth2 address '2001:db8::12/32' + + +# Using rendered +# +# +- name: Render the commands for provided  configuration +  vyos.vyos.vyos_l3_interfaces: +    config: +      - name: eth1 +        ipv4: +          - address: 192.0.2.14/24 +      - name: eth2 +        ipv4: +          - address: 192.0.2.10/24 +          - address: 192.0.2.11/24 +        ipv6: +          - address: 2001:db8::10/32 +          - address: 2001:db8::12/32 +    state: rendered +# +# +# ------------------------- +# Module Execution Result +# ------------------------- +# +# +# "rendered": [ +#         "set interfaces ethernet eth1 address '192.0.2.14/24'", +#         "set interfaces ethernet eth2 address '192.0.2.11/24'", +#         "set interfaces ethernet eth2 address '192.0.2.10/24'", +#         "set interfaces ethernet eth2 address '2001:db8::10/32'", +#         "set interfaces ethernet eth2 address '2001:db8::12/32'" +#     ] + + +# Using parsed +# +# +- name: parse the provided running configuration +  vyos.vyos.vyos_l3_interfaces: +    running_config: +      "set interfaces ethernet eth0 address 'dhcp' + set interfaces ethernet eth1 address '192.0.2.14/24' + set interfaces ethernet eth2 address '192.0.2.10/24' + set interfaces ethernet eth2 address '192.0.2.11/24' + set interfaces ethernet eth2 address '2001:db8::10/32' + set interfaces ethernet eth2 address '2001:db8::12/32'" +    state: parsed +# +# +# ------------------------- +# Module Execution Result +# ------------------------- +# +# +# "parsed": [ +#         { +#             "ipv4": [ +#                 { +#                     "address": "192.0.2.10/24" +#                 }, +#                 { +#                     "address": "192.0.2.11/24" +#                 } +#             ], +#             "ipv6": [ +#                 { +#                     "address": "2001:db8::10/32" +#                 }, +#                 { +#                     "address": "2001:db8::12/32" +#                 } +#             ], +#             "name": "eth2" +#         }, +#         { +#             "ipv4": [ +#                 { +#                     "address": "192.0.2.14/24" +#                 } +#             ], +#             "name": "eth1" +#         }, +#         { +#             "ipv4": [ +#                 { +#                     "address": "dhcp" +#                 } +#             ], +#             "name": "eth0" +#         } +#     ] + +  """  RETURN = """  before: @@ -365,8 +554,20 @@ def main():      :returns: the result form module invocation      """ +    required_if = [ +        ("state", "merged", ("config",)), +        ("state", "replaced", ("config",)), +        ("state", "rendered", ("config",)), +        ("state", "overridden", ("config",)), +        ("state", "parsed", ("running_config",)), +    ] +    mutually_exclusive = [("config", "running_config")] +      module = AnsibleModule( -        argument_spec=L3_interfacesArgs.argument_spec, supports_check_mode=True +        argument_spec=L3_interfacesArgs.argument_spec, +        required_if=required_if, +        supports_check_mode=True, +        mutually_exclusive=mutually_exclusive,      )      result = L3_interfaces(module).execute_module() diff --git a/plugins/modules/vyos_lag_interfaces.py b/plugins/modules/vyos_lag_interfaces.py index 84f3d018..1ba511c9 100644 --- a/plugins/modules/vyos_lag_interfaces.py +++ b/plugins/modules/vyos_lag_interfaces.py @@ -30,16 +30,13 @@ from __future__ import absolute_import, division, print_function  __metaclass__ = type -ANSIBLE_METADATA = { -    "metadata_version": "1.1", -    "status": ["preview"], -    "supported_by": "network", -} +ANSIBLE_METADATA = {"metadata_version": "1.1", "supported_by": "Ansible"}  DOCUMENTATION = """module: vyos_lag_interfaces -short_description: Manages attributes of link aggregation groups on VyOS network devices. +short_description: LAG interfaces resource module  description: This module manages attributes of link aggregation groups on VyOS network    devices. +version_added: "1.0.0"  notes:  - Tested against VyOS 1.1.8 (helium).  - This module works with connection C(network_cli). See L(the VyOS OS Platform Options,../network/user_guide/platform_vyos.html). @@ -100,6 +97,15 @@ options:              description:              - IP address to use for ARP monitoring.              type: list +  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 bond). +      - 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:      description:      - The state of the configuration after module completion. @@ -109,6 +115,9 @@ options:      - replaced      - overridden      - deleted +    - parsed +    - gathered +    - rendered      default: merged  """  EXAMPLES = """ @@ -122,7 +131,7 @@ EXAMPLES = """  # set interfaces bonding bond3  #  - name: Merge provided configuration with device configuration -  vyos_lag_interfaces: +  vyos.vyos.vyos_lag_interfaces:      config:        - name: bond2          mode: active-backup @@ -226,7 +235,7 @@ EXAMPLES = """  # set interfaces ethernet eth3 bond-group 'bond3'  #  - name: Replace device configurations of listed LAGs with provided configurations -  vyos_lag_interfaces: +  vyos.vyos.vyos_lag_interfaces:      config:        - name: bond3          mode: '802.3ad' @@ -331,7 +340,7 @@ EXAMPLES = """  # set interfaces ethernet eth3 bond-group 'bond3'  #  - name: Overrides all device configuration with provided configuration -  vyos_lag_interfaces: +  vyos.vyos.vyos_lag_interfaces:      config:        - name: bond3          mode: active-backup @@ -441,7 +450,7 @@ EXAMPLES = """  # set interfaces ethernet eth3 bond-group 'bond3'  #  - name: Delete LAG attributes of given interfaces (Note This won't delete the interface itself) -  vyos_lag_interfaces: +  vyos.vyos.vyos_lag_interfaces:      config:        - name: bond2        - name: bond3 @@ -507,6 +516,202 @@ EXAMPLES = """  # set interfaces bonding bond3 +# Using gathered +# +# Before state: +# ------------- +# +# vyos@192# run show configuration commands | grep bond +# set interfaces bonding bond0 hash-policy 'layer2' +# set interfaces bonding bond0 mode 'active-backup' +# set interfaces bonding bond0 primary 'eth1' +# set interfaces bonding bond1 hash-policy 'layer2+3' +# set interfaces bonding bond1 mode 'active-backup' +# set interfaces bonding bond1 primary 'eth2' +# set interfaces ethernet eth1 bond-group 'bond0' +# set interfaces ethernet eth2 bond-group 'bond1' +# +- name: Gather listed  lag interfaces with provided configurations +  vyos.vyos.vyos_lag_interfaces: +    config: +    state: gathered +# +# +# ------------------------- +# Module Execution Result +# ------------------------- +# +#    "gathered": [ +#        { +#            "afi": "ipv6", +#            "rule_sets": [ +#                { +#                    "default_action": "accept", +#                    "description": "This is ipv6 specific rule-set", +#                    "name": "UPLINK", +#                    "rules": [ +#                        { +#                            "action": "accept", +#                            "description": "Fwipv6-Rule 1 is configured by Ansible", +#                            "ipsec": "match-ipsec", +#                            "number": 1 +#                        }, +#                        { +#                            "action": "accept", +#                            "description": "Fwipv6-Rule 2 is configured by Ansible", +#                            "ipsec": "match-ipsec", +#                            "number": 2 +#                        } +#                    ] +#                } +#            ] +#        }, +#        { +#            "afi": "ipv4", +#            "rule_sets": [ +#                { +#                    "default_action": "accept", +#                    "description": "IPv4 INBOUND rule set", +#                    "name": "INBOUND", +#                    "rules": [ +#                        { +#                            "action": "accept", +#                            "description": "Rule 101 is configured by Ansible", +#                            "ipsec": "match-ipsec", +#                            "number": 101 +#                        }, +#                        { +#                            "action": "reject", +#                            "description": "Rule 102 is configured by Ansible", +#                            "ipsec": "match-ipsec", +#                            "number": 102 +#                        }, +#                        { +#                            "action": "accept", +#                            "description": "Rule 103 is configured by Ansible", +#                            "destination": { +#                                "group": { +#                                    "address_group": "inbound" +#                                } +#                            }, +#                            "number": 103, +#                            "source": { +#                                "address": "192.0.2.0" +#                            }, +#                            "state": { +#                                "established": true, +#                                "invalid": false, +#                                "new": false, +#                                "related": true +#                            } +#                        } +#                    ] +#                } +#            ] +#        } +#    ] +# +# +# After state: +# ------------- +# +# vyos@192# run show configuration commands | grep bond +# set interfaces bonding bond0 hash-policy 'layer2' +# set interfaces bonding bond0 mode 'active-backup' +# set interfaces bonding bond0 primary 'eth1' +# set interfaces bonding bond1 hash-policy 'layer2+3' +# set interfaces bonding bond1 mode 'active-backup' +# set interfaces bonding bond1 primary 'eth2' +# set interfaces ethernet eth1 bond-group 'bond0' +# set interfaces ethernet eth2 bond-group 'bond1' + + +# Using rendered +# +# +- name: Render the commands for provided  configuration +  vyos.vyos.vyos_lag_interfaces: +    config: +       - name: bond0 +         hash_policy: layer2 +         members: +           - member: eth1 +         mode: active-backup +         primary: eth1 +       - name: bond1 +         hash_policy: layer2+3 +         members: +           - member: eth2 +         mode: active-backup +         primary: eth2 +    state: rendered +# +# +# ------------------------- +# Module Execution Result +# ------------------------- +# +# +# "rendered": [ +#        "set interfaces bonding bond0 hash-policy 'layer2'", +#        "set interfaces ethernet eth1 bond-group 'bond0'", +#        "set interfaces bonding bond0 mode 'active-backup'", +#        "set interfaces bonding bond0 primary 'eth1'", +#        "set interfaces bonding bond1 hash-policy 'layer2+3'", +#        "set interfaces ethernet eth2 bond-group 'bond1'", +#        "set interfaces bonding bond1 mode 'active-backup'", +#        "set interfaces bonding bond1 primary 'eth2'" +#    ] + + +# Using parsed +# +# +- name: Parsed the commands for provided  configuration +  vyos.vyos.vyos_l3_interfaces: +    running_config: +      "set interfaces bonding bond0 hash-policy 'layer2' + set interfaces bonding bond0 mode 'active-backup' + set interfaces bonding bond0 primary 'eth1' + set interfaces bonding bond1 hash-policy 'layer2+3' + set interfaces bonding bond1 mode 'active-backup' + set interfaces bonding bond1 primary 'eth2' + set interfaces ethernet eth1 bond-group 'bond0' + set interfaces ethernet eth2 bond-group 'bond1'" +    state: parsed +# +# +# ------------------------- +# Module Execution Result +# ------------------------- +# +# +# "parsed": [ +#         { +#             "hash_policy": "layer2", +#             "members": [ +#                 { +#                     "member": "eth1" +#                 } +#             ], +#             "mode": "active-backup", +#             "name": "bond0", +#             "primary": "eth1" +#         }, +#         { +#             "hash_policy": "layer2+3", +#             "members": [ +#                 { +#                     "member": "eth2" +#                 } +#             ], +#             "mode": "active-backup", +#             "name": "bond1", +#             "primary": "eth2" +#         } +#     ] + +  """  RETURN = """  before: @@ -551,12 +756,17 @@ def main():      required_if = [          ("state", "merged", ("config",)),          ("state", "replaced", ("config",)), +        ("state", "rendered", ("config",)),          ("state", "overridden", ("config",)), +        ("state", "parsed", ("running_config",)),      ] +    mutually_exclusive = [("config", "running_config")] +      module = AnsibleModule(          argument_spec=Lag_interfacesArgs.argument_spec,          required_if=required_if,          supports_check_mode=True, +        mutually_exclusive=mutually_exclusive,      )      result = Lag_interfaces(module).execute_module() diff --git a/plugins/modules/vyos_lldp_global.py b/plugins/modules/vyos_lldp_global.py index 08eb1133..3a93c955 100644 --- a/plugins/modules/vyos_lldp_global.py +++ b/plugins/modules/vyos_lldp_global.py @@ -30,17 +30,13 @@ from __future__ import absolute_import, division, print_function  __metaclass__ = type -ANSIBLE_METADATA = { -    "metadata_version": "1.1", -    "status": ["preview"], -    "supported_by": "network", -} +ANSIBLE_METADATA = {"metadata_version": "1.1", "supported_by": "Ansible"}  DOCUMENTATION = """module: vyos_lldp_global -short_description: Manage link layer discovery protocol (LLDP) attributes on VyOS -  devices.. +short_description: LLDP global resource module  description: This module manages link layer discovery protocol (LLDP) attributes on    VyOS devices. +version_added: "1.0.0"  notes:  - Tested against VyOS 1.1.8 (helium).  - This module works with connection C(network_cli). See L(the VyOS OS Platform Options,../network/user_guide/platform_vyos.html). @@ -72,6 +68,15 @@ options:          - edp          - fdp          - sonmp +  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 lldp). +      - 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:      description:      - The state of the configuration after module completion. @@ -80,6 +85,9 @@ options:      - merged      - replaced      - deleted +    - gathered +    - rendered +    - parsed      default: merged  """  EXAMPLES = """ @@ -89,10 +97,9 @@ EXAMPLES = """  # -------------  #  # vyos@vyos:~$ show configuration commands|grep lldp -# vyos@vyos:~$  #  - name: Merge provided configuration with device configuration -  vyos_lldp_global: +  vyos.vyos.vyos_lldp_global:      config:        legacy_protocols:          - 'fdp' @@ -154,7 +161,7 @@ EXAMPLES = """  # set service lldp snmp enable  #  - name: Replace device configurations with provided configurations -  vyos_lldp_global: +  vyos.vyos.vyos_lldp_global:      config:        legacy_protocols:          - 'edp' @@ -231,7 +238,7 @@ EXAMPLES = """  # set service lldp management-address '192.0.2.14'  #  - name: Delete attributes of given lldp service (This won't delete the LLDP service itself) -  vyos_lldp_global: +  vyos.vyos.vyos_lldp_global:      config:      state: deleted  # @@ -273,6 +280,163 @@ EXAMPLES = """  # set service lldp +# Using gathered +# +# Before state: +# ------------- +# +# vyos@192# run show configuration commands | grep lldp +# set service lldp legacy-protocols 'cdp' +# set service lldp management-address '192.0.2.17' +# +- name: Gather lldp global config with provided configurations +  vyos.vyos.vyos_lldp_global: +    config: +    state: gathered +# +# +# ------------------------- +# Module Execution Result +# ------------------------- +# +#    "gathered": [ +# { +#        "config_trap": true, +#        "group": { +#            "address_group": [ +#                { +#                    "description": "Sales office hosts address list", +#                    "members": [ +#                        { +#                            "address": "192.0.3.1" +#                        }, +#                        { +#                            "address": "192.0.3.2" +#                        } +#                    ], +#                    "name": "ENG-HOSTS" +#                }, +#                { +#                    "description": "Sales office hosts address list", +#                    "members": [ +#                        { +#                            "address": "192.0.2.1" +#                        }, +#                        { +#                            "address": "192.0.2.2" +#                        }, +#                        { +#                            "address": "192.0.2.3" +#                        } +#                    ], +#                    "name": "SALES-HOSTS" +#                } +#            ], +#            "network_group": [ +#                { +#                    "description": "This group has the Management network addresses", +#                    "members": [ +#                        { +#                            "address": "192.0.1.0/24" +#                        } +#                    ], +#                    "name": "MGMT" +#                } +#            ] +#        }, +#        "log_martians": true, +#        "ping": { +#            "all": true, +#            "broadcast": true +#        }, +#        "route_redirects": [ +#            { +#                "afi": "ipv4", +#                "icmp_redirects": { +#                    "receive": false, +#                    "send": true +#                }, +#                "ip_src_route": true +#            } +#        ], +#        "state_policy": [ +#            { +#                "action": "accept", +#                "connection_type": "established", +#                "log": true +#            }, +#            { +#                "action": "reject", +#                "connection_type": "invalid" +#            } +#        ], +#        "syn_cookies": true, +#        "twa_hazards_protection": true, +#        "validation": "strict" +#    } +# +# After state: +# ------------- +# +# vyos@192# run show configuration commands | grep lldp +# set service lldp legacy-protocols 'cdp' +# set service lldp management-address '192.0.2.17' + + +# Using rendered +# +# +- name: Render the commands for provided  configuration +  vyos.vyos.vyos_lldp_global: +    config: +      address: 192.0.2.17 +      enable: true +      legacy_protocols: +        - cdp +    state: rendered +# +# +# ------------------------- +# Module Execution Result +# ------------------------- +# +# +# "rendered": [ +#         "set service lldp legacy-protocols 'cdp'", +#         "set service lldp", +#         "set service lldp management-address '192.0.2.17'" +#     ] +# + + +# Using parsed +# +# +- name: Parse the provided commands to provide structured configuration +  vyos.vyos.vyos_lldp_global: +    running_config: +      "set service lldp legacy-protocols 'cdp' + set service lldp legacy-protocols 'fdp' + set service lldp management-address '192.0.2.11'" +    state: parsed +# +# +# ------------------------- +# Module Execution Result +# ------------------------- +# +# +# "parsed": { +#         "address": "192.0.2.11", +#         "enable": true, +#         "legacy_protocols": [ +#             "cdp", +#             "fdp" +#         ] +#     } +# + +  """  RETURN = """  before: @@ -317,13 +481,16 @@ def main():      required_if = [          ("state", "merged", ("config",)),          ("state", "replaced", ("config",)), +        ("state", "rendered", ("config",)), +        ("state", "parsed", ("running_config",)),      ] +    mutually_exclusive = [("config", "running_config")]      module = AnsibleModule(          argument_spec=Lldp_globalArgs.argument_spec,          required_if=required_if,          supports_check_mode=True, +        mutually_exclusive=mutually_exclusive,      ) -      result = Lldp_global(module).execute_module()      module.exit_json(**result) diff --git a/plugins/modules/vyos_lldp_interfaces.py b/plugins/modules/vyos_lldp_interfaces.py index 8fe572b0..b26da49e 100644 --- a/plugins/modules/vyos_lldp_interfaces.py +++ b/plugins/modules/vyos_lldp_interfaces.py @@ -30,18 +30,15 @@ from __future__ import absolute_import, division, print_function  __metaclass__ = type -ANSIBLE_METADATA = { -    "metadata_version": "1.1", -    "status": ["preview"], -    "supported_by": "network", -} +ANSIBLE_METADATA = {"metadata_version": "1.1", "supported_by": "Ansible"}  DOCUMENTATION = """module: vyos_lldp_interfaces -short_description: Manages attributes of lldp interfaces on VyOS devices. +short_description: LLDP interfaces resource module  description: This module manages attributes of lldp interfaces on VyOS network devices.  notes:  - Tested against VyOS 1.1.8 (helium).  - This module works with connection C(network_cli). See L(the VyOS OS Platform Options,../network/user_guide/platform_vyos.html). +version_added: "1.0.0"  author:  - Rohit Thakur (@rohitthakur2590)  options: @@ -111,6 +108,15 @@ options:            elin:              description: Emergency Call Service ELIN number (between 10-25 numbers).              type: str +  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 lldp). +      - 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:      description:      - The state of the configuration after module completion. @@ -120,6 +126,9 @@ options:      - replaced      - overridden      - deleted +    - rendered +    - parsed +    - gathered      default: merged  """  EXAMPLES = """ @@ -131,7 +140,7 @@ EXAMPLES = """  # vyos@vyos:~$ show configuration  commands | grep lldp  #  - name: Merge provided configuration with device configuration -  vyos_lldp_interfaces: +  vyos.vyos.vyos_lldp_interfaces:      config:        - name: 'eth1'          location: @@ -225,7 +234,7 @@ EXAMPLES = """  # set service lldp interface eth2 location coordinate-based longitude '222.267255W'  #  - name: Replace device configurations of listed LLDP interfaces with provided configurations -  vyos_lldp_interfaces: +  vyos.vyos.vyos_lldp_interfaces:      config:        - name: 'eth2'          location: @@ -348,7 +357,7 @@ EXAMPLES = """  # set service lldp interface eth2 location civic-based country-code 'US'  #  - name: Overrides all device configuration with provided configuration -  vyos_lag_interfaces: +  vyos.vyos.vyos_lldp_interfaces:      config:       - name: 'eth2'         location: @@ -423,7 +432,7 @@ EXAMPLES = """  # set service lldp interface eth2 location elin '0000000911'  #  - name: Delete lldp  interface attributes of given interfaces. -  vyos_lag_interfaces: +  vyos.vyos.vyos_lldp_interfaces:      config:       - name: 'eth2'      state: deleted @@ -453,6 +462,159 @@ EXAMPLES = """  # set service 'lldp' +# Using gathered +# +# Before state: +# ------------- +# +# vyos@192# run show configuration commands | grep lldp +# set service lldp interface eth1 location civic-based ca-type 0 ca-value 'ENGLISH' +# set service lldp interface eth1 location civic-based country-code 'US' +# set service lldp interface eth2 location coordinate-based altitude '2200' +# set service lldp interface eth2 location coordinate-based datum 'WGS84' +# set service lldp interface eth2 location coordinate-based latitude '33.524449N' +# set service lldp interface eth2 location coordinate-based longitude '222.267255W' +# +- name: Gather listed lldp interfaces from running configuration +  vyos.vyos.vyos_lldp_interfaces: +    config: +    state: gathered +# +# +# ------------------------- +# Module Execution Result +# ------------------------- +# +#    "gathered": [ +#         { +#             "location": { +#                 "coordinate_based": { +#                     "altitude": 2200, +#                     "datum": "WGS84", +#                     "latitude": "33.524449N", +#                     "longitude": "222.267255W" +#                 } +#             }, +#             "name": "eth2" +#         }, +#         { +#             "location": { +#                 "civic_based": { +#                     "ca_info": [ +#                         { +#                             "ca_type": 0, +#                             "ca_value": "ENGLISH" +#                         } +#                     ], +#                     "country_code": "US" +#                 } +#             }, +#             "name": "eth1" +#         } +#     ] +# +# +# After state: +# ------------- +# +# vyos@192# run show configuration commands | grep lldp +# set service lldp interface eth1 location civic-based ca-type 0 ca-value 'ENGLISH' +# set service lldp interface eth1 location civic-based country-code 'US' +# set service lldp interface eth2 location coordinate-based altitude '2200' +# set service lldp interface eth2 location coordinate-based datum 'WGS84' +# set service lldp interface eth2 location coordinate-based latitude '33.524449N' +# set service lldp interface eth2 location coordinate-based longitude '222.267255W' + + +# Using rendered +# +# +- name: Render the commands for provided  configuration +  vyos.vyos.vyos_lldp_interfaces: +    config: +          - name: eth1 +            location: +              civic_based: +                country_code: US +                ca_info: +                  - ca_type: 0 +                    ca_value: ENGLISH +          - name: eth2 +            location: +              coordinate_based: +                altitude: 2200 +                datum: WGS84 +                longitude: 222.267255W +                latitude: 33.524449N +    state: rendered +# +# +# ------------------------- +# Module Execution Result +# ------------------------- +# +# +# "rendered": [ +#         "set service lldp interface eth1 location civic-based country-code 'US'", +#         "set service lldp interface eth1 location civic-based ca-type 0 ca-value 'ENGLISH'", +#         "set service lldp interface eth1", +#         "set service lldp interface eth2 location coordinate-based latitude '33.524449N'", +#         "set service lldp interface eth2 location coordinate-based altitude '2200'", +#         "set service lldp interface eth2 location coordinate-based datum 'WGS84'", +#         "set service lldp interface eth2 location coordinate-based longitude '222.267255W'", +#         "set service lldp interface eth2" +#     ] + + +# Using parsed +# +# +- name: Parsed the commands to provide structured configuration. +  vyos.vyos.vyos_lldp_interfaces: +    running_config: +      "set service lldp interface eth1 location civic-based ca-type 0 ca-value 'ENGLISH' + set service lldp interface eth1 location civic-based country-code 'US' + set service lldp interface eth2 location coordinate-based altitude '2200' + set service lldp interface eth2 location coordinate-based datum 'WGS84' + set service lldp interface eth2 location coordinate-based latitude '33.524449N' + set service lldp interface eth2 location coordinate-based longitude '222.267255W'" +    state: parsed +# +# +# ------------------------- +# Module Execution Result +# ------------------------- +# +# +# "parsed": [ +#         { +#             "location": { +#                 "coordinate_based": { +#                     "altitude": 2200, +#                     "datum": "WGS84", +#                     "latitude": "33.524449N", +#                     "longitude": "222.267255W" +#                 } +#             }, +#             "name": "eth2" +#         }, +#         { +#             "location": { +#                 "civic_based": { +#                     "ca_info": [ +#                         { +#                             "ca_type": 0, +#                             "ca_value": "ENGLISH" +#                         } +#                     ], +#                     "country_code": "US" +#                 } +#             }, +#             "name": "eth1" +#         } +#     ] + +  """  RETURN = """  before: @@ -497,12 +659,17 @@ def main():      required_if = [          ("state", "merged", ("config",)),          ("state", "replaced", ("config",)), +        ("state", "rendered", ("config",)),          ("state", "overridden", ("config",)), +        ("state", "parsed", ("running_config",)),      ] +    mutually_exclusive = [("config", "running_config")] +      module = AnsibleModule(          argument_spec=Lldp_interfacesArgs.argument_spec,          required_if=required_if,          supports_check_mode=True, +        mutually_exclusive=mutually_exclusive,      )      result = Lldp_interfaces(module).execute_module() diff --git a/plugins/modules/vyos_static_routes.py b/plugins/modules/vyos_static_routes.py index 6e502037..e71114a1 100644 --- a/plugins/modules/vyos_static_routes.py +++ b/plugins/modules/vyos_static_routes.py @@ -30,16 +30,13 @@ from __future__ import absolute_import, division, print_function  __metaclass__ = type -ANSIBLE_METADATA = { -    "metadata_version": "1.1", -    "status": ["preview"], -    "supported_by": "network", -} +ANSIBLE_METADATA = {"metadata_version": "1.1", "supported_by": "Ansible"}  DOCUMENTATION = """module: vyos_static_routes -short_description: Manages attributes of static routes on VyOS network devices. +short_description: Static routes resource module  description: This module manages attributes of static routes on VyOS network devices.  notes: +version_added: "1.0.0"  - Tested against VyOS 1.1.8 (helium).  - This module works with connection C(network_cli). See L(the VyOS OS Platform Options,../network/user_guide/platform_vyos.html).  author: @@ -114,13 +111,12 @@ options:                      type: str    running_config:      description: -    - The module, by default, will connect to the remote device and retrieve the current -      running-config to use as a base for comparing against the contents of source. -      There are times when it is not desirable to have the task get the current running-config -      for every task in a playbook.  The I(running_config) argument allows the implementer -      to pass in the configuration to use as the base config for comparison. This -      value of this option should be the output received from device by executing -      command C(show configuration commands | grep 'static route') +      - 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 static route). +      - 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:      description: @@ -145,7 +141,7 @@ EXAMPLES = """  # vyos@vyos:~$ show configuration  commands | grep static  #  - name: Merge the provided configuration with the exisiting running configuration -  vyos_static_routes: +  vyos.vyos.vyos_static_routes:      config:       - address_families:         - afi: 'ipv4' @@ -259,7 +255,7 @@ EXAMPLES = """  # set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::2'  #  - name: Replace device configurations of listed static routes with provided configurations -  vyos_static_routes: +  vyos.vyos.vyos_static_routes:      config:       - address_families:         - afi: 'ipv4' @@ -435,7 +431,7 @@ EXAMPLES = """  # set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::2'  #  - name: Overrides all device configuration with provided configuration -  vyos_static_routes: +  vyos.vyos.vyos_static_routes:      config:       - address_families:         - afi: 'ipv4' @@ -531,92 +527,6 @@ EXAMPLES = """  # set protocols static route 198.0.2.48/28 next-hop '192.0.2.18' -# Using deleted to delete static route based on destination -# -# Before state -# ------------- -# -# vyos@vyos:~$ show configuration commands| grep static -# set protocols static route 192.0.2.32/28 'blackhole' -# set protocols static route 192.0.2.32/28 next-hop '192.0.2.6' -# set protocols static route 192.0.2.32/28 next-hop '192.0.2.7' -# set protocols static route6 2001:db8:1000::/36 blackhole distance '2' -# set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::1' -# set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::2' -# -- name: Delete static route per destination. -  vyos_static_routes: -    config: -     - address_families: -       - afi: 'ipv4' -         routes: -           - dest: '192.0.2.32/28' -       - afi: 'ipv6' -         routes: -           - dest: '2001:db8:1000::/36' -    state: deleted -# -# -# ------------------------ -# Module Execution Results -# ------------------------ -# -#    "before": [ -#        { -#            "address_families": [ -#                { -#                    "afi": "ipv4", -#                    "routes": [ -#                        { -#                            "blackhole_config": { -#                                "type": "blackhole" -#                            }, -#                            "dest": "192.0.2.32/28", -#                            "next_hops": [ -#                                { -#                                    "forward_router_address": "192.0.2.6" -#                                }, -#                                { -#                                    "forward_router_address": "192.0.2.7" -#                                } -#                            ] -#                        } -#                    ] -#                }, -#                { -#                    "afi": "ipv6", -#                    "routes": [ -#                        { -#                            "blackhole_config": { -#                                "distance": 2 -#                            }, -#                            "dest": "2001:db8:1000::/36", -#                            "next_hops": [ -#                                { -#                                    "forward_router_address": "2001:db8:2000:2::1" -#                                }, -#                                { -#                                    "forward_router_address": "2001:db8:2000:2::2" -#                                } -#                            ] -#                        } -#                    ] -#                } -#            ] -#        } -#    ] -#    "commands": [ -#       "delete protocols static route 192.0.2.32/28", -#       "delete protocols static route6 2001:db8:1000::/36" -#    ] -# -# "after": [] -# After state -# ------------ -# vyos@vyos# run show configuration commands | grep static -# set protocols 'static' - -  # Using deleted to delete static route based on afi  #  # Before state @@ -631,7 +541,7 @@ EXAMPLES = """  # set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::2'  #  - name: Delete static route based on afi. -  vyos_static_routes: +  vyos.vyos.vyos_static_routes:      config:       - address_families:         - afi: 'ipv4' @@ -713,7 +623,7 @@ EXAMPLES = """  # set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::2'  #  - name: Delete all the static routes. -  vyos_static_routes: +  vyos.vyos.vyos_static_routes:      config:      state: deleted  # @@ -778,141 +688,11 @@ EXAMPLES = """  # set protocols 'static' -# Using deleted to delete static route based on next-hop -# -# Before state -# ------------- -# -# vyos@vyos:~$ show configuration commands| grep static -# set protocols static route 192.0.2.32/28 'blackhole' -# set protocols static route 192.0.2.32/28 next-hop '192.0.2.6' -# set protocols static route 192.0.2.32/28 next-hop '192.0.2.7' -# set protocols static route6 2001:db8:1000::/36 blackhole distance '2' -# set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::1' -# set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::2' -# -- name: Delete static routes per next-hops -  vyos_static_routes: -    config: -     - address_families: -       - afi: 'ipv4' -         routes: -           - dest: '192.0.2.32/28' -             next-hops: -               - forward_router_address: '192.0.2.6' -       - afi: 'ipv6' -         routes: -           - dest: '2001:db8:1000::/36' -             next-hops: -               - forward_router_address: '2001:db8:2000:2::1' -    state: deleted -# -# -# ------------------------ -# Module Execution Results -# ------------------------ -# -#    "before": [ -#        { -#            "address_families": [ -#                { -#                    "afi": "ipv4", -#                    "routes": [ -#                        { -#                            "blackhole_config": { -#                                "type": "blackhole" -#                            }, -#                            "dest": "192.0.2.32/28", -#                            "next_hops": [ -#                                { -#                                    "forward_router_address": "192.0.2.6" -#                                }, -#                                { -#                                    "forward_router_address": "192.0.2.7" -#                                } -#                            ] -#                        } -#                    ] -#                }, -#                { -#                    "afi": "ipv6", -#                    "routes": [ -#                        { -#                            "blackhole_config": { -#                                "distance": 2 -#                            }, -#                            "dest": "2001:db8:1000::/36", -#                            "next_hops": [ -#                                { -#                                    "forward_router_address": "2001:db8:2000:2::1" -#                                }, -#                                { -#                                    "forward_router_address": "2001:db8:2000:2::2" -#                                } -#                            ] -#                        } -#                    ] -#                } -#            ] -#        } -#    ] -#    "commands": [ -#       "delete protocols static route 192.0.2.32/28 next-hop '192.0.2.6'", -#       "delete protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::1'" -#    ] -# -#    "after": [ -#        { -#            "address_families": [ -#                { -#                    "afi": "ipv4", -#                    "routes": [ -#                        { -#                            "blackhole_config": { -#                                "type": "blackhole" -#                            }, -#                            "dest": "192.0.2.32/28", -#                            "next_hops": [ -#                                { -#                                    "forward_router_address": "192.0.2.7" -#                                } -#                            ] -#                        } -#                    ] -#                }, -#                { -#                    "afi": "ipv6", -#                    "routes": [ -#                        { -#                            "blackhole_config": { -#                                "distance": 2 -#                            }, -#                            "dest": "2001:db8:1000::/36", -#                            "next_hops": [ -#                                { -#                                    "forward_router_address": "2001:db8:2000:2::2" -#                                } -#                            ] -#                        } -#                    ] -#                } -#            ] -#        } -#    ] -# After state -# ------------ -# vyos@vyos:~$ show configuration commands| grep static -# set protocols static route 192.0.2.32/28 'blackhole' -# set protocols static route 192.0.2.32/28 next-hop '192.0.2.7' -# set protocols static route6 2001:db8:1000::/36 blackhole distance '2' -# set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::2' - -  # Using rendered  #  #  - name: Render the commands for provided  configuration -  vyos_static_routes: +  vyos.vyos.vyos_static_routes:      config:        - address_families:            - afi: 'ipv4' @@ -955,8 +735,8 @@ EXAMPLES = """  # Using parsed  #  # -- name: Render the commands for provided  configuration -  vyos_static_routes: +- name: Parse the provided running configuration +  vyos.vyos.vyos_static_routes:      running_config:        "set protocols static route 192.0.2.32/28 'blackhole'   set protocols static route 192.0.2.32/28 next-hop '192.0.2.6' @@ -1026,7 +806,7 @@ EXAMPLES = """  # set protocols static route6 2001:db8:1000::/36 next-hop '2001:db8:2000:2::2'  #  - name: Gather listed static routes with provided configurations -  vyos_static_routes: +  vyos.vyos.vyos_static_routes:      config:      state: gathered  # @@ -1137,6 +917,7 @@ def main():      required_if = [          ("state", "merged", ("config",)),          ("state", "replaced", ("config",)), +        ("state", "rendered", ("config",)),          ("state", "overridden", ("config",)),          ("state", "parsed", ("running_config",)),      ] | 
