I have my playbook yml script below:
---
- name: Download files from FTP
hosts: localhost
gather_facts: false
vars_prompt:
- name: target_host
prompt: "Target Host IP: "
- name: auth_method
prompt: "Authentication method (password/key): "
tasks:
- name: Gather target host credentials
when: auth_method == 'password'
vars_prompt:
- name: ssh_user
prompt: "SSH Username: "
- name: ssh_pass
prompt: "SSH Password: "
private: true
- name: Gather key path for target host
when: auth_method == 'key'
vars_prompt:
- name: ssh_user
prompt: "SSH Username: "
- name: key_path
prompt: "Path to SSH Key: "
- name: Gather FTP credentials
vars_prompt:
- name: ftp_username
prompt: "FTP Username: "
- name: ftp_password
prompt: "FTP Password: "
private: true
- name: Download files from FTP on target host
hosts: "{{ target_host }}"
gather_facts: false
remote_user: "{{ ssh_user }}"
become: true
become_user: root
become_method: sudo
tasks:
- name: Create upgrade directory if not exist
file:
path: /root/upgrade
state: directory
- name: Download file from FTP
get_url:
url: "ftp://something.com/{{ file_path }}"
dest: "/root/upgrade/{{ file_path }}"
force: yes
timeout: 30
remote_src: yes
validate_certs: false
url_username: "{{ ftp_username }}"
url_password: "{{ ftp_password }}"
register: download_result
ignore_errors: true
- name: Check if file downloaded successfully
debug:
msg: "File '{{ file_path }}' downloaded successfully."
when: download_result is success
- name: Display error message if file download failed
debug:
msg: "Failed to download file '{{ file_path }}'. Please check the file path or FTP credentials."
when: download_result is failed and file_path != 'q'
- name: Exit playbook if 'q' is pressed
meta: end_play
when: file_path == 'q'
I have checked the indentation and everything seems to be correct from my understanding. But it shows the below error when I try to run it:
root@DESKTOP-VLCQSJO:/home/ridhoswasta/tassta-automation# ansible-playbook download-files.yml
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match
'all'
ERROR! unexpected parameter type in action: <class 'ansible.parsing.yaml.objects.AnsibleSequence'>
The error appears to be in '/home/ridhoswasta/tassta-automation/download-files.yml': line 13, column 7, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
tasks:
- name: Gather target host credentials
^ here
root@DESKTOP-VL
Any advice what could be wrong?
Thanks!