{"id":103239,"date":"2024-08-23T22:33:19","date_gmt":"2024-08-23T14:33:19","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=103239"},"modified":"2024-08-23T22:33:19","modified_gmt":"2024-08-23T14:33:19","slug":"ansible-install-all","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/ansible-install-all.html","title":{"rendered":"ansible\u4f7f\u7528\u5c0f\u7ed3\uff1aansible\u7684\u5b89\u88c5"},"content":{"rendered":"
Ansible \u662f\u4e00\u4e2a\u914d\u7f6e\u7ba1\u7406\u548c\u5e94\u7528\u90e8\u7f72\u5de5\u5177\uff0c\u529f\u80fd\u7c7b\u4f3c\u4e8e\u76ee\u524d\u4e1a\u754c\u7684\u914d\u7f6e\u7ba1\u7406\u5de5\u5177 Chef,Puppet,Saltstack\u3002Ansible \u662f\u901a\u8fc7 Python \u8bed\u8a00\u5f00\u53d1\u3002Ansible \u5e73\u53f0\u7531 Michael DeHaan \u521b\u5efa\uff0c\u4ed6\u540c\u65f6\u4e5f\u662f\u77e5\u540d\u8f6f\u4ef6 Cobbler \u4e0e Func \u7684\u4f5c\u8005\u3002Ansible \u7684\u7b2c\u4e00\u4e2a\u7248\u672c\u53d1\u5e03\u4e8e 2012 \u5e74 2 \u6708\u3002Ansible \u9ed8\u8ba4\u901a\u8fc7 SSH \u534f\u8bae\u7ba1\u7406\u673a\u5668\uff0c\u6240\u4ee5 Ansible \u4e0d\u9700\u8981\u5b89\u88c5\u5ba2\u6237\u7aef\u7a0b\u5e8f\u5728\u670d\u52a1\u5668\u4e0a\u3002\u60a8\u53ea\u9700\u8981\u5c06 Ansible \u5b89\u88c5\u5728\u4e00\u53f0\u670d\u52a1\u5668\uff0c\u5728 Ansible \u5b89\u88c5\u5b8c\u540e\uff0c\u60a8\u5c31\u53ef\u4ee5\u53bb\u7ba1\u7406\u63a7\u5236\u5176\u5b83\u670d\u52a1\u5668\u3002\u4e0d\u9700\u8981\u4e3a\u5b83\u914d\u7f6e\u6570\u636e\u5e93\uff0cAnsible \u4e0d\u4f1a\u4ee5 daemons \u65b9\u5f0f\u6765\u542f\u52a8\u6216\u4fdd\u6301\u8fd0\u884c\u72b6\u6001\u3002Ansible \u53ef\u4ee5\u5b9e\u73b0\u4ee5\u4e0b\u76ee\u6807\uff1a<\/p>\n
\u6839\u636e Ansible \u5b98\u65b9\u63d0\u4f9b\u7684\u4fe1\u606f\uff0c\u5f53\u524d\u4f7f\u7528 Ansible \u7684\u7528\u6237\u6709\uff1aevernote\u3001rackspace\u3001NASA\u3001Atlassian\u3001twitter \u7b49\u3002<\/p>\n
\u6ce8\uff1a\u4ee5\u4e0a\u7b80\u4ecb\u6765\u81ea\u4e8eibm developerworks \u4e2d\u56fd\u7684\u4ecb\u7ecd\u3002<\/p>\n
\u4ee5centos\u4e3a\u4f8b\uff0c\u9ed8\u8ba4\u5728\u6e90\u91cc\u6ca1\u6709ansible\uff0c\u4e0d\u8fc7\u5728fedora epel\u6e90<\/a>\u91cc\u6709ansible\uff0c\u914d\u7f6e\u5b8cepel \u6e90\u540e\uff0c\u53ef\u4ee5\u76f4\u63a5\u901a\u8fc7yum \u8fdb\u884c\u5b89\u88c5\u3002\u8fd9\u91cc\u4ee5centos6.8\u4e3a\u4f8b\uff1a<\/p>\n \u5728ubuntu\u53ca\u5176\u884d\u751f\u7248\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u589e\u52a0ppa\u6e90\u8fdb\u884capt-get\u5b89\u88c5\uff0c\u5177\u4f53\u5982\u4e0b\uff1a<\/p>\n 3\u3001\u6e90\u7801\u5b89\u88c5<\/strong> \u6700\u540e\u901a\u8fc7github<\/a>\u6216pypi\u4e0a<\/a>\u4e0b\u8f7dansible\u6e90\u7801\u5305\uff0c\u901a\u8fc7python setup.py install \u5b89\u88c5\u5373\u53ef\u3002\u7531\u4e8e\u5b89\u88c5\u8fc7\u7a0b\u76f8\u5bf9\u7b80\u5355\uff0c\u8fd9\u91cc\u7565\u8fc7\uff0c\u4e3b\u8981\u4ecb\u7ecd\u5b89\u88c5\u540e\uff0c\u53ef\u80fd\u9047\u5230\u7684\u95ee\u9898\u3002<\/p>\n a\u3001\u5b89\u88c5PyYAML\u65f6\uff0c\u62a5\u9519\u5982\u4e0b\uff1a<\/p>\n \u5728centos6.8\u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7yum -y install libyaml \u5305\u89e3\u51b3\uff0c\u6216\u8005\u4eceISO\u6587\u4ef6\u4e2d\u63d0\u4f9b\u8be5\u5305\uff0c\u901a\u8fc7rpm -ivh\u8fdb\u884c\u5b89\u88c5\u3002<\/p>\n b\u3001\u5b89\u88c5\u5b8cansible\u662f\uff0c\u62a5\u9519\u5982\u4e0b\uff1a<\/p>\n import paramiko\u5305\u65f6\uff0c\u62a5\u9519\u5982\u4e0b\uff1a<\/p>\n \u7ecf\u7f51\u4e0a\u67e5\u627e\uff0c\u786e\u8ba4\u4e3apycrypto\u5305\u5b89\u88c5\u65f6\u4f9d\u8d56\u7684GMP\u7248\u672c\u4e0d\u5bf9\u7684\u95ee\u9898\uff0c\u5177\u4f53\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u9a8c\u8bc1\uff1a<\/p>\n \u89e3\u51b3\u65b9\u6cd5\uff1a<\/strong><\/p>\n \u6253\u5f00 \/usr\/lib64\/python2.6\/site-packages\/Crypto\/Util\/number.py \u6587\u4ef6\uff0c\u53ef\u4ee5 \u770b\u5230 56 \u884c\u4e0a\u7684\u6ce8\u91ca\u8bf4\u660e\uff0c\u8981\u6c42 libgmp \u4e3a v5 \u4ee5\u4e0a\u7248\u672c\u3002\u800c\u7cfb\u7edf\u73b0\u6709\u7248\u672c\u4e3a 4.1.4\uff0c\u628a\u4ee5\u4e0b\u4e24\u884c\u6682\u65f6\u6ce8\u91ca\u6389\uff0cAnsible \u6267\u884c\u6b63\u5e38\u3002<\/p>\n \u4e0d\u8fc7\uff0c\u6b64\u65b9\u6cd5\u53ea\u662f\u4e34\u65f6\u52a0\u4ee5\u89e3\u51b3\uff0c\u66f4\u597d\u7684\u65b9\u5f0f\u662f\u53bb\u5c06 libgmp \u5347\u7ea7\u5230\u7b26\u5408\u8981\u6c42\u7684\u7248\u672c\u3002<\/p>\n c\u3001\u6267\u884c\u65f6\u62a5\u9519<\/p>\n \u5b89\u88c5sshpass\u7a0b\u5e8f<\/a>\u3002\u9ed8\u8ba4\u6e90\u91cc\u6ca1\u6709\uff0c\u6211\u8fd9\u91cc\u9009\u62e9\u76f4\u63a5\u4ecesohu\u6e90\u91cc\u4e0b\u8f7d\u5b89\u88c5\u3002<\/p>\n \u8fd9\u91cc\u4ee5pypi\u4e0a\u4e0b\u8f7d\u7684\u6e90\u7801\u5185\u6709\u4e00\u4e2aexamles\u5305\uff0c\u53ef\u4ee5\u5c06\u4f7f\u7528\u8be5\u793a\u4f8b\u6587\u4ef6\u505a\u4e3a\u9ed8\u8ba4\u914d\u7f6e\uff0c\u5177\u4f53\u5982\u4e0b\uff1a<\/p>\n \u4f7f\u7528\u9ed8\u8ba4\u793a\u4f8b\u914d\u7f6e\u6587\u4ef6\u540e\uff0c\u7f16\u8f91\/etc\/ansible\/hosts\u6587\u4ef6\uff0c\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u9a8c\u8bc1ansible\u662f\u5426\u53ef\u7528\uff1a<\/p>\n \u4ee5\u4e0a\u7684\u914d\u7f6e\u4e2d\uff0c\u6211\u914d\u7f6e\u4e86\u4e00\u4e2atest\u7ec4\uff0c\u8be5\u7ec4\u4e0b\u6709\u4e09\u53f0\u4e3b\u673a\uff0c\u4e09\u53f0\u90fd\u4f7f\u7528root\u9a8c\u8bc1\uff0c\u4e09\u53f0\u7684\u5bc6\u7801\u5206\u522b\u662f361way.com\u3001abc123\u300191it.org \u3002<\/p>\n \u6ce8\uff1a\u540e\u9762\u7684\u7528\u6237\u548c\u5bc6\u7801\u9879\u662f\u975e\u5fc5\u987b\u7684\uff0c\u5728\u914d\u7f6ekey\u8ba4\u8bc1\u7684\u60c5\u51b5\u4e0b\uff0c\u4e0d\u4f7f\u7528\u5bc6\u7801\u4e5f\u53ef\u4ee5\u76f4\u63a5\u64cd\u4f5c \u3002\u672a\u4f7f\u7528key\u7684\uff0c\u4e5f\u53ef\u4ee5\u5728ansible\u901a\u8fc7 -k\u53c2\u6570\u5728\u64cd\u4f5c\u524d\u8be2\u95ee\u624b\u52a8\u8f93\u5165\u5bc6\u7801\u3002<\/p>\n \u6267\u884c\u4ee5\u4e0a\u6307\u4ee4\u540e\uff0c\u6709\u7ed3\u679c\u8f93\u51fa\uff0c\u8bc1\u660e\u5b89\u88c5\u6210\u529f\u3002<\/p>\n \u539f\u6587\u6765\u81ea\uff1ahttp:\/\/www.361way.com\/ansible-install\/4371.html<\/a><\/p>\n# yum install http:\/\/mirrors.sohu.com\/fedora-epel\/6\/x86_64\/epel-release-6-8.noarch.rpm\r\n# yum install ansible\r\n<\/pre>\n
$ sudo apt-get install software-properties-common\r\n$ sudo apt-add-repository ppa:ansible\/ansible\r\n$ sudo apt-get update\r\n$ sudo apt-get install ansible\r\n<\/pre>\n
\n\u6e90\u7801\u5b89\u88c5\u9700\u8981python2.6\u4ee5\u4e0a\u7248\u672c\uff0c\u5176\u4f9d\u8d56\u6a21\u5757paramiko\u3001PyYAML\u3001Jinja2\u3001httplib2\u3001simplejson\u3001pycrypto\u6a21\u5757\uff0c\u4ee5\u4e0a\u6a21\u5757\u53ef\u4ee5\u901a\u8fc7pip\u6216easy_install \u8fdb\u884c\u5b89\u88c5\uff0c\u4e0d\u8fc7\u672c\u90e8\u5206\u65e2\u7136\u63d0\u5230\u7684\u662f\u6e90\u7801\u5b89\u88c5\uff0c\u4e3b\u8981\u9488\u5bf9\u7684\u65e0\u6cd5\u4e0a\u5916\u7f51\u7684\u60c5\u51b5\u4e0b\uff0c\u53ef\u4ee5\u901a\u8fc7pypi \u7ad9\u70b9<\/a>\u641c\u7d22\u4ee5\u4e0a\u5305\uff0c\u4e0b\u8f7d\u540e\u901a\u8fc7python setup.py install \u8fdb\u884c\u5b89\u88c5\u3002<\/p>\n# python setup.py install\r\nlibyaml is not found or a compiler error: forcing --without-libyaml\r\n(if libyaml is installed correctly, you may need to\r\nspecify the option --include-dirs or uncomment and\r\nmodify the parameter include_dirs in setup.cfg)\r\nrunning install_lib\r\nrunning install_egg_info\r\nRemoving \/usr\/lib64\/python2.6\/site-packages\/PyYAML-3.11-py2.6.egg-info\r\nWriting \/usr\/lib64\/python2.6\/site-packages\/PyYAML-3.11-py2.6.egg-info\r\n<\/pre>\n
[root@361way.com ansible-1.9.1]# ansible -h\r\nTraceback (most recent call last):\r\nFile \"\/usr\/local\/src\/ansible-devel\/bin\/ansible\", line 36, in \r\nfrom ansible.runner import Runner\r\nFile \"\/usr\/local\/src\/ansible-devel\/lib\/ansible\/runner\/__init__.py\", line 62, in \r\nfrom Crypto.Random import atfork\r\nFile \"\/usr\/lib64\/python2.6\/site-packages\/Crypto\/Random\/__init__.py\", line 29, in \r\nfrom Crypto.Random import _UserFriendlyRNG\r\nFile \"\/usr\/lib64\/python2.6\/site-packages\/Crypto\/Random\/_UserFriendlyRNG.py\", line 38, in \r\nfrom Crypto.Random.Fortuna import FortunaAccumulator\r\nFile \"\/usr\/lib64\/python2.6\/site-packages\/Crypto\/Random\/Fortuna\/FortunaAccumulator.py\", line 39, in \r\nimport FortunaGenerator\r\nFile \"\/usr\/lib64\/python2.6\/site-packages\/Crypto\/Random\/Fortuna\/FortunaGenerator.py\", line 34, in \r\nfrom Crypto.Util.number import ceil_shift, exact_log2, exact_div\r\nFile \"\/usr\/lib64\/python2.6\/site-packages\/Crypto\/Util\/number.py\", line 56, in \r\nif _fastmath is not None and not _fastmath.HAVE_DECL_MPZ_POWM_SEC:\r\nAttributeError: 'module' object has no attribute 'HAVE_DECL_MPZ_POWM_SEC'\r\n<\/pre>\n
>>> import paramiko\r\nTraceback (most recent call last):\r\nFile \"\", line 1, in \r\nFile \"\/usr\/lib\/python2.6\/site-packages\/paramiko\/__init__.py\", line 69, in \r\nfrom transport import randpool, SecurityOptions, Transport\r\nFile \"\/usr\/lib\/python2.6\/site-packages\/paramiko\/transport.py\", line 32, in \r\nfrom paramiko import util\r\nFile \"\/usr\/lib\/python2.6\/site-packages\/paramiko\/util.py\", line 32, in \r\nfrom paramiko.common import *\r\nFile \"\/usr\/lib\/python2.6\/site-packages\/paramiko\/common.py\", line 98, in \r\nfrom rng import StrongLockingRandomPool\r\nFile \"\/usr\/lib\/python2.6\/site-packages\/paramiko\/rng.py\", line 22, in \r\nfrom Crypto.Util.randpool import RandomPool as _RandomPool\r\nFile \"\/usr\/lib64\/python2.6\/site-packages\/Crypto\/Util\/randpool.py\", line 30, in \r\nimport Crypto.Random\r\nFile \"\/usr\/lib64\/python2.6\/site-packages\/Crypto\/Random\/__init__.py\", line 29, in \r\nfrom Crypto.Random import _UserFriendlyRNG\r\nFile \"\/usr\/lib64\/python2.6\/site-packages\/Crypto\/Random\/_UserFriendlyRNG.py\", line 38, in \r\nfrom Crypto.Random.Fortuna import FortunaAccumulator\r\nFile \"\/usr\/lib64\/python2.6\/site-packages\/Crypto\/Random\/Fortuna\/FortunaAccumulator.py\", line 39, in \r\nimport FortunaGenerator\r\nFile \"\/usr\/lib64\/python2.6\/site-packages\/Crypto\/Random\/Fortuna\/FortunaGenerator.py\", line 34, in \r\nfrom Crypto.Util.number import ceil_shift, exact_log2, exact_div\r\nFile \"\/usr\/lib64\/python2.6\/site-packages\/Crypto\/Util\/number.py\", line 56, in \r\nif _fastmath is not None and not _fastmath.HAVE_DECL_MPZ_POWM_SEC:\r\nAttributeError: 'module' object has no attribute 'HAVE_DECL_MPZ_POWM_SEC'\r\n<\/pre>\n
[root@361way.com pycrypto-2.6.1]# python setup.py build\r\nrunning build\r\nrunning build_py\r\nrunning build_ext\r\nrunning build_configure\r\nwarning: GMP or MPIR library not found; Not building Crypto.PublicKey._fastmath.\r\n<\/pre>\n
if _fastmath is not None and not _fastmath.HAVE_DECL_MPZ_POWM_SEC:\r\n_warn(\"Not using mpz_powm_sec. You should rebuild using libgmp >= 5 to avoid timing attack \r\nvulnerability.\", PowmInsecureWarning)\r\n<\/pre>\n
[root@361way.com src]# ansible test -m raw -a 'uptime'\r\n10.212.52.14 | FAILED => to use the 'ssh' connection type with passwords, you must install the sshpass program\r\n10.212.52.16 | FAILED => to use the 'ssh' connection type with passwords, you must install the sshpass program\r\n<\/pre>\n
[root@361way.com ansible-1.9.1]# mkdir -p \/etc\/ansible\r\n[root@361way.com ansible-1.9.1]# cp -rp examples\/* \/etc\/ansible\/\r\n[root@361way.com ansible-1.9.1]# cd \/etc\/ansible\/<\/pre>\n
[root@361way.com ~]# cat \/etc\/ansible\/hosts\r\n[test]\r\n10.212.52.252 ansible_ssh_user=root ansible_ssh_pass=361way.com\r\n10.212.52.14 ansible_ssh_user=root ansible_ssh_pass=abc123\r\n10.212.52.16 ansible_ssh_user=root ansible_ssh_pass=91it.org<\/pre>\n
[root@361way.com ~]# ansible test -a 'uptime'\r\n10.212.52.252 | success | rc=0 >>\r\n18:01pm up 21 days 3:24, 3 users, load average: 0.39, 0.38, 0.35\r\n10.212.52.16 | success | rc=0 >>\r\n18:09pm up 329 days 1:01, 2 users, load average: 0.08, 0.03, 0.05\r\n10.212.52.14 | success | rc=0 >>\r\n18:08pm up 329 days 0:23, 2 users, load average: 0.06, 0.06, 0.05<\/pre>\n
\n