mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-25 14:20:22 -07:00
wakeonlan: Bugfix and small improvements (#22389)
- Close the socket after use - Use proper parameter types - Remove redundant parameter options - Clean up docs - Move module from network/ to remote_management/ - Add check-mode support
This commit is contained in:
parent
a64665ae91
commit
c45f6905fc
1 changed files with 19 additions and 17 deletions
|
@ -25,25 +25,22 @@ ANSIBLE_METADATA = {'status': ['preview'],
|
||||||
DOCUMENTATION = '''
|
DOCUMENTATION = '''
|
||||||
---
|
---
|
||||||
module: wakeonlan
|
module: wakeonlan
|
||||||
version_added: 2.2
|
version_added: '2.2'
|
||||||
short_description: Send a magic Wake-on-LAN (WoL) broadcast packet
|
short_description: Send a magic Wake-on-LAN (WoL) broadcast packet
|
||||||
description:
|
description:
|
||||||
- The C(wakeonlan) module sends magic Wake-on-LAN (WoL) broadcast packets.
|
- The C(wakeonlan) module sends magic Wake-on-LAN (WoL) broadcast packets.
|
||||||
options:
|
options:
|
||||||
mac:
|
mac:
|
||||||
description:
|
description:
|
||||||
- MAC address to send Wake-on-LAN broadcast packet for
|
- MAC address to send Wake-on-LAN broadcast packet for.
|
||||||
required: true
|
required: true
|
||||||
default: null
|
|
||||||
broadcast:
|
broadcast:
|
||||||
description:
|
description:
|
||||||
- Network broadcast address to use for broadcasting magic Wake-on-LAN packet
|
- Network broadcast address to use for broadcasting magic Wake-on-LAN packet.
|
||||||
required: false
|
|
||||||
default: 255.255.255.255
|
default: 255.255.255.255
|
||||||
port:
|
port:
|
||||||
description:
|
description:
|
||||||
- UDP port to use for magic Wake-on-LAN packet
|
- UDP port to use for magic Wake-on-LAN packet.
|
||||||
required: false
|
|
||||||
default: 7
|
default: 7
|
||||||
author: "Dag Wieers (@dagwieers)"
|
author: "Dag Wieers (@dagwieers)"
|
||||||
todo:
|
todo:
|
||||||
|
@ -57,8 +54,8 @@ notes:
|
||||||
'''
|
'''
|
||||||
|
|
||||||
EXAMPLES = '''
|
EXAMPLES = '''
|
||||||
# Send a magic Wake-on-LAN packet to 00:00:5E:00:53:66
|
- name: Send a magic Wake-on-LAN packet to 00:00:5E:00:53:66
|
||||||
- wakeonlan:
|
wakeonlan:
|
||||||
mac: '00:00:5E:00:53:66'
|
mac: '00:00:5E:00:53:66'
|
||||||
broadcast: 192.0.2.23
|
broadcast: 192.0.2.23
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
|
@ -111,23 +108,28 @@ def wakeonlan(module, mac, broadcast, port):
|
||||||
sock.sendto(data, (broadcast, port))
|
sock.sendto(data, (broadcast, port))
|
||||||
except socket.error:
|
except socket.error:
|
||||||
e = get_exception()
|
e = get_exception()
|
||||||
|
sock.close()
|
||||||
module.fail_json(msg=str(e))
|
module.fail_json(msg=str(e))
|
||||||
|
sock.close()
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
argument_spec = dict(
|
argument_spec = dict(
|
||||||
mac = dict(required=True, type='str'),
|
mac = dict(type='str', required=True),
|
||||||
broadcast = dict(required=False, default='255.255.255.255'),
|
broadcast = dict(type='str', default='255.255.255.255'),
|
||||||
port = dict(required=False, type='int', default=7),
|
port = dict(type='int', default=7),
|
||||||
),
|
),
|
||||||
|
supports_check_mode = True,
|
||||||
)
|
)
|
||||||
|
|
||||||
mac = module.params.get('mac')
|
mac = module.params['mac']
|
||||||
broadcast = module.params.get('broadcast')
|
broadcast = module.params['broadcast']
|
||||||
port = module.params.get('port')
|
port = module.params['port']
|
||||||
|
|
||||||
|
if not module.check_mode:
|
||||||
|
wakeonlan(module, mac, broadcast, port)
|
||||||
|
|
||||||
wakeonlan(module, mac, broadcast, port)
|
|
||||||
module.exit_json(changed=True)
|
module.exit_json(changed=True)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue