--- - name: Gather host facts for delivery directory discovery hosts: "{{ target_hosts | default('all') }}" become: true gather_facts: true vars: delivery_lookup_path: "{{ lookup_path | default('') }}" tasks: - name: Show directory completions ansible.builtin.shell: | set -euo pipefail python3 - <<'PY' import json import os import sys prefix = os.environ.get("LOOKUP_PATH", "").strip() if not prefix.startswith("/") or "\x00" in prefix: print("XINFRA_PATH_COMPLETIONS_JSON=[]") sys.exit(0) if prefix.endswith("/"): parent = prefix.rstrip("/") or "/" needle = "" else: parent = os.path.dirname(prefix) or "/" needle = os.path.basename(prefix) items = [] try: children = sorted(os.listdir(parent)) except OSError: children = [] for name in children: if needle and not name.startswith(needle): continue path = os.path.join(parent, name) if parent != "/" else "/" + name if not os.path.isdir(path): continue available_gi = 0 try: stat = os.statvfs(path) available_gi = int(stat.f_bavail * stat.f_frsize / 1073741824) except OSError: pass items.append({"path": path, "available_gi": available_gi}) print("XINFRA_PATH_COMPLETIONS_JSON=" + json.dumps(items, ensure_ascii=False)) PY args: executable: /bin/bash environment: LOOKUP_PATH: "{{ delivery_lookup_path }}" changed_when: false when: delivery_lookup_path | length > 0 - name: Show discovered mounts ansible.builtin.debug: var: ansible_mounts when: delivery_lookup_path | length == 0