在运行中会出现很多错误,如需详细的执行过程需要在命令中加上-vvvv,会有蓝色字体表示执行过程
ansible较为全面的讨论区:
https://github.com/ansible/ansible/issues
Q1:pip安装ansible附加包时编译错误
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
| $ sudo pip install paramiko PyYAML Jinja2 httplib2six
Downloading/unpacking paramiko
Cannot fetch index base URL http://pypi.python.org/simple/
Downloading paramiko-2.0.2.tar.gz (1.2Mb): 1.2Mb downloaded
Running setup.py egg_info for package paramiko
Downloading/unpacking PyYAML
Downloading PyYAML-3.12.tar.gz (253Kb): 253Kb downloaded
Running setup.py egg_info for package PyYAML
Downloading/unpacking Jinja2
Real name of requirement Jinja2 is jinja2
Downloading Jinja2-2.8.tar.gz (357Kb): 45Kb downloaded
Exception:
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 126, in main
self.run(options, args)
File "/usr/lib/python2.7/dist-packages/pip/commands/install.py", line 223, in run
requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
File "/usr/lib/python2.7/dist-packages/pip/req.py", line 955, in prepare_files
self.unpack_url(url, location, self.is_download)
File "/usr/lib/python2.7/dist-packages/pip/req.py", line 1072, in unpack_url
return unpack_http_url(link, location, self.download_cache, only_download)
File "/usr/lib/python2.7/dist-packages/pip/download.py", line 441, in unpack_http_url
download_hash = _download_url(resp, link, temp_location)
File "/usr/lib/python2.7/dist-packages/pip/download.py", line 366, in _download_url
chunk = resp.read(4096)
File "/usr/lib/python2.7/socket.py", line 380, in read
data = self._sock.recv(left)
File "/usr/lib/python2.7/httplib.py", line 569, in read
s = self.fp.read(amt)
File "/usr/lib/python2.7/socket.py", line 380, in read
data = self._sock.recv(left)
File "/usr/lib/python2.7/ssl.py", line 241, in recv
return self.read(buflen)
File "/usr/lib/python2.7/ssl.py", line 160, in read
return self._sslobj.read(len)
error: [Errno 104] Connection reset by peer
Storing complete log in /home/ansible/.pip/pip.log
error: Setup script exited with error: command 'gcc' failed with exit status 1
make: *** [install] Error 1
|
A1:未安装Python dev库
1
2
| $ sudo apt-get install python-dev
$ sudo apt-get install libffi-dev
|
Q2:源码编译或无法运行,提示没有hosts文件
1
2
3
| $ ansible all -m ping
[WARNING]: Host file not found: /etc/ansible/hosts
[WARNING]: provided hosts list is empty, only localhost is available
|
A2:在源码的example目录中可以找到hosts文件
1
2
| #mkdir /etc/ansible
#cp -r /home/ansible/ansible/example/* /etc/ansible
|
Q3:Failed to connect to the host via ssh错误
1
2
3
4
5
6
| $ansible all -m ping -u root
192.168.3.2 | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh.",
"unreachable": true
}
|
A3:两种方法
在/etc/ansible/hosts配置将注释驱动 1
2
| [ssh_connection]
scp_if_ssh = True
|
或者命令中带有--ssh-extra-args="-o ControlPath=none" --sftp-extra-args="-o ControlPath=none
Q4:场景为已经配置好的机器,公钥已经发送,但是无法联通
1
2
3
4
5
6
| $ ansible share -m ping -u root
192.168.30.200 | UNREACHABLE! => {
"changed": false,
"msg": "SSH Error: data could not be sent to the remote host. Make sure this host can be reached over ssh",
"unreachable": true
}
|
A4:开启远程被控机sftp权限
原因:在/etc/ansible/ansible.cfg中开启下列选项
1
2
| [ssh_connection]
scp_if_ssh = True
|
配置后需要检查远程被控机器的ssh是否打开sftp功能,否则无法联通
1
2
| vi /etc/ssh/sshd_config
Subsystem sftp /usr/lib/openssh/sftp-server
|
|