Code Monkey home page Code Monkey logo

ansible-ftp's Introduction

ftp

Transfers files and directories from or to ftp servers.

Synopsis

Transfers files and directories from or to FTP servers

Options

parameter required default choices comments
src yes Path on the source host that will be synchronized to the destination.
direction no push
  • push
  • pull
Specify the direction of the synchronization. In push mode the localhost or delegate is the source; In pull mode the remote FTP server is the source.
protocol no ftp
  • ftp
  • ftps
FTP protocol to use.
retries no 3 Specifies the number of retries the upload should by tried before it is considered failed.
dest yes Path on the destination host that will be synchronized from the source.
interval no 1 Configures the interval in seconds to wait between retries of the upload.
host yes FTP server.
ftp_mode no passive
  • passive
  • active
FTP mode.
user no The username used to authenticate with.
timeout no Timeout in seconds for FTP request.
password no The password used to authenticate with.
backup no False Create a remote backup file including the timestamp information so you can get the original file back if you somehow clobbered it incorrectly.
port no 21 FTP port.
tmp_dest no Absolute path of where temporary file is downloaded to. Defaults to TMPDIR, TEMP or TMP env variables or a platform specific value (https://docs.python.org/2/library/tempfile.html#tempfile.tempdir).
others no All arguments accepted by the file module also work when direction is pull.

Examples

# Upload a local file to a remote FTP server
- local_action:
    module: ftp
    host: my.ftp.server.net
    user: myuser
    password: mypassword
    src: /tmp/myfile.txt
    dest: /dest
    direction: push

# Download a directory from a remote FTP server
- local_action:
    module: ftp
    host: my.ftp.server.net
    user: myuser
    password: mypassword
    src: /backups
    dest: /var/backups/
    direction: pull

ansible-ftp's People

Contributors

melmorabity avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

ansible-ftp's Issues

module errors

hi . I'd like to transfer a file on to filezilla server, and this is my playbook

[root@centopingtest ansible]# cat copy.ftp.yml

  • name: PLAYBOOK COPY RUNNING ON FTP SERVER
    hosts: ftp_server
    gather_facts: no
    tasks:
    - local_action:
    module: ftp
    protocols: ftp
    ftp_mode: passive
    host: 10.227.5.196
    user: terna
    password: terna
    port: 21
    src: /backup/PE_9_config.2020-07-03@11:45:40
    dest: /file_config_bck
    direction: push

[root@centopingtest ansible]# ansible --version
ansible 2.9.9
config file = /home/user/Desktop/ansible/ansible.cfg
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.6/site-packages/ansible
executable location = /usr/bin/ansible
python version = 3.6.8 (default, Nov 21 2019, 19:31:34) [GCC 8.3.1 20190507 (Red Hat 8.3.1-4)]

when i play this playbook i've the follow errors:

PLAYBOOK: copy.ftp.yml *******************************************************************************************************************
Positional arguments: copy.ftp.yml
verbosity: 4
connection: smart
timeout: 10
become_method: sudo
tags: ('all',)
inventory: ('/home/user/Desktop/ansible/hosts',)
forks: 5
1 plays in copy.ftp.yml

PLAY [PLAYBOOK COPY RUNNING ON FTP SERVER] ***********************************************************************************************
META: ran handlers

TASK [ftp] *******************************************************************************************************************************
task path: /home/user/Desktop/ansible/copy.ftp.yml:6
ESTABLISH LOCAL CONNECTION FOR USER: root
EXEC /bin/sh -c 'echo ~root && sleep 0'
EXEC /bin/sh -c '( umask 77 && mkdir -p "echo /root/.ansible/tmp"&& mkdir /root/.ansible/tmp/ansible-tmp-1594024518.8450358-58209-225072018467028 && echo ansible-tmp-1594024518.8450358-58209-225072018467028="echo /root/.ansible/tmp/ansible-tmp-1594024518.8450358-58209-225072018467028" ) && sleep 0'
Using module file /usr/lib/python3.6/site-packages/ansible/modules/files/ftp.py
PUT /root/.ansible/tmp/ansible-local-58202tsavmnxn/tmp1e2irpzy TO /root/.ansible/tmp/ansible-tmp-1594024518.8450358-58209-225072018467028/AnsiballZ_ftp.py
EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-tmp-1594024518.8450358-58209-225072018467028/ /root/.ansible/tmp/ansible-tmp-1594024518.8450358-58209-225072018467028/AnsiballZ_ftp.py && sleep 0'
EXEC /bin/sh -c '/usr/bin/python3.6 /root/.ansible/tmp/ansible-tmp-1594024518.8450358-58209-225072018467028/AnsiballZ_ftp.py && sleep 0'
EXEC /bin/sh -c 'rm -f -r /root/.ansible/tmp/ansible-tmp-1594024518.8450358-58209-225072018467028/ > /dev/null 2>&1 && sleep 0'
fatal: [ftp_server -> localhost]: FAILED! => {
"changed": false,
"invocation": {
"module_args": {
"dest": "/file_config_bck",
"direction": "push",
"ftp_mode": "passive",
"host": "10.227.5.196",
"password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"port": 21,
"protocols": "ftp",
"src": "/backup/PE_9_config.2020-07-03@11:45:40",
"user": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER"
}
},
"msg": "Unsupported parameters for (ftp) module: protocols Supported parameters include: attributes, backup, content, delimiter, dest, direction, directory_mode, follow, force, ftp_mode, group, host, interval, mode, owner, password, port, protocol, regexp, remote_src, retries, selevel, serole, setype, seuser, src, timeout, tmp_dest, unsafe_writes, user"
}

Do you have an idea?hlep me ...thanks

Error when using FTPS protocol

I'm trying to use the module to download a file from an FTPS server, and get an error. I downloaded the latest master.

$ ansible --version
ansible 2.10.8
  config file = /Users/kmhait/.ansible.cfg
  configured module search path = ['/Users/user/.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)]
KMHAITs-MacBook-Pro:exa-playbooks kmhait$ 

Here's the task

---
# tasks file for test-ftps
- ftp:
    host: ftp.domain.com
    protocol: ftps
    user: ***
    password: ***
    src: "/path/config.xml"
    dest: /tmp
    direction: pull

Here's the error.

fatal: [10.227.26.97]: FAILED! => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": false,
    "module_stderr": "Exception calling \"Create\" with \"1\" argument(s): \"At line:4 char:21\r\n+ def _ansiballz_main():\r\n+                     ~\r\nAn expression was expected after '('.\r\nAt line:13 char:27\r\n+     except (AttributeError, OSError):\r\n+                           ~\r\nMissing argument in parameter list.\r\nAt line:15 char:29\r\n+     excludes = set(('', '.', scriptdir))\r\n+                             ~\r\nMissing expression after ','.\r\nAt line:15 char:30\r\n+     excludes = set(('', '.', scriptdir))\r\n+                              ~~~~~~~~~\r\nUnexpected token 'scriptdir' in expression or statement.\r\nAt line:15 char:29\r\n+     excludes = set(('', '.', scriptdir))\r\n+                             ~\r\nMissing closing ')' in expression.\r\nAt line:15 char:39\r\n+     excludes = set(('', '.', scriptdir))\r\n+                                       ~\r\nUnexpected token ')' in expression or statement.\r\nAt line:15 char:40\r\n+     excludes = set(('', '.', scriptdir))\r\n+                                        ~\r\nUnexpected token ')' in expression or statement.\r\nAt line:22 char:7\r\n+     if sys.version_info < (3,):\r\n+       ~\r\nMissing '(' after 'if' in if statement.\r\nAt line:22 char:30\r\n+     if sys.version_info < (3,):\r\n+                              ~\r\nMissing expression after ','.\r\nAt line:22 char:25\r\n+     if sys.version_info < (3,):\r\n+                         ~\r\nThe '<' operator is reserved for future use.\r\nNot all parse errors were reported.  Correct the reported errors and try again.\"\r\nAt line:10 char:1\r\n+ $exec_wrapper = [ScriptBlock]::Create($split_parts[0])\r\n+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException\r\n    + FullyQualifiedErrorId : ParseException\r\n \r\nThe expression after '&' in a pipeline element produced an object that was not valid. It must result in a command \r\nname, a script block, or a CommandInfo object.\r\nAt line:11 char:2\r\n+ &$exec_wrapper\r\n+  ~~~~~~~~~~~~~\r\n    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException\r\n    + FullyQualifiedErrorId : BadExpression\r\n ",
    "module_stdout": "",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1
}

I can't connect to the ftp server

This is playbook:

---
- name: CREATE BACKUP SERVERS
  hosts: all
  gather_facts: no
  become: yes

  tasks:
  - name: CONNECT FTP
    local_action:
      module: ftp
      host: 192.168.1.1
      user: admin
      password: 123456
      src: /home/ansible/create_backup/tmp
      dest: /
      direction: pull

This is error log:

[ansible@Ansible create_backup]$ ansible-playbook -l host01 ftp.yml --ask-vault-pass -vvvvv
Using /home/ansible/create_backup/ansible.cfg as config file
Vault password:
Loading callback plugin default of type stdout, v2.0 from /usr/lib/python2.6/site-packages/ansible/plugins/callback/__init__.pyc

PLAYBOOK: ftp.yml *********************************************************************************************************************************************************************************
1 plays in ftp.yml

PLAY [CREATE BACKUP SERVERS] *****************************************************************************************************************************************************
META: ran handlers

TASK [CONNECT FTP] ********************************************************************************************************************************************************************************
task path: /home/ansible/create_backup/ftp.yml:9
fatal: [host01]: FAILED! => {
    "failed": true,
    "msg": "Could not find imported module support code for ftp.  Looked for either BOOLEANS.py or convert_bool.py"
}
        to retry, use: --limit @/home/ansible/create_backup/ftp.retry

PLAY RECAP ****************************************************************************************************************************************************************************************
host01                    : ok=0    changed=0    unreachable=0    failed=1

This is ansible version:

> ansible --version
ansible 2.3.0.0
  config file = /home/ansible/create_backup/ansible.cfg
  configured module search path = [u'/usr/share/ansible/modules']
  python version = 2.6.6 (r266:84292, Aug 18 2016, 15:13:37) [GCC 4.4.7 20120313 (Red Hat 4.4.7-17)]

I copied the module ftp.py to the directory /usr/share/ansible/modules/
Please help, what could be the problem?

Cannot connect to secure FTP server, says login incorrect

I have the following Ansible task

- name: Download artifact
  block:
  - name: "Download {{ rel_path }}"
    ftp:
      host: "sftp.company.com"
      user: "{{ sftp_user }}"
      password: "{{ sftp_password }}"
      src: "/devops/exa-3rdparty/{{ rel_path }}"
      dest: "/tmp"
      direction: pull
      timeout: 60
      protocol: ftps
    delegate_to: localhost
    register: download_st

But get the following, even though I know that I have the correct credentials

The full traceback is:
  File "/var/folders/kb/mk006j312mz2nyxbxd66gmth9fk800/T/ansible_ftp_payload_12u2ey9r/ansible_ftp_payload.zip/ansible/modules/ftp.py", line 544, in main
  File "/var/folders/kb/mk006j312mz2nyxbxd66gmth9fk800/T/ansible_ftp_payload_12u2ey9r/ansible_ftp_payload.zip/ansible/modules/ftp.py", line 169, in wrapper
  File "/var/folders/kb/mk006j312mz2nyxbxd66gmth9fk800/T/ansible_ftp_payload_12u2ey9r/ansible_ftp_payload.zip/ansible/modules/ftp.py", line 496, in _ftp_connect
  File "/usr/local/Cellar/[email protected]/3.9.4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ftplib.py", line 746, in login
    return super().login(user, passwd, acct)
  File "/usr/local/Cellar/[email protected]/3.9.4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ftplib.py", line 414, in login
    resp = self.sendcmd('PASS ' + passwd)
  File "/usr/local/Cellar/[email protected]/3.9.4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ftplib.py", line 281, in sendcmd
    return self.getresp()
  File "/usr/local/Cellar/[email protected]/3.9.4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ftplib.py", line 254, in getresp
    raise error_perm(resp)
fatal: [10.227.26.97]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "attributes": null,
            "backup": false,
            "dest": "/tmp",
            "direction": "pull",
            "ftp_mode": "passive",
            "group": null,
            "host": "stp.company.com",
            "interval": 1,
            "mode": null,
            "owner": null,
            "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "port": 21,
            "protocol": "ftps",
            "retries": 3,
            "selevel": null,
            "serole": null,
            "setype": null,
            "seuser": null,
            "src": "/devops/exa-3rdparty/7z/7z2107-x64.exe",
            "timeout": 60,
            "tmp_dest": null,
            "unsafe_writes": false,
            "user": "devops"
        }
    },
    "msg": "Unable to connect to FTP server: 530 Login incorrect."

