diff --git a/plugins/module_utils/network/vyos/config/ntp_global/ntp_global.py b/plugins/module_utils/network/vyos/config/ntp_global/ntp_global.py index 106faac5..0af1af58 100644 --- a/plugins/module_utils/network/vyos/config/ntp_global/ntp_global.py +++ b/plugins/module_utils/network/vyos/config/ntp_global/ntp_global.py @@ -31,6 +31,10 @@ NtpTemplate, ) +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import get_os_version + +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.utils.version import LooseVersion + class Ntp_global(ResourceModule): """ @@ -120,6 +124,17 @@ def generate_commands(self): for k, want in iteritems(wantd): self._compare(want=want, have=haved.pop(k, {})) + if LooseVersion(get_os_version(self._module)) >= LooseVersion("1.4"): + path = "service" + ac = "allow-client" + else: + path = "system" + ac = "allow-clients" + + if self.commands: + self.commands = [cl.replace('%%path%%', path) for cl in self.commands] + self.commands = [nc.replace('%%ac%%', ac) for nc in self.commands] + def _compare(self, want, have): """Leverages the base class `compare()` method and populates the list of commands to be run by comparing diff --git a/plugins/module_utils/network/vyos/rm_templates/ntp_global.py b/plugins/module_utils/network/vyos/rm_templates/ntp_global.py index 33d173e0..1e011dd9 100644 --- a/plugins/module_utils/network/vyos/rm_templates/ntp_global.py +++ b/plugins/module_utils/network/vyos/rm_templates/ntp_global.py @@ -35,11 +35,11 @@ def __init__(self, lines=None, module=None): "name": "allow_clients", "getval": re.compile( r""" - ^set\ssystem\sntp\sallow-clients\saddress (\s(?P\S+))? + ^set\s(?Psystem|service)?\sntp\s(?Pallow-clients|allow-client)?\saddress (\s(?P\S+))? $""", re.VERBOSE, ), - "setval": "system ntp allow-clients address {{allow_clients}}", + "setval": "%%path%% ntp %%ac%% address {{allow_clients}}", "result": { "allow_clients": ["{{ipaddress}}"], }, @@ -50,11 +50,11 @@ def __init__(self, lines=None, module=None): "name": "allow_clients_delete", "getval": re.compile( r""" - ^set\ssystem\sntp\sallow-clients + ^set\s(?Psystem|service)?\sntp\s(?Pallow-clients|allow-client)? $""", re.VERBOSE, ), - "setval": "system ntp allow-clients", + "setval": "%%path%% ntp %%ac%%", "result": { }, @@ -66,11 +66,11 @@ def __init__(self, lines=None, module=None): "name": "listen_addresses", "getval": re.compile( r""" - ^set\ssystem\sntp\slisten-address (\s(?P\S+))? + ^set\s(?Psystem|service)?\sntp\slisten-address (\s(?P\S+))? $""", re.VERBOSE, ), - "setval": "system ntp listen-address {{listen_addresses}}", + "setval": "%%path%% ntp listen-address {{listen_addresses}}", "result": { "listen_addresses": ["{{ip_address}}"], }, @@ -81,11 +81,11 @@ def __init__(self, lines=None, module=None): "name": "listen_addresses_delete", "getval": re.compile( r""" - ^set\ssystem\sntp\slisten-address + ^set\s(?Psystem|service)?\sntp\slisten-address $""", re.VERBOSE, ), - "setval": "system ntp listen-address", + "setval": "%%path%% ntp listen-address", "result": { }, }, @@ -95,11 +95,11 @@ def __init__(self, lines=None, module=None): "name": "server", "getval": re.compile( r""" - ^set\ssystem\sntp\sserver (\s(?P\S+))? + ^set\s(?Psystem|service)?\sntp\sserver (\s(?P\S+))? $""", re.VERBOSE, ), - "setval": "system ntp server {{server}}", + "setval": "%%path%% ntp server {{server}}", "result": { "servers": { "{{name}}": { @@ -115,13 +115,13 @@ def __init__(self, lines=None, module=None): "name": "options", "getval": re.compile( r""" - ^set\ssystem\sntp\sserver + ^set\s(?Psystem|service)?\sntp\sserver \s(?P\S+) \s(?Pnoselect|dynamic|pool|preempt|prefer)? $""", re.VERBOSE, ), - "setval": "system ntp server {{server}} {{options}}", + "setval": "%%path%% ntp server {{server}} {{options}}", "result": { "servers": { "{{name}}": {