1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-04-24 12:49:03 +00:00

Reformat everything.

This commit is contained in:
Felix Fontein 2025-11-01 12:08:41 +01:00
parent 3f2213791a
commit 340ff8586d
1008 changed files with 61301 additions and 58309 deletions

View file

@ -137,6 +137,7 @@ from ansible.module_utils.basic import AnsibleModule, missing_required_lib
# Main
#
def main():
# From https://docs.python.org/3/library/ssl.html#constants, this:
#
@ -145,37 +146,37 @@ def main():
#
# @TODO: update the use of `ssl` constants
tls_map = {
'tlsv1.2': ssl.PROTOCOL_TLSv1_2,
'tlsv1.1': ssl.PROTOCOL_TLSv1_1,
"tlsv1.2": ssl.PROTOCOL_TLSv1_2,
"tlsv1.1": ssl.PROTOCOL_TLSv1_1,
}
module = AnsibleModule(
argument_spec=dict(
server=dict(default='localhost'),
port=dict(default=1883, type='int'),
server=dict(default="localhost"),
port=dict(default=1883, type="int"),
topic=dict(required=True),
payload=dict(required=True),
client_id=dict(),
qos=dict(default="0", choices=["0", "1", "2"]),
retain=dict(default=False, type='bool'),
retain=dict(default=False, type="bool"),
username=dict(),
password=dict(no_log=True),
ca_cert=dict(type='path', aliases=['ca_certs']),
client_cert=dict(type='path', aliases=['certfile']),
client_key=dict(type='path', aliases=['keyfile']),
tls_version=dict(choices=['tlsv1.1', 'tlsv1.2'])
ca_cert=dict(type="path", aliases=["ca_certs"]),
client_cert=dict(type="path", aliases=["certfile"]),
client_key=dict(type="path", aliases=["keyfile"]),
tls_version=dict(choices=["tlsv1.1", "tlsv1.2"]),
),
supports_check_mode=True
supports_check_mode=True,
)
if not HAS_PAHOMQTT:
module.fail_json(msg=missing_required_lib('paho-mqtt'), exception=PAHOMQTT_IMP_ERR)
module.fail_json(msg=missing_required_lib("paho-mqtt"), exception=PAHOMQTT_IMP_ERR)
server = module.params.get("server", 'localhost')
server = module.params.get("server", "localhost")
port = module.params.get("port", 1883)
topic = module.params.get("topic")
payload = module.params.get("payload")
client_id = module.params.get("client_id", '')
client_id = module.params.get("client_id", "")
qos = int(module.params.get("qos", 0))
retain = module.params.get("retain")
username = module.params.get("username", None)
@ -188,12 +189,12 @@ def main():
if client_id is None:
client_id = f"{socket.getfqdn()}_{os.getpid()}"
if payload and payload == 'None':
if payload and payload == "None":
payload = None
auth = None
if username is not None:
auth = {'username': username, 'password': password}
auth = {"username": username, "password": password}
tls = None
if ca_certs is not None:
@ -201,32 +202,21 @@ def main():
tls_version = tls_map.get(tls_version, ssl.PROTOCOL_TLS)
tls = {
'ca_certs': ca_certs,
'certfile': certfile,
'keyfile': keyfile,
'tls_version': tls_version,
"ca_certs": ca_certs,
"certfile": certfile,
"keyfile": keyfile,
"tls_version": tls_version,
}
try:
mqtt.single(
topic,
payload,
qos=qos,
retain=retain,
client_id=client_id,
hostname=server,
port=port,
auth=auth,
tls=tls
topic, payload, qos=qos, retain=retain, client_id=client_id, hostname=server, port=port, auth=auth, tls=tls
)
except Exception as e:
module.fail_json(
msg=f"unable to publish to MQTT broker {e}",
exception=traceback.format_exc()
)
module.fail_json(msg=f"unable to publish to MQTT broker {e}", exception=traceback.format_exc())
module.exit_json(changed=False, topic=topic)
if __name__ == '__main__':
if __name__ == "__main__":
main()