ci / test (push) Successful in 2m39s
Ansible collection that converges MeshCore repeaters through a companion radio (TCP, USB serial or BLE): admin ACL, CLI prefs, region tree, firmware facts, companion remote-CLI ACL, and the meshcore-tth extras (BLE on/off and own BLE PIN, channel-hash filter, message age, advert fairness). Every change is read, diffed, sent and read back; --check only reads. ansible-test sanity, unit tests and a galaxy build in CI. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
107 lines
4.4 KiB
Python
107 lines
4.4 KiB
Python
# Copyright: (c) 2026, TeTeHacko <tth@rfa.cz>
|
|
# GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
DOCUMENTATION = r"""
|
|
module: meshcore_fw_facts
|
|
short_description: Firmware version of a MeshCore repeater or companion, over RF
|
|
author: TeTeHacko (@TeTeHacko)
|
|
description:
|
|
- Logs in as admin and reads `ver`. A companion (C(companion), fw 1.18+ /
|
|
Solo 2.0+) answers `ver` as remote CLI only to a contact in its ACL (the
|
|
"remote CLI" flag 0x10, see meshcore_companion_acl); anyone else gets silence. With C(wanted), also says whether the
|
|
node is current, outdated, dirty (built from a dirty tree, '+') or unknown.
|
|
- Returns C(clock_skew), node clock minus ours in seconds, from the
|
|
timestamp on the node's `ver` reply.
|
|
- Read-only; runs in check mode too.
|
|
options:
|
|
transport: {description: Companion to talk through (see meshcore_acl)., type: dict, required: true}
|
|
target: {description: Full 64-hex pubkey of the node., type: str, required: true}
|
|
name: {description: Name for the contact if the companion has to create it., type: str}
|
|
companion: {description: "The target is a companion (remote CLI, ACL = flagged contacts).", type: bool, default: false}
|
|
password: {description: Admin password (empty = blank login)., type: str, default: ""}
|
|
wanted: {description: The version stamp the node should run (from the built ELF)., type: str}
|
|
clock_sync:
|
|
description:
|
|
- Send `clock sync` first (sets the node clock from our timestamp when it is
|
|
behind). A freshly flashed node boots in May 2024, and clients drop
|
|
replies stamped that far back. Fire-and-forget, its own reply may be the
|
|
one that gets dropped.
|
|
type: bool
|
|
default: false
|
|
"""
|
|
|
|
EXAMPLES = r"""
|
|
- name: Which firmware runs there
|
|
tth.meshcore.meshcore_fw_facts:
|
|
transport: {type: tcp, host: 127.0.0.1, port: 5000}
|
|
target: "{{ mc_target }}"
|
|
password: "{{ vault_meshcore_admin_password }}"
|
|
clock_sync: true
|
|
register: fw
|
|
|
|
- name: Show it
|
|
ansible.builtin.debug:
|
|
msg: "{{ fw.version }}, clock off by {{ fw.clock_skew | default('?') }} s"
|
|
"""
|
|
import asyncio
|
|
|
|
from ansible.module_utils.basic import AnsibleModule, missing_required_lib
|
|
from ansible_collections.tth.meshcore.plugins.module_utils.meshcore_fw import fw_state, parse_version
|
|
from ansible_collections.tth.meshcore.plugins.module_utils.meshcore_link import HAS_MESHCORE, Link, LinkError, run
|
|
|
|
|
|
async def work(module, link):
|
|
await link.open()
|
|
try:
|
|
if not module.params["companion"]:
|
|
await link.login()
|
|
if module.params["clock_sync"] and not module.check_mode:
|
|
await link.mc.commands.send_cmd(link.contact, "clock sync")
|
|
link.log.append("$ clock sync (not waiting for the reply)")
|
|
await asyncio.sleep(3)
|
|
reply = await link.cli("ver", r"\(Build: ")
|
|
finally:
|
|
await link.close()
|
|
version = parse_version(reply)
|
|
out = {"changed": False, "ver": reply, "version": version, "name": link.name()}
|
|
# Node clock minus ours, from the timestamp the node put on its `ver` reply:
|
|
# costs no extra packet and works for companions too (they have no `clock`
|
|
# CLI). Positive = node ahead. Accurate to the reply latency (seconds).
|
|
if link.last_reply_ts:
|
|
out["clock_skew"] = int(link.last_reply_ts - link.last_reply_at)
|
|
if module.params["wanted"]:
|
|
out["state"] = fw_state(version, module.params["wanted"])
|
|
return out
|
|
|
|
|
|
def main():
|
|
module = AnsibleModule(
|
|
argument_spec={
|
|
"transport": {"type": "dict", "required": True},
|
|
"target": {"type": "str", "required": True},
|
|
"password": {"type": "str", "default": "", "no_log": True},
|
|
"wanted": {"type": "str"},
|
|
"clock_sync": {"type": "bool", "default": False},
|
|
"companion": {"type": "bool", "default": False},
|
|
"name": {"type": "str"},
|
|
},
|
|
supports_check_mode=True,
|
|
)
|
|
if not HAS_MESHCORE:
|
|
module.fail_json(msg=missing_required_lib("meshcore"))
|
|
link = Link(
|
|
module.params["transport"],
|
|
module.params["target"],
|
|
module.params["password"],
|
|
companion=module.params["companion"],
|
|
name=module.params["name"],
|
|
)
|
|
try:
|
|
result = run(work(module, link))
|
|
except (LinkError, ValueError) as e:
|
|
module.fail_json(msg=str(e), log=link.log)
|
|
module.exit_json(log=link.log, **result)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|