Ansible 模块在我的 Mac 上成功,但在 Rock Linux 机器上失败?

问题描述 投票:0回答:1

我创建了一个 Ansible 模块,如本文所示 Paramiko SFTPClient get() 和 put() 函数的通过/失败结果? 这是一个用于测试该模块的简单手册。

- hosts: localhost
  tasks:
    - name: Test that my module works
      sftp:
        host: "{{ sftp_url }}"
        user: "{{ sftp_user }}"
        password: "{{ sftp_password }}"
        src: "/devops/junk.txt"
        dest: "/tmp/junk.txt"
        direction: download
      register: result
      delegate_to: localhost

我能够在我的 Mac 和 Ubuntu Linux 上成功运行它。然而,当我在 Rocky Linux 机器上运行它时,我得到了

2024-02-01 17:42:32,518 p=1787 u=jenkins n=ansible | [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

2024-02-01 17:42:32,748 p=1787 u=jenkins n=ansible | PLAY [localhost] ***********************************************************************************************************************************************
2024-02-01 17:42:32,792 p=1787 u=jenkins n=ansible | TASK [Gathering Facts] *****************************************************************************************************************************************
2024-02-01 17:42:34,060 p=1787 u=jenkins n=ansible | ok: [localhost]
2024-02-01 17:42:34,095 p=1787 u=jenkins n=ansible | TASK [Test SFTP] ***********************************************************************************************************************************************
2024-02-01 17:42:35,086 p=1787 u=jenkins n=ansible | An exception occurred during task execution. To see the full traceback, use -vvv. The error was: FileNotFoundError: [Errno 2] No such file or directory: '/devops/junk.txt'
2024-02-01 17:42:35,100 p=1787 u=jenkins n=ansible | fatal: [localhost]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n  File \"/home/jenkins/.ansible/tmp/ansible-tmp-1706827354.125057-1845-53715366175385/AnsiballZ_sftp.py\", line 107, in <module>\n    _ansiballz_main()\n  File \"/home/jenkins/.ansible/tmp/ansible-tmp-1706827354.125057-1845-53715366175385/AnsiballZ_sftp.py\", line 99, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/home/jenkins/.ansible/tmp/ansible-tmp-1706827354.125057-1845-53715366175385/AnsiballZ_sftp.py\", line 47, in invoke_module\n    runpy.run_module(mod_name='ansible.modules.sftp', init_globals=dict(_module_fqn='ansible.modules.sftp', _modlib_path=modlib_path),\n  File \"/usr/lib64/python3.9/runpy.py\", line 225, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/lib64/python3.9/runpy.py\", line 97, in _run_module_code\n    _run_code(code, mod_globals, init_globals,\n  File \"/usr/lib64/python3.9/runpy.py\", line 87, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_sftp_payload_w5bn7ztl/ansible_sftp_payload.zip/ansible/modules/sftp.py\", line 67, in <module>\n  File \"/tmp/ansible_sftp_payload_w5bn7ztl/ansible_sftp_payload.zip/ansible/modules/sftp.py\", line 62, in main\n  File \"/tmp/ansible_sftp_payload_w5bn7ztl/ansible_sftp_payload.zip/ansible/modules/sftp.py\", line 30, in transfer_file\n  File \"/home/jenkins/.local/lib/python3.9/site-packages/paramiko/sftp_client.py\", line 757, in put\n    file_size = os.stat(localpath).st_size\nFileNotFoundError: [Errno 2] No such file or directory: '/devops/junk.txt'\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}
2024-02-01 17:42:35,113 p=1787 u=jenkins n=ansible | PLAY RECAP *****************************************************************************************************************************************************
2024-02-01 17:42:35,119 p=1787 u=jenkins n=ansible | localhost                  : ok=1    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0

该文件当然是存在的。这是一个屏幕截图。

有什么线索吗?谢谢!

python-3.x ansible paramiko
1个回答
0
投票

sftp
模块是你写的吗?在错误消息中,我们看到它因以下
FileNotFoundError
异常而失败:

      File \"/home/jenkins/.local/lib/python3.9/site-packages/paramiko/sftp_client.py\", line 757, in put
        file_size = os.stat(localpath).st_size
    FileNotFoundError: [Errno 2] No such file or directory: '/devops/junk.txt'

它正在

本地计算机
上寻找/devops/junk.txt,但从您的剧本来看,您似乎正在尝试从远程计算机检索该文件。

看起来

src
dest
混淆了,或者代码不尊重
direction
属性的值。

© www.soinside.com 2019 - 2024. All rights reserved.