繁体   English   中英

等待文件通过 ssh

[英]Wait for file over ssh

我想做类似的事情:

- name: Wait until the file is touched
  ansible.builtin.wait_for:
    path: 192.168.1.1:/home/test.txt
    timeout: 300

其中 192.168.1.1 是我连接的某个远程主机。 这可能吗?

我不相信使用 wait_for 模块是可能的。
我的解决方法是使用until

  - name: Wait until file exists on remote.
    shell: ssh $USER@192.168.1.1 ls /home/test.txt
    register: filecheck
    until: filecheck.stdout == "/home/test.txt"
    retries: 10
    delay: 1

当剧本运行第 9 次尝试时,我将文件复制到主机:

changed: [localhost] => {
    "attempts": 9,
    "changed": true,
    "cmd": "ssh root@192.168.1.1 ls /home/test.txt",
    "delta": "0:00:01.548091",
    "end": "2022-08-11 15:31:05.276277",
    "invocation": {
        "module_args": {
            "_raw_params": "ssh root@192.168.1.1 ls /home/test.txt",
            "_uses_shell": true,
            "argv": null,
            "chdir": null,
            "creates": null,
            "executable": null,
            "removes": null,
            "stdin": null,
            "stdin_add_newline": true,
            "strip_empty_ends": true,
            "warn": false
        }
    },
    "msg": "",
    "rc": 0,
    "start": "2022-08-11 15:31:03.728186",
    "stderr": "",
    "stderr_lines": [],
    "stdout": "/home/test.txt",
    "stdout_lines": [
        "/home/test.txt"
    ]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM