在運行中會出現很多錯誤,如需詳細的執行過程需要在命令中加上-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:更改ansible配置,開啓遠程被控機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
Q5:安裝過程中pycrypto編譯錯誤
會產生報錯
Installed /usr/lib/python2.6/site-packages/ansible-2.2.0-py2.6.egg Processing dependencies for ansible==2.2.0 Searching for pycrypto>=2.6 Reading http://pypi.python.org/simple/pycrypto/ Best match: pycrypto 2.6.1 ...... RuntimeError: autoconf error
A5:
嘗試easy_install pycrypto-2.6.1.tar.gz sudo yum install gcc
未完待續......