在运行中会出现很多错误,如需详细的执行过程需要在命令中加上-vvvv,会有蓝色字体表示执行过程
ansible较为全面的讨论区:
https://github.com/ansible/ansible/issues
Q1:pip安装ansible附加包时编译错误
$ 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库
$ sudo apt-get install python-dev $ sudo apt-get install libffi-dev
Q2:源码编译或无法运行,提示没有hosts文件
$ 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文件
#mkdir /etc/ansible #cp -r /home/ansible/ansible/example/* /etc/ansible
Q3:Failed to connect to the host via ssh错误
$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配置将注释驱动
[ssh_connection] scp_if_ssh = True
或者命令中带有--ssh-extra-args="-o ControlPath=none" --sftp-extra-args="-o ControlPath=none
Q4:场景为已经配置好的机器,公钥已经发送,但是无法联通
$ 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中开启下列选项
[ssh_connection] scp_if_ssh = True
配置后需要检查远程被控机器的ssh是否打开sftp功能,否则无法联通
vi /etc/ssh/sshd_config Subsystem sftp /usr/lib/openssh/sftp-server
未完待续......
本文出自 “M层” 博客,请务必保留此出处http://mengix.blog.51cto.com/7194660/1862690
原文地址:http://mengix.blog.51cto.com/7194660/1862690