diff --git a/ansible_collections/juniper/device/plugins/connection/pyez.py b/ansible_collections/juniper/device/plugins/connection/pyez.py index 11f93923..b262fc23 100644 --- a/ansible_collections/juniper/device/plugins/connection/pyez.py +++ b/ansible_collections/juniper/device/plugins/connection/pyez.py @@ -754,7 +754,7 @@ def commit_configuration(self, ignore_warning=None, comment=None, raise AnsibleError('Failure committing the configuraton: %s' % (str(ex))) - def system_api(self, action, in_min, at, all_re, vmhost, other_re, media): + def system_api(self, action, in_min, at, all_re, vmhost, other_re, media, member_id): """Triggers the system calls like reboot, shutdown, halt and zeroize to device. """ msg = None @@ -767,7 +767,11 @@ def system_api(self, action, in_min, at, all_re, vmhost, other_re, media): try: self.sw = jnpr.junos.utils.sw.SW(self.dev) if action == 'reboot': - got = self.sw.reboot(in_min, at, all_re, None, vmhost, other_re) + if member_id is not None: + for m_id in member_id: + got = self.sw.reboot(in_min, at, all_re, None, vmhost, other_re, member_id=m_id) + else: + got = self.sw.reboot(in_min, at, all_re, None, vmhost, other_re) elif action == 'shutdown': got = self.sw.poweroff(in_min, at, None, all_re, other_re) elif action == 'halt': @@ -815,7 +819,7 @@ def software_api(self, install_params): self.pyez_exception.RpcError) as ex: raise AnsibleError('Installation failed. Error: %s' % str(ex)) - def reboot_api(self, all_re, vmhost): + def reboot_api(self, all_re, vmhost, member_id): """reboots the device. """ msg = None @@ -824,7 +828,11 @@ def reboot_api(self, all_re, vmhost): if self.dev.timeout > 5: self.dev.timeout = 5 try: - got = self.sw.reboot(0, None, all_re, None, vmhost) + if member_id is not None: + for m_id in member_id: + got = self.sw.reboot(0, None, all_re, None, vmhost, member_id=m_id) + else: + got = self.sw.reboot(0, None, all_re, None, vmhost) self.dev.timeout = restore_timeout except Exception: # pylint: disable=broad-except self.dev.timeout = restore_timeout diff --git a/ansible_collections/juniper/device/plugins/modules/software.py b/ansible_collections/juniper/device/plugins/modules/software.py index a6c244af..54a5b814 100644 --- a/ansible_collections/juniper/device/plugins/modules/software.py +++ b/ansible_collections/juniper/device/plugins/modules/software.py @@ -88,6 +88,12 @@ required: false default: true type: bool + member_id: + description: + - install software on the specified members ids of VC. + required: false + default: none + type: list checksum: description: - The pre-calculated checksum, using the I(checksum_algorithm) of the @@ -492,6 +498,9 @@ def main(): all_re=dict(required=False, type='bool', default=True), + member_id=dict(required=False, + type='list', + default=None), vmhost=dict(required=False, type='bool', default=False), @@ -541,6 +550,7 @@ def main(): install_timeout = junos_module.params.pop('install_timeout') cleanfs = junos_module.params.pop('cleanfs') all_re = junos_module.params.pop('all_re') + member_id = junos_module.params.pop('member_id') kwargs = junos_module.params.pop('kwargs') url = None @@ -684,6 +694,7 @@ def main(): install_params['no_copy'] = no_copy install_params['timeout'] = install_timeout install_params['all_re'] = all_re + install_params['member_id'] = member_id for key in option_keys: value = junos_module.params.get(key) if value is not None: @@ -715,7 +726,11 @@ def main(): if reboot is True: junos_module.logger.debug('Initiating reboot.') if junos_module.conn_type != "local": - results['msg'] += junos_module._pyez_conn.reboot_api(all_re, install_params.get('vmhost')) + if member_id is not None: + for m_id in member_id: + results['msg'] += junos_module._pyez_conn.reboot_api(all_re, install_params.get('vmhost'), member_id=m_id) + else: + results['msg'] += junos_module._pyez_conn.reboot_api(all_re, install_params.get('vmhost')) else: try: # Try to deal with the fact that we might not get the closing @@ -728,7 +743,11 @@ def main(): "to 5 seconds.") junos_module.dev.timeout = 5 try: - got = junos_module.sw.reboot(0, None, all_re, None, install_params.get('vmhost')) + if member_id is not None: + for m_id in member_id: + got = junos_module.sw.reboot(0, None, all_re, None, install_params.get('vmhost'), member_id=m_id) + else: + got = junos_module.sw.reboot(0, None, all_re, None, install_params.get('vmhost')) junos_module.dev.timeout = restore_timeout except Exception: # pylint: disable=broad-except junos_module.dev.timeout = restore_timeout diff --git a/ansible_collections/juniper/device/plugins/modules/system.py b/ansible_collections/juniper/device/plugins/modules/system.py index b8aa3c86..6dd40178 100644 --- a/ansible_collections/juniper/device/plugins/modules/system.py +++ b/ansible_collections/juniper/device/plugins/modules/system.py @@ -273,6 +273,9 @@ def main(): all_re=dict(type='bool', required=False, default=True), + member_id=dict(type='list', + required=False, + default=None), other_re=dict(type='bool', required=False, default=False), @@ -297,6 +300,7 @@ def main(): other_re = params.get('other_re') media = params.get('media') vmhost = params.get('vmhost') + member_id = params.get('member_id') # Synonymn for shutdown if action == 'off' or action == 'power_off' or action == 'power-off': @@ -331,7 +335,11 @@ def main(): if not junos_module.check_mode: if junos_module.conn_type != "local": - results['msg'] = junos_module._pyez_conn.system_api(action, in_min, at, all_re, vmhost, other_re, media) + if member_id is not None: + for m_id in member_id: + results['msg'] = junos_module._pyez_conn.system_api(action, in_min, at, all_re, vmhost, other_re, media, member_id=m_id) + else: + results['msg'] = junos_module._pyez_conn.system_api(action, in_min, at, all_re, vmhost, other_re, media) results['failed'] = False else: if action != 'zeroize': @@ -351,7 +359,11 @@ def main(): junos_module.logger.debug("Executing RPC") junos_module.add_sw() if action == 'reboot': - got = junos_module.sw.reboot(in_min, at, all_re, None, vmhost, other_re) + if member_id is not None: + for m_id in member_id: + got = junos_module.sw.reboot(in_min, at, all_re, None, vmhost, other_re, member_id=m_id) + else: + got = junos_module.sw.reboot(in_min, at, all_re, None, vmhost, other_re) elif action == 'shutdown': got = junos_module.sw.poweroff(in_min, at, None, all_re, other_re) elif action == 'halt':