If I connect to a non-SFTP server it works.

Unable to upload to remote FTPS site

When I try to upload to a remote site (in this case an Azure WebApp repo), I get an error message:

Unable to get status for destination /repository: 550 The system cannot find the file specified.

I'm using a playbook like so:

  • name: Testing local file upload to remote FTP server
    hosts: localhost
    connection: local
    gather_facts: no
    tasks:
    • local_action:
      module: ftp
      protocol: ftps
      host: somesite.ftp.com
      user: "mycoolusername"
      password: "reallyhardpassword"
      src: testfile.txt
      dest: "/repository/"
      direction: push

Seen this problem or have any ideas?

I cannot pull a specified file

Hi,

When I pull a specified file, But I cannot get successful.

env: Ansible AWX 13.x

Discription:
I can pull directory ,but cannot pull a specified file.
When I try pull a specified file .The source path display difference between "msg:" and "invocation-->module_args-->src:" in this result .
like this png:
微信图片_20210419153117

Finally , I run it failed.

Problem with 'backup' parameter

Hi,

when i try to use your module, ill get

KeyError: 'backup'

The full traceback is:
Traceback (most recent call last):
  File "/home/random/.ansible/tmp/ansible-tmp-1601392183.2-8280-274907447958570/AnsiballZ_ftp.py", line 102, in <module>
    _ansiballz_main()
  File "/home/random/.ansible/tmp/ansible-tmp-1601392183.2-8280-274907447958570/AnsiballZ_ftp.py", line 94, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/home/random/.ansible/tmp/ansible-tmp-1601392183.2-8280-274907447958570/AnsiballZ_ftp.py", line 40, in invoke_module
    runpy.run_module(mod_name='ansible.modules.ftp', init_globals=None, run_name='__main__', alter_sys=True)
  File "/usr/lib/python3.8/runpy.py", line 206, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File "/usr/lib/python3.8/runpy.py", line 96, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/usr/lib/python3.8/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/tmp/ansible_ftp_payload_jgpafi95/ansible_ftp_payload.zip/ansible/modules/ftp.py", line 563, in <module>
  File "/tmp/ansible_ftp_payload_jgpafi95/ansible_ftp_payload.zip/ansible/modules/ftp.py", line 552, in main
  File "/tmp/ansible_ftp_payload_jgpafi95/ansible_ftp_payload.zip/ansible/modules/ftp.py", line 355, in _ftp_upload
