{"id":4597,"date":"2022-03-27T13:42:15","date_gmt":"2022-03-27T05:42:15","guid":{"rendered":"https:\/\/egonlin.com\/?p=4597"},"modified":"2022-03-27T13:42:22","modified_gmt":"2022-03-27T05:42:22","slug":"%e7%ac%ac%e5%85%ad%e7%ab%a0%ef%bc%9a%e5%b0%8f%e7%99%bd%e5%ad%a6ansible%e4%b9%8b%e5%9f%ba%e6%9c%ac%e4%bb%8b%e7%bb%8d","status":"publish","type":"post","link":"https:\/\/egonlin.com\/?p=4597","title":{"rendered":"\u7b2c\u516d\u8282\uff1a\u5c0f\u767d\u5b66Ansible\u4e4b\u57fa\u672c\u4ecb\u7ecd"},"content":{"rendered":"<h4>\u5c0f\u767d\u5b66Ansible\u4e4b\u57fa\u672c\u4ecb\u7ecd<\/h4>\n<h5>\u4e3a\u5565\u8981\u4f7f\u7528 Ansible\uff1f<\/h5>\n<p><strong>\u6211\u4eec\u5148\u770b\u539f\u59cb\u7684\u8fd0\u7ef4\u65f6\u4ee3\uff0c\u4e5f\u5c31\u662f\u624b\u52a8\u8fd0\u7ef4\u7684\u65f6\u5019\uff0c\u6211\u4eec\u5982\u4f55\u53bb\u5b89\u88c5\u4e00\u4e2a\u8f6f\u4ef6<\/strong><\/p>\n<blockquote>\n<p>\u5728\u4ee5\u524d\uff0c\u8fd0\u7ef4\u9700\u8981\u89c4\u8303\uff0c\u9700\u8981\u7edf\u4e00\u914d\u7f6e\u7ba1\u7406\uff0c\u6211\u4eec\u53ea\u80fd\u4f7f\u7528\u6e90\u7801\u5b89\u88c5\u65b9\u5f0f\uff0c\u4fbf\u4e8e\u6211\u4eec\u53bb\u7ba1\u7406\uff0c\u6e90\u7801\u5b89\u88c5\uff0c\u5982\u679c\u662f\u5355\u53f0\u8fd8\u597d\uff0c\u4e00\u4f1a\u4e5f\u5c31\u88c5\u5b8c\u4e86\uff0c\u5982\u679c\u6b64\u65f6\uff0c\u751f\u4ea7\u73af\u5883\u538b\u529b\u9aa4\u589e\uff0c\u9700\u8981\u6269\u5c55100\u53f0web\u8282\u70b9\uff08\u6e90\u7801\u5b89\u88c5100\u53f0nginx\uff09\u6211\u4eec\u8be5\u5982\u4f55\u64cd\u4f5c\uff1f<\/p>\n<\/blockquote>\n<p>\u4e0b\u9762\u662f\u6211\u4eec\u4e4b\u524d\u5b89\u88c5nginx\u7684\u4e00\u4e2a\u811a\u672c\uff1a<\/p>\n<pre><code class=\"language-python\">#1.\u5b89\u88c5\u4f9d\u8d56\nyum install pcre-devel openssl-devel -y\n#2.\u8fdb\u5165\u5b89\u88c5\u76ee\u5f55\ncd \/usr\/local\/tools\n#3.\u521b\u5efanginx\u7528\u6237\nuseradd nginx -M -s \/sbin\/nologin\n#4.\u89e3\u538b\ntar xf nginx-1.6.3.tar.gz\n#5.\u8fdb\u5165nginx\u7a0b\u5e8f\u76ee\u5f55\ncd nginx-1.6.3\n#6.\u751f\u6210\n.\/configure --prefix=\/usr\/local\/nginx-1.6.3 --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module\n#7.\u7f16\u8bd1\nmake\n#8.\u5b89\u88c5\nmake install\n#9.\u505a\u8f6f\u94fe\u63a5\nln -s \/usr\/local\/nginx-1.6.3\/ \/usr\/local\/nginx<\/code><\/pre>\n<p>\u5f88\u660e\u663e\uff0c\u5982\u679c\u6211\u4eec\u88c5\u4e00\u53f0\u4e5f\u8fd8\u597d\uff0c\u90a3\u5982\u679c\u88c5100\u53f0\u670d\u52a1\u5668\uff0c\u90a3\u6211\u4eec\u662f\u4e0d\u662f\u8981\u91cd\u590d\u6267\u884c100\u6b21<br \/>\n\u4ee5\u4e0a\u6b65\u9aa4\u8fd8\u53ea\u662f\u5b89\u88c5\uff0c\u90a3\u8fd8\u8981\u90e8\u7f72\u4ee3\u7801\u5462\uff1f\u4fee\u6539\u914d\u7f6e\u6587\u4ef6\uff1f\u4f18\u5316\uff1f\u542f\u52a8\uff1f\u90a3\u8fd8\u5de5\u4f5c\u4e2a\u6bdb\u7ebf\u554a\uff0c\u4e00\u5929\u5565\u4e5f\u4e0d\u7528\u5e72\u4e86\uff0c\u5c31\u88c5nginx\u5427<\/p>\n<p>\u6b63\u56e0\u4e3a\u6709\u4e86\u4e0a\u9762\u975e\u5e38\u9ebb\u70e6\u7684\u64cd\u4f5c\uff0c\u56e0\u6b64\u6211\u4eec\u5728\u60f3\uff0c\u5982\u679c\u80fd\u6709\u4e00\u4e2a\u6279\u91cf\u5316\u64cd\u4f5c\u4e0a\u8ff0\u811a\u672c\u6216\u8005\u6279\u91cf\u5316\u6267\u884c\u547d\u4ee4\u7684\u8f6f\u4ef6\u5c31\u975e\u5e38\u597d\u4e86<\/p>\n<p>\u56e0\u6b64\uff0c\u5c31\u51fa\u73b0\u4e86\u4ee5Ansible\u4e3a\u4ee3\u8868\u7684\u4e00\u7cfb\u5217\u81ea\u52a8\u5316\u8fd0\u7ef4\u5de5\u5177\uff0c\u4ece\u6b64\u6211\u4eec\u7684\u8fd0\u7ef4\u5de5\u4f5c\u5c31\u4f1a\u53d8\u5f97\u975e\u5e38\u7684\u7b80\u5355\u548c\u65b9\u4fbf<\/p>\n<h5>\u4ec0\u4e48\u662fAnsible\uff1f<\/h5>\n<blockquote>\n<p>Ansible\u662f\u4e00\u4e2a\u81ea\u52a8\u5316\u7edf\u4e00\u914d\u7f6e\u7ba1\u7406\u5de5\u5177\uff0c\u81ea\u52a8\u5316\u4e3b\u8981\u4f53\u73b0\u5728Ansible\u96c6\u6210\u4e86\u4e30\u5bcc\u6a21\u5757\u4ee5\u53ca\u529f\u80fd\u7ec4\u4ef6\uff0c\u53ef\u4ee5\u901a\u8fc7\u4e00\u4e2a\u547d\u4ee4\u5b8c\u6210\u4e00\u7cfb\u5217\u7684\u64cd\u4f5c\uff0c\u8fdb\u800c\u80fd\u51cf\u5c11\u91cd\u590d\u6027\u7684\u5de5\u4f5c\u548c\u7ef4\u62a4\u6210\u672c\uff0c\u53ef\u4ee5\u63d0\u9ad8\u5de5\u4f5c\u6548\u7387<\/p>\n<\/blockquote>\n<h5>Ansible \u7684\u7279\u70b9<\/h5>\n<p>1.\u8fdc\u7a0b\u6267\u884c<\/p>\n<blockquote>\n<p>\u6279\u91cf\u6267\u884c\u8fdc\u7a0b\u547d\u4ee4\uff0c\u53ef\u4ee5\u5bf9\u591a\u53f0\u4e3b\u673a\u8fdb\u884c\u8fdc\u7a0b\u64cd\u4f5c<\/p>\n<\/blockquote>\n<p>2.\u914d\u7f6e\u7ba1\u7406<\/p>\n<blockquote>\n<p>\u6279\u91cf\u914d\u7f6e\u8f6f\u4ef6\u670d\u52a1\uff0c\u53ef\u4ee5\u8fdb\u884c\u81ea\u52a8\u5316\u65b9\u5f0f\u914d\u7f6e\uff0c\u670d\u52a1\u7684\u7edf\u4e00\u914d\u7f6e\u7ba1\u7406\uff0c\u548c\u542f\u505c<\/p>\n<\/blockquote>\n<p>3.\u4e8b\u4ef6\u9a71\u52a8<\/p>\n<blockquote>\n<p>\u901a\u8fc7Ansible\u7684\u6a21\u5757\uff0c\u5bf9\u670d\u52a1\u8fdb\u884c\u4e0d\u540c\u7684\u4e8b\u4ef6\u9a71\u52a8<br \/>\n\u6bd4\u5982\uff1a<br \/>\n1\uff09\u4fee\u6539\u914d\u7f6e\u540e\u91cd\u542f<br \/>\n2\uff09\u53ea\u4fee\u6539\u914d\u7f6e\u6587\u4ef6\uff0c\u4e0d\u91cd\u542f<br \/>\n3\uff09\u4fee\u6539\u914d\u7f6e\u6587\u4ef6\u540e\uff0c\u91cd\u65b0\u52a0\u8f7d<br \/>\n4\uff09\u8fdc\u7a0b\u542f\u505c\u670d\u52a1\u7ba1\u7406<\/p>\n<\/blockquote>\n<p>4.\u7ba1\u7406\u516c\u6709\u4e91<\/p>\n<blockquote>\n<p>\u901a\u8fc7API\u63a5\u53e3\u7684\u65b9\u5f0f\u7ba1\u7406\u516c\u6709\u4e91\uff0c\u4e0d\u8fc7\u8fd9\u65b9\u9762\u505a\u7684\u4e0d\u5982saltstack.<br \/>\nsaltstack\u672c\u8eab\u53ef\u4ee5\u901a\u8fc7saltcloud\u7ba1\u7406\u5404\u5927\u4e91\u5382\u5546\u7684\u4e91\u5e73\u53f0\u3002<\/p>\n<\/blockquote>\n<p>5.\u4e8c\u6b21\u5f00\u53d1<\/p>\n<blockquote>\n<p>\u56e0\u4e3a\u8bed\u6cd5\u662fPython\uff0c\u6240\u4ee5\u4fbf\u4e8e\u8fd0\u7ef4\u8fdb\u884c\u4e8c\u6b21\u5f00\u53d1\u3002<\/p>\n<\/blockquote>\n<p>6.\u4efb\u52a1\u7f16\u6392<\/p>\n<blockquote>\n<p>\u53ef\u4ee5\u901a\u8fc7playbook\u7684\u65b9\u5f0f\u6765\u7edf\u4e00\u7ba1\u7406\u670d\u52a1\uff0c\u5e76\u4e14\u53ef\u4ee5\u4f7f\u7528\u4e00\u6761\u547d\u4ee4\uff0c\u5b9e\u73b0\u4e00\u5957\u67b6\u6784\u7684\u90e8\u7f72<\/p>\n<\/blockquote>\n<p>7.\u8de8\u5e73\u53f0\uff0c\u8de8\u7cfb\u7edf<\/p>\n<blockquote>\n<p>\u51e0\u4e4e\u4e0d\u53d7\u5230\u5e73\u53f0\u548c\u7cfb\u7edf\u7684\u9650\u5236\uff0c\u6bd4\u5982\u5b89\u88c5apache\u548c\u542f\u52a8\u670d\u52a1<\/p>\n<\/blockquote>\n<h5>Ansible\u67b6\u6784\u56fe<\/h5>\n<p><a href=\"https:\/\/imgchr.com\/i\/MKQba4\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/s2.ax1x.com\/2019\/11\/10\/MKQba4.md.jpg'><img class=\"lazyload lazyload-style-2\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  data-original=\"https:\/\/s2.ax1x.com\/2019\/11\/10\/MKQba4.md.jpg\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"MKQba4.md.jpg\" \/><\/div><\/a><\/p>\n<p>1\u3001\u8fde\u63a5\u63d2\u4ef6connection plugins\u7528\u4e8e\u8fde\u63a5\u4e3b\u673a \u7528\u6765\u8fde\u63a5\u88ab\u7ba1\u7406\u7aef<br \/>\n2\u3001\u6838\u5fc3\u6a21\u5757core modules\u8fde\u63a5\u4e3b\u673a\u5b9e\u73b0\u64cd\u4f5c\uff0c \u5b83\u4f9d\u8d56\u4e8e\u5177\u4f53\u7684\u6a21\u5757\u6765\u505a\u5177\u4f53\u7684\u4e8b\u60c5<br \/>\n3\u3001\u81ea\u5b9a\u4e49\u6a21\u5757custom modules\u6839\u636e\u81ea\u5df1\u7684\u9700\u6c42\u7f16\u5199\u5177\u4f53\u7684\u6a21\u5757<br \/>\n4\u3001\u63d2\u4ef6plugins\u5b8c\u6210\u6a21\u5757\u529f\u80fd\u7684\u8865\u5145<br \/>\n5\u3001\u5267\u672cplaybookansible\u7684\u914d\u7f6e\u6587\u4ef6,\u5c06\u591a\u4e2a\u4efb\u52a1\u5b9a\u4e49\u5728\u5267\u672c\u4e2d\uff0c\u7531ansible\u81ea\u52a8\u6267\u884c<br \/>\n6\u3001\u4e3b\u673a\u6e05\u5355inventor\u5b9a\u4e49ansible\u9700\u8981\u64cd\u4f5c\u4e3b\u673a\u7684\u8303\u56f4<br \/>\n\u6700\u91cd\u8981\u7684\u4e00\u70b9\u662f ansible\u662f\u6a21\u5757\u5316\u7684 \u5b83\u6240\u6709\u7684\u64cd\u4f5c\u90fd\u4f9d\u8d56\u4e8e\u6a21\u5757<\/p>\n<h5>Ansible\u7684\u6267\u884c\u6d41\u7a0b<\/h5>\n<p>1.Ansible\u8bfb\u53d6playbook\u5267\u672c\uff0c\u5267\u672c\u4e2d\u4f1a\u8bb0\u5f55\u5bf9\u54ea\u4e9b\u4e3b\u673a\u6267\u884c\u54ea\u4e9b\u4efb\u52a1<br \/>\n2.\u9996\u5148Ansible\u901a\u8fc7\u4e3b\u673a\u6e05\u5355\u627e\u5230\u8981\u6267\u884c\u7684\u4e3b\u673a\uff0c\u7136\u540e\u8c03\u7528\u5177\u4f53\u7684\u6a21\u5757<br \/>\n3.\u5176\u6b21Ansible\u4f1a\u901a\u8fc7\u8fde\u63a5\u63d2\u4ef6\u8fde\u63a5\u5bf9\u5e94\u7684\u4e3b\u673a\u5e76\u63a8\u9001\u5bf9\u5e94\u7684\u4efb\u52a1\u5217\u8868<br \/>\n4.\u6700\u540e\u88ab\u7ba1\u7406\u7684\u4e3b\u673a\u4f1a\u5c06Ansible\u53d1\u9001\u8fc7\u6765\u7684\u4efb\u52a1\u89e3\u6790\u4e3a\u672c\u5730Shell\u547d\u4ee4\u6267\u884c<\/p>\n<h5>Ansible\u7684\u5b89\u88c5\u548c\u914d\u7f6e<\/h5>\n<p><strong>\u73af\u5883\u51c6\u5907<\/strong><\/p>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: left;\">\u4e3b\u673a\u540d<\/th>\n<th style=\"text-align: right;\">IP<\/th>\n<th style=\"text-align: center;\">\u89d2\u8272<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: left;\">m01<\/td>\n<td style=\"text-align: right;\">10.0.0.61<\/td>\n<td style=\"text-align: center;\">Ansible\u63a7\u5236\u7aef<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">web01<\/td>\n<td style=\"text-align: right;\">10.0.0.7<\/td>\n<td style=\"text-align: center;\">Ansible\u88ab\u63a7\u7aef<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">web02<\/td>\n<td style=\"text-align: right;\">10.0.0.8<\/td>\n<td style=\"text-align: center;\">Ansible\u88ab\u63a7\u7aef<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>\u5b89\u88c5Ansible<\/strong><\/p>\n<pre><code class=\"language-python\">#1.\u5b89\u88c5epel\u6e90\n[root@m01 ~]# wget -O \/etc\/yum.repos.d\/epel.repo http:\/\/mirrors.aliyun.com\/repo\/epel-7.repo\n\n#2.\u5b89\u88c5Ansible\n[root@m01 ~]# yum install -y ansible\n\n# ansible &lt;host-pattern&gt; [options]\n--version   #ansible\u7248\u672c\u4fe1\u606f\n-v          #\u663e\u793a\u8be6\u7ec6\u4fe1\u606f\n-i          #\u4e3b\u673a\u6e05\u5355\u6587\u4ef6\u8def\u5f84\uff0c\u9ed8\u8ba4\u662f\u5728\/etc\/ansible\/hosts\n-m          #\u4f7f\u7528\u7684\u6a21\u5757\u540d\u79f0\uff0c\u9ed8\u8ba4\u4f7f\u7528command\u6a21\u5757\n-a          #\u4f7f\u7528\u7684\u6a21\u5757\u53c2\u6570\uff0c\u6a21\u5757\u7684\u5177\u4f53\u52a8\u4f5c\n-k          #\u63d0\u793a\u8f93\u5165ssh\u5bc6\u7801\uff0c\u800c\u4e0d\u4f7f\u7528\u57fa\u4e8essh\u7684\u5bc6\u94a5\u8ba4\u8bc1\n-C          #\u6a21\u62df\u6267\u884c\u6d4b\u8bd5\uff0c\u4f46\u4e0d\u4f1a\u771f\u7684\u6267\u884c\n-T          #\u6267\u884c\u547d\u4ee4\u7684\u8d85\u65f6\n\n#3.\u67e5\u770bAnsible\u7248\u672c\u53ca\u6a21\u5757\u8def\u5f84\n[root@m01 ~]# ansible --version\nansible 2.7.1\n  config file = \/etc\/ansible\/ansible.cfg\n  configured module search path = [u&#039;\/root\/.ansible\/plugins\/modules&#039;, u&#039;\/usr\/share\/ansible\/plugins\/modules&#039;]\n  ansible python module location = \/usr\/lib\/python2.7\/site-packages\/ansible\n  executable location = \/usr\/bin\/ansible\n  python version = 2.7.5 (default, Apr 11 2018, 07:36:10) [GCC 4.8.5 20150623 (Red Hat 4.8.5-28)]<\/code><\/pre>\n<p><strong>Ansible\u914d\u7f6e\u6587\u4ef6\u4ecb\u7ecd<\/strong><\/p>\n<pre><code class=\"language-python\">[root@m01 ~]# cat \/etc\/ansible\/ansible.cfg \n#inventory      = \/etc\/ansible\/hosts      #\u4e3b\u673a\u5217\u8868\u914d\u7f6e\u6587\u4ef6\n#library        = \/usr\/share\/my_modules\/  #\u5e93\u6587\u4ef6\u5b58\u653e\u76ee\u5f55\n#remote_tmp     = ~\/.ansible\/tmp          #\u4e34\u65f6py\u6587\u4ef6\u5b58\u653e\u5728\u8fdc\u7a0b\u4e3b\u673a\u76ee\u5f55\n#local_tmp      = ~\/.ansible\/tmp          #\u672c\u673a\u7684\u4e34\u65f6\u6267\u884c\u76ee\u5f55\n#forks          = 5                       #\u9ed8\u8ba4\u5e76\u53d1\u6570\n#sudo_user      = root                    #\u9ed8\u8ba4sudo\u7528\u6237\n#ask_sudo_pass = True                     #\u6bcf\u6b21\u6267\u884c\u662f\u5426\u8be2\u95eesudo\u7684ssh\u5bc6\u7801\n#ask_pass      = True                     #\u6bcf\u6b21\u6267\u884c\u662f\u5426\u8be2\u95eessh\u5bc6\u7801\n#remote_port    = 22                      #\u8fdc\u7a0b\u4e3b\u673a\u7aef\u53e3\nhost_key_checking = False                 #\u8df3\u8fc7\u68c0\u67e5\u4e3b\u673a\u6307\u7eb9\nlog_path = \/var\/log\/ansible.log           #ansible\u65e5\u5fd7\n\n#\u666e\u901a\u7528\u6237\u63d0\u6743\u64cd\u4f5c\n[privilege_escalation]\n#become=True\n#become_method=sudo\n#become_user=root\n#become_ask_pass=False <\/code><\/pre>\n<h5>Ansible Inventory \u4ecb\u7ecd\u548c\u521d\u8bc6<\/h5>\n<p>\/etc\/ansible\/hosts\u662fansible\u9ed8\u8ba4\u4e3b\u673a\u8d44\u4ea7\u6e05\u5355\u6587\u4ef6\uff0c\u7528\u4e8e\u5b9a\u4e49\u88ab\u7ba1\u7406\u4e3b\u673a\u7684\u8ba4\u8bc1\u4fe1\u606f\uff0c \u4f8b\u5982ssh\u767b\u5f55\u7528\u6237\u540d\u3001\u5bc6\u7801\u4ee5\u53cakey\u76f8\u5173\u4fe1\u606f\u3002Inventory\u6587\u4ef6\u4e2d\u586b\u5199\u9700\u8981\u88ab\u7ba1\u7406\u7684\u4e3b\u673a\u4e0e\u4e3b\u673a\u7ec4\u4fe1\u606f\u3002\u8fd8\u53ef\u4ee5\u81ea\u5b9a\u4e49Inventory\u4e3b\u673a\u6e05\u5355\u7684\u4f4d\u7f6e\uff0c\u4f7f\u7528-i\u6307\u5b9a\u6587\u4ef6\u4f4d\u7f6e\u5373\u53ef<\/p>\n<p><strong>\u573a\u666f\u4e00<\/strong><\/p>\n<pre><code class=\"language-python\">[root@m01 ~]# cat \/etc\/ansible\/hosts\n\n#\u65b9\u5f0f\u4e00\u3001IP+\u7aef\u53e3+\u7528\u6237+\u5bc6\u7801\n[webs]\n10.0.0.7 ansible_ssh_port=22 ansible_ssh_user=root ansible_ssh_pass=&#039;1&#039;\n10.0.0.8 ansible_ssh_port=22 ansible_ssh_user=root ansible_ssh_pass=&#039;1&#039;\n\n#\u65b9\u5f0f\u4e8c\u3001\u4e3b\u673a\u540d+\u5bc6\u7801\n[webs]\nweb0[1:2] ansible_ssh_pass=&#039;123456&#039;\n\n#\u65b9\u5f0f\u4e09\u3001\u4e3b\u673a+\u7aef\u53e3+\u5bc6\u7801\n[webs]\nweb0[1:2]\n[webs:vars]\nansible_ssh_pass=&#039;123456&#039;\n\n[root@m01 ~]# ansible webs -m ping -i .\/hosts\n10.0.0.8 | SUCCESS =&gt; {\n    &quot;ansible_facts&quot;: {\n        &quot;discovered_interpreter_python&quot;: &quot;\/usr\/bin\/python&quot;\n    },\n    &quot;changed&quot;: false,\n    &quot;ping&quot;: &quot;pong&quot;\n}\n10.0.0.7 | SUCCESS =&gt; {\n    &quot;ansible_facts&quot;: {\n        &quot;discovered_interpreter_python&quot;: &quot;\/usr\/bin\/python&quot;\n    },\n    &quot;changed&quot;: false,\n    &quot;ping&quot;: &quot;pong&quot;\n}<\/code><\/pre>\n<p><strong>\u573a\u666f\u4e8c\uff0c\u57fa\u4e8e\u516c\u94a5\u548c\u79c1\u94a5\u7684\u8fde\u63a5<\/strong><\/p>\n<pre><code class=\"language-python\">#\u521b\u5efa\u79d8\u94a5\u5bf9\n[root@m01 ~]# ssh-keygen\n\n#\u63a8\u9001\u516c\u94a5\n[root@m01 ~]# ssh-copy-id -i ~\/.ssh\/id_rsa.pub root@172.16.1.7\n[root@m01 ~]# ssh-copy-id -i ~\/.ssh\/id_rsa.pub root@172.16.1.8<\/code><\/pre>\n<pre><code class=\"language-python\">[root@m01 ~]# cat .\/hosts\n#\u65b9\u5f0f\u4e00\u3001\u4e3b\u673a+\u7aef\u53e3+\u5bc6\u94a5\n[webs]\n10.0.0.7:22\n10.0.0.8\n\n[root@m01 ~]# ansible webs -m ping -i .\/hosts\n10.0.0.8 | SUCCESS =&gt; {\n    &quot;ansible_facts&quot;: {\n        &quot;discovered_interpreter_python&quot;: &quot;\/usr\/bin\/python&quot;\n    },\n    &quot;changed&quot;: false,\n    &quot;ping&quot;: &quot;pong&quot;\n}\n10.0.0.7 | SUCCESS =&gt; {\n    &quot;ansible_facts&quot;: {\n        &quot;discovered_interpreter_python&quot;: &quot;\/usr\/bin\/python&quot;\n    },\n    &quot;changed&quot;: false,\n    &quot;ping&quot;: &quot;pong&quot;\n}\n\n#\u65b9\u5f0f\u4e8c\u3001\u522b\u540d+\u4e3b\u673a+\u7aef\u53e3+\u5bc6\u94a5\n[root@m01 ~]# cat .\/hosts\n[webs]\nweb01 ansible_ssh_host=10.0.0.7 ansible_ssh_port=22\nweb02 ansible_ssh_host=10.0.0.8\n\n[root@m01 ~]# ansible webs -m ping -i .\/hosts\nweb02 | SUCCESS =&gt; {\n    &quot;ansible_facts&quot;: {\n        &quot;discovered_interpreter_python&quot;: &quot;\/usr\/bin\/python&quot;\n    },\n    &quot;changed&quot;: false,\n    &quot;ping&quot;: &quot;pong&quot;\n}\nweb01 | SUCCESS =&gt; {\n    &quot;ansible_facts&quot;: {\n        &quot;discovered_interpreter_python&quot;: &quot;\/usr\/bin\/python&quot;\n    },\n    &quot;changed&quot;: false,\n    &quot;ping&quot;: &quot;pong&quot;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5c0f\u767d\u5b66Ansible\u4e4b\u57fa\u672c\u4ecb\u7ecd \u4e3a\u5565\u8981\u4f7f\u7528 Ansible\uff1f \u6211\u4eec\u5148\u770b\u539f\u59cb\u7684\u8fd0\u7ef4\u65f6\u4ee3\uff0c\u4e5f\u5c31\u662f\u624b\u52a8\u8fd0\u7ef4\u7684\u65f6\u5019\uff0c\u6211 [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[352,351],"tags":[],"_links":{"self":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts\/4597"}],"collection":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4597"}],"version-history":[{"count":0,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts\/4597\/revisions"}],"wp:attachment":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4597"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4597"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4597"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}