On a Mac OS
$ ansible --version
ansible 2.10.8
config file = /Users/cfouts/.ansible.cfg
configured module search path = ['/Users/myUser/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/Cellar/ansible/3.3.0/libexec/lib/python3.9/site-packages/ansible
executable location = /usr/local/bin/ansible
python version = 3.9.4 (default, Apr 5 2021, 01:50:46) [Clang 12.0.0 (clang-1200.0.32.29)]
This is a follow up to In Ansible, how to download from a secure FTP (SFTP) server?
I'm trying to modify the ftp.py library mentioned in the answer in above post to support SFTP by adding the pysftp
library. So I added
import contextlib
from enum import Enum
import ftplib
import hashlib
import os
import tempfile
import time
import pysftp <--------- Added this
Now I'm getting
TASK [downloader : Download] **************************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ModuleNotFoundError: No module named 'pysftp'
fatal: [10.227.x.x]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n File \"/Users/myUser/.ansible/tmp/ansible-tmp-1679500320.631737-50774-110602676057179/AnsiballZ_ftp.py\", line 102, in <module>\n _ansiballz_main()\n File \"/Users/myUser/.ansible/tmp/ansible-tmp-1679500320.631737-50774-110602676057179/AnsiballZ_ftp.py\", line 94, in _ansiballz_main\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n File \"/Users/myUser/.ansible/tmp/ansible-tmp-1679500320.631737-50774-110602676057179/AnsiballZ_ftp.py\", line 40, in invoke_module\n runpy.run_module(mod_name='ansible.modules.ftp', init_globals=None, run_name='__main__', alter_sys=True)\n File \"/usr/local/Cellar/python@3.9/3.9.4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py\", line 210, in run_module\n return _run_module_code(code, init_globals, run_name, mod_spec)\n File \"/usr/local/Cellar/python@3.9/3.9.4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py\", line 97, in _run_module_code\n _run_code(code, mod_globals, init_globals,\n File \"/usr/local/Cellar/python@3.9/3.9.4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py\", line 87, in _run_code\n exec(code, run_globals)\n File \"/var/folders/kb/mk006j312mz2nyxbxd66gmth9fk800/T/ansible_ftp_payload_3u9acyhb/ansible_ftp_payload.zip/ansible/modules/ftp.py\", line 27, in <module>\nModuleNotFoundError: No module named 'pysftp'\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}
It can't find the pysftp
module. I even added this task before calling the ftp.py
module
- name: Install pysftp
pip:
name:
- pysftp
delegate_to: localhost
- name: Download from SFTP server using ftp.py library
ftp:
protocol: sftp
...
delegate_to: localhost
But I just get
TASK [downloader : Install pysftp] ********************************************************************************************************************
ok: [10.227.x.x]
which indicates that the module is installed?
What gives? How can I fix this? TIA