KeyError: 'backup'
fatal: [localhost]: FAILED! => {
    "changed": false, 
    "module_stderr": "Traceback (most recent call last):\n  File \"/home/random/.ansible/tmp/ansible-tmp-1601392183.2-8280-274907447958570/AnsiballZ_ftp.py\", line 102, in <module>\n    _ansiballz_main()\n  File \"/home/david/.ansible/tmp/ansible-tmp-1601392183.2-8280-274907447958570/AnsiballZ_ftp.py\", line 94, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/home/david/.ansible/tmp/ansible-tmp-1601392183.2-8280-274907447958570/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/lib/python3.8/runpy.py\", line 206, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/lib/python3.8/runpy.py\", line 96, in _run_module_code\n    _run_code(code, mod_globals, init_globals,\n  File \"/usr/lib/python3.8/runpy.py\", line 86, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_ftp_payload_jgpafi95/ansible_ftp_payload.zip/ansible/modules/ftp.py\", line 563, in <module>\n  File \"/tmp/ansible_ftp_payload_jgpafi95/ansible_ftp_payload.zip/ansible/modules/ftp.py\", line 552, in main\n  File \"/tmp/ansible_ftp_payload_jgpafi95/ansible_ftp_payload.zip/ansible/modules/ftp.py\", line 355, in _ftp_upload\nKeyError: 'backup'\n", 
    "module_stdout": "", 
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", 
    "rc": 1
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.