0

Hi I have a task which requires ftp a file from remote box to ansible controlled machine.I am using expect based FTP,so want the ansible to fail if file does not exist on the remote box.Following is my code. I am using a register variable.But i dont see the debug displaying the register contents.

     - name: copy files remote
       shell: |
         set timeout 1000
         spawn ftp {{ buildIP }}

         expect ":"
         send "{{ build_user }}\n"

    expect "ssword:"
    send "{{ build_password }}\n"

    expect "ftp>"
    send "get {{ build_path }} /root/Desktop/Sanity/{{  TID }}/{{ Image_dir }}/{{ build_filename }}\n"

    expect "ftp>"
    send "quit\n"

    set multiPrompt {[#$]}
    expect -re $multiPrompt
    exit 0
  args:
    executable: /usr/bin/expect
  register: shell_output
  tags: copy_source_code
- debug:
    var: shell_output.stdout_lines
Suzanno Hogwarts
  • 323
  • 2
  • 3
  • 12
  • "i don't see the debug display the register contents" ... and instead you see what? Also, I hope dearly that your yaml file is not **really** indented like that, otherwise of course you won't see anything – mdaniel Oct 21 '18 at 03:35
  • I dont see debug as task as listed "shell_result.stdout_lines": [ "1", "10.106.81.102_46_1_a_P101_main.info", "10.217.204.80_48_6_P10_main.info", "10.220.225.4_65_1_P2_main.info", "10.71.137.55_cfiles", "10.71.137.9_cfiles", "17.138.8.10.pl", "17.138.8.12.pl", "17.138.8.1.pl", "17.138.8.2.pl", "17.138.8.3.pl", "17.138.8.4.pl", "17.138.8.6.pl", "17.138.8.7.pl", "17.138.8.8.pl", } debug is not getting played – Suzanno Hogwarts Oct 23 '18 at 05:19

1 Answers1

0

I would recommend using get_url for fetching files from FTP instead of expect,It will show whether the task failed or succeeded in the play recap

example play:

---
- hosts: localhost
  tasks:
    - name: FTP Download
      get_url: url=ftp://username:password@localhost/file.zip dest=/tmp
      register: get_url_result

if the file is not present in the FTP server, output will be similar to this:

PLAY RECAP ********************************************************

localhost : ok=1 changed=0 unreachable=0
failed=1

In the task error details you can find the "not found" error as well

ClumsyPuffin
  • 3,909
  • 1
  • 17
  • 17