-
Notifications
You must be signed in to change notification settings - Fork 2
/
ftp.yml
102 lines (89 loc) · 2.67 KB
/
ftp.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
---
- name: start FTP server
hosts: server
gather_facts: false
become: true
vars:
quiet: false
tasks:
- name: enable anonymous FTP
lineinfile:
path=/etc/vsftpd.conf
regexp='anonymous_enable='
line='anonymous_enable=YES'
- name: enable IPv6 listen
lineinfile:
path=/etc/vsftpd.conf
regexp='listen_ipv6='
line='listen_ipv6=YES'
- name: use / as a FTP user's home directory
user: name=ftp home=/
- name: restart FTP server
# https://stackoverflow.com/questions/30162528/ansible-service-restart-failed
command: systemctl restart vsftpd
register: result
changed_when: false
- name: print out the result
debug: var=result
when: not quiet|bool
- name: FTP GET from server
hosts: client
vars:
path: index.html
dest: /tmp
timeout: 3
debug: false
quiet: false
gather_facts: false
tasks:
- name: check FTP GET (IPv4)
get_url:
url: "ftp://ftp@{{ server.ipv4 }}/{{ path }}"
dest: "{{ dest }}"
timeout: "{{ timeout }}"
register: result
ignore_errors: "{{ debug }}"
- name: print out the result
debug: var=result
when: not quiet|bool
- name: check FTP GET (private IPv4)
get_url:
url: "ftp://ftp@{{ server.ipv4_private }}/{{ path }}"
dest: "{{ dest }}"
timeout: "{{ timeout }}"
register: result
ignore_errors: "{{ debug }}"
- name: print out the result
debug: var=result
when: not quiet|bool
- name: check FTP GET (IPv6)
# It seems get_url module doesn't support IPv6 raw address format:
# https://github.com/ansible/ansible/issues/4482#issuecomment-307961120
command: >
curl --connect-timeout "{{ timeout }}" "ftp://ftp@[{{ server.ipv6 }}]/{{ path }}" -o "{{ dest }}/{{ path }}"
register: result
ignore_errors: "{{ debug }}"
changed_when: false
- name: print out the result
debug: var=result
when: not quiet|bool
- name: check FTP GET (Floating IP)
# get_url module doesn't have a passive support.
# http://docs.ansible.com/ansible/get_url_module.html
command: >
curl --connect-timeout "{{ timeout }}" --ftp-pasv "ftp://ftp@{{ server.flip }}/{{ path }}" -o "{{ dest }}/{{ path }}"
register: result
ignore_errors: "{{ debug }}"
changed_when: false
- name: print out the result
debug: var=result
when: not quiet|bool
- name: stop FTP server
hosts: server
gather_facts: false
become: true
tasks:
- name: stop FTP server
command: systemctl stop vsftpd
register: result
changed_when: false