{"id":291367,"date":"2024-05-03T23:08:10","date_gmt":"2024-05-03T15:08:10","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=291367"},"modified":"2024-08-11T17:29:30","modified_gmt":"2024-08-11T09:29:30","slug":"learing-linux-16","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/learing-linux-16.html","title":{"rendered":"\u7b2c16\u7ae0 \u4f7f\u7528Ansible\u670d\u52a1\u5b9e\u73b0\u81ea\u52a8\u5316\u8fd0\u7ef4"},"content":{"rendered":"
\u7ae0\u8282\u7b80\u8ff0\uff1a<\/strong><\/p>\n Ansible\u662f\u8fd1\u5e74\u6765\u5907\u53d7\u77a9\u76ee\u7684\u4e00\u6b3e\u5f00\u6e90\u8fd0\u7ef4\u81ea\u52a8\u5316\u5de5\u5177\uff0c\u582a\u79f0\u8fd0\u7ef4\u9886\u57df\u7684\u7fd8\u695a\u3002\u5b83\u6781\u5927\u5730\u63d0\u5347\u4e86\u8fd0\u7ef4\u4eba\u5458\u7684\u5de5\u4f5c\u6548\u7387\uff0c\u540c\u65f6\u51cf\u5c11\u4e86\u4eba\u4e3a\u9519\u8bef\u7684\u53d1\u751f\uff0c\u53ef\u8c13\u4e8b\u534a\u529f\u500d\u3002Ansible\u5305\u542b\u6570\u5343\u4e2a\u529f\u80fd\u4e30\u5bcc\u4e14\u5b9e\u7528\u7684\u6a21\u5757\uff0c\u5e76\u9644\u6709\u8be6\u5c3d\u7684\u5e2e\u52a9\u4fe1\u606f\uff0c\u5373\u4f7f\u662f\u521d\u5b66\u8005\u4e5f\u80fd\u8fc5\u901f\u4e0a\u624b\uff0c\u5982\u9c7c\u5f97\u6c34\u3002<\/p>\n \u672c\u7ae0\u9996\u5148\u4ecb\u7ecd\u4e86Ansible\u7684\u8d77\u6e90\u3001\u5173\u952e\u672f\u8bed\u4ee5\u53ca\u4e3b\u673a\u6e05\u5355\u7684\u914d\u7f6e\uff0c\u5e26\u9886\u5927\u5bb6\u6df1\u5165\u5b66\u4e60ping\u3001yum\u3001firewalld\u3001service\u3001template\u3001setup\u3001lvol\u3001lvg\u3001copy\u3001file\u3001debug\u7b49\u5341\u591a\u4e2a\u5e38\u7528\u7684Ansible\u6a21\u5757\uff0c\u4ee5\u6ee1\u8db3\u65e5\u5e38\u8fd0\u7ef4\u7684\u9700\u6c42\u3002\u63a5\u7740\uff0c\u672c\u7ae0\u901a\u8fc7\u52a8\u624b\u5b9e\u64cd\uff0c\u8be6\u89e3\u5982\u4f55\u4ece\u7cfb\u7edf\u4e2d\u52a0\u8f7d\u89d2\u8272\u3001\u4ece\u5916\u90e8\u83b7\u53d6\u89d2\u8272\u4ee5\u53ca\u81ea\u884c\u521b\u5efa\u89d2\u8272\u7684\u65b9\u6cd5\uff0c\u65e8\u5728\u8ba9\u8bfb\u8005\u5728\u751f\u4ea7\u73af\u5883\u4e2d\u80fd\u591f\u5f97\u5fc3\u5e94\u624b\u5730\u7ba1\u7406\u548c\u63a7\u5236\u4efb\u52a1\u6d41\u7a0b\u3002\u6b64\u5916\uff0c\u672c\u7ae0\u8fd8\u901a\u8fc7\u7cbe\u5fc3\u7f16\u5199\u7684playbook\u6587\u4ef6\uff0c\u6f14\u793a\u4e86\u5982\u4f55\u521b\u5efa\u903b\u8f91\u5377\u8bbe\u5907\u3001\u4f9d\u636e\u4e3b\u673a\u6539\u5199\u6587\u4ef6\u4ee5\u53ca\u7ba1\u7406\u6587\u4ef6\u5c5e\u6027\u7684\u65b9\u6cd5\u3002\u6700\u540e\uff0c\u7ae0\u8282\u4ee5\u4f7f\u7528Ansible\u7684vault\u529f\u80fd\u5bf9\u53d8\u91cf\u548cplaybook\u6587\u4ef6\u8fdb\u884c\u52a0\u5bc6\u7684\u5185\u5bb9\u6536\u5c3e\u3002<\/p>\n \u672c\u7ae0\u5168\u9762\u6db5\u76d6\u4e86Ansible\u7684\u4f7f\u7528\u7ec6\u8282\uff0c\u5185\u5bb9\u73af\u73af\u76f8\u6263\uff0c\u76f8\u4fe1\u8bfb\u8005\u5728\u5b66\u5b8c\u672c\u7ae0\u5185\u5bb9\u4e4b\u540e\u4f1a\u6709\u9163\u7545\u6dcb\u6f13\u4e4b\u611f\u3002<\/p>\n Ansible\u662f\u5f53\u524d\u8fd0\u7ef4\u81ea\u52a8\u5316\u5de5\u5177\u4e2d\u7b80\u4fbf\u6613\u7528\u7684\u5178\u8303\uff0c\u582a\u79f0\u8fd0\u7ef4\u4eba\u5458\u7684\u5f97\u529b\u52a9\u624b\u3002\u5b83\u80fd\u591f\u9ad8\u6548\u5730\u7ba1\u7406\u5404\u79cd\u8d44\u6e90\uff0c\u5e76\u901a\u8fc7\u81ea\u52a8\u90e8\u7f72\u5e94\u7528\u7a0b\u5e8f\uff0c\u5b9e\u73b0IT\u57fa\u7840\u67b6\u6784\u7684\u5168\u9762\u81ea\u52a8\u5316\u3002\u501f\u52a9Ansible\uff0c\u6211\u4eec\u53ef\u4ee5\u8f7b\u677e\u5b8c\u6210\u670d\u52a1\u5668\u7684\u521d\u59cb\u5316\u914d\u7f6e\u3001\u5b89\u5168\u57fa\u7ebf\u914d\u7f6e\uff0c\u4ee5\u53ca\u7cfb\u7edf\u66f4\u65b0\u548c\u8865\u4e01\u7ba1\u7406\u7b49\u64cd\u4f5c\u3002\u4e0eChef\u3001Puppet\u3001SaltStack\u7b49\u91c7\u7528C\/S\uff08\u5ba2\u6237\u7aef\/\u670d\u52a1\u5668\uff09\u67b6\u6784\u7684\u81ea\u52a8\u5316\u5de5\u5177\u76f8\u6bd4\uff0c\u5c3d\u7ba1Ansible\u5728\u6027\u80fd\u4e0a\u5e76\u975e\u6700\u4f73\uff0c\u4f46\u7531\u4e8e\u5176\u57fa\u4e8eSSH\u8fdc\u7a0b\u4f1a\u8bdd\u534f\u8bae\uff0c\u4e0d\u9700\u8981\u5b89\u88c5\u5ba2\u6237\u7aef\u7a0b\u5e8f\uff0c\u53ea\u9700\u638c\u63e1\u53d7\u63a7\u4e3b\u673a\u7684\u8d26\u53f7\u5bc6\u7801\uff0c\u4fbf\u53ef\u76f4\u63a5\u901a\u8fc7SSH\u534f\u8bae\u8fdb\u884c\u8fdc\u7a0b\u63a7\u5236\u3002\u56e0\u6b64\uff0cAnsible\u5728\u4f7f\u7528\u4fbf\u6377\u6027\u4e0a\u5360\u636e\u4e86\u663e\u8457\u4f18\u52bf\uff0c\u79f0\u5f97\u4e0a\u662f\u8fd0\u7ef4\u9886\u57df\u7684\u201c\u5229\u5668\u201d\u3002<\/p>\n 2012\u5e742\u6708\uff0c\u7a0b\u5e8f\u5458Michael DeHaan\u53d1\u5e03\u4e86Ansible\u7684\u7b2c\u4e00\u4e2a\u7248\u672c\u3002Michael DeHaan\u5728\u914d\u7f6e\u7ba1\u7406\u548c\u67b6\u6784\u8bbe\u8ba1\u9886\u57df\u62e5\u6709\u4e30\u5bcc\u7684\u7ecf\u9a8c\uff0c\u4ed6\u5728\u7ea2\u5e3d\u516c\u53f8\u4efb\u804c\u671f\u95f4\uff0c\u66fe\u7814\u53d1\u4e86Cobbler\u81ea\u52a8\u5316\u7cfb\u7edf\u5b89\u88c5\u5de5\u5177\u3002\u7136\u800c\uff0c\u9762\u5bf9\u73b0\u6709\u81ea\u52a8\u5316\u5de5\u5177\u7684\u590d\u6742\u6027\u548c\u5c40\u9650\u6027\uff0c\u4ed6\u6df1\u611f\u4e0d\u6ee1\uff0c\u9042\u51b3\u5fc3\u6253\u9020\u4e00\u6b3e\u96c6\u4f17\u5bb6\u6240\u957f\u7684\u81ea\u52a8\u5316\u5de5\u5177\u3002Ansible\u56e0\u6b64\u5e94\u8fd0\u800c\u751f\u3002\u51ed\u501f\u5176\u5353\u8d8a\u7684\u6613\u7528\u6027\u548c\u5f3a\u5927\u529f\u80fd\uff0cAnsible\u8fc5\u901f\u83b7\u5f97\u4e86\u8fd0\u7ef4\u754c\u7684\u5e7f\u6cdb\u8ba4\u53ef\uff0c\u5176\u5728GitHub\u4e0a\u7684star\u548cfork\u6570\u91cf\u8fdc\u8d85SaltStack\uff0c\u8db3\u4ee5\u89c1\u5176\u53d7\u6b22\u8fce\u7a0b\u5ea6\u30022015\u5e74\uff0cAnsible\u6b63\u5f0f\u88ab\u7ea2\u5e3d\u516c\u53f8\u6536\u8d2d\uff0c\u4e3a\u5176\u672a\u6765\u53d1\u5c55\u589e\u6dfb\u4e86\u65e0\u9650\u6f5c\u529b\u3002<\/p>\n <\/p>\n \u4f7f\u7528\u81ea\u52a8\u5316\u8fd0\u7ef4\u5de5\u5177\uff0c\u80fd\u591f\u8089\u773c\u53ef\u89c1\u5730\u63d0\u9ad8\u8fd0\u7ef4\u4eba\u5458\u7684\u5de5\u4f5c\u6548\u7387\uff0c\u5e76\u51cf\u5c11\u4eba\u4e3a\u9519\u8bef\u3002Ansible\u670d\u52a1\u672c\u8eab\u5e76\u6ca1\u6709\u6279\u91cf\u90e8\u7f72\u7684\u529f\u80fd\uff0c\u5b83\u4ec5\u4ec5\u662f\u4e00\u4e2a\u6846\u67b6\uff0c\u771f\u6b63\u5177\u6709\u6279\u91cf\u90e8\u7f72\u80fd\u529b\u7684\u662f\u5176\u6240\u8fd0\u884c\u7684\u6a21\u5757\u3002Ansible\u5185\u7f6e\u4e86\u4e0a\u5343\u4e2a\u6a21\u5757\uff0c\u4f1a\u5728\u5b89\u88c5Ansible\u65f6\u4e00\u5e76\u5b89\u88c5\uff0c\u901a\u8fc7\u8c03\u7528\u6307\u5b9a\u7684\u6a21\u5757\uff0c\u5c31\u80fd\u5b9e\u73b0\u7279\u5b9a\u7684\u529f\u80fd\u3002Ansible\u5185\u7f6e\u7684\u6a21\u5757\u975e\u5e38\u4e30\u5bcc\uff0c\u51e0\u4e4e\u6ee1\u8db3\u4e86\u4e00\u5207\u9700\u6c42\uff0c\u4f7f\u7528\u8d77\u6765\u4e5f\u975e\u5e38\u7b80\u5355\uff0c\u4e00\u6761\u547d\u4ee4\u751a\u81f3\u5f71\u54cd\u4e0a\u5343\u53f0\u4e3b\u673a\u3002\u5982\u679c\u9700\u8981\u66f4\u9ad8\u7ea7\u7684\u529f\u80fd\uff0c\u4e5f\u53ef\u4ee5\u8fd0\u7528Python\u8bed\u8a00\u5bf9Ansible\u8fdb\u884c\u4e8c\u6b21\u5f00\u53d1\u3002<\/p>\n \u5982\u4eca\uff0cAnsible\u5df2\u88abAmazon\u3001Google\u3001Microsoft\u3001Cisco\u3001HP\u3001VMware\u3001Twitter\u7b49\u5927\u79d1\u6280\u516c\u53f8\u63a5\u7eb3\u5e76\u6295\u5165\u4f7f\u7528\uff0c\u5e76\u5728\u5b9e\u8df5\u4e2d\u5c55\u73b0\u51fa\u975e\u51e1\u7684\u6027\u80fd\u548c\u7075\u6d3b\u6027\u3002\u7ea2\u5e3d\u516c\u53f8\u66f4\u662f\u5bf9\u81ea\u5bb6\u4ea7\u54c1\u8fdb\u884c\u4e86\u4e0d\u9057\u4f59\u529b\u7684\u652f\u6301\u3002\u4ece2020\u5e748\u67081\u65e5\u8d77\uff0cRHCE\u8003\u8bd5\u7684\u5185\u5bb9\u7531\u914d\u7f6e\u591a\u6b3e\u670d\u52a1\u8f6c\u53d8\u6210Ansible\u4e13\u9879\u8003\u9898\u5185\u5bb9\u3002\u73b0\u5728\uff0c\u8981\u60f3\u987a\u5229\u62ff\u5230RHCE\u8ba4\u8bc1\uff0c\u771f\u7684\u6709\u5fc5\u8981\u597d\u597d\u5b66\u4e60\u4e00\u4e0b\u672c\u7ae0\u4e86\u3002<\/p>\n \u5728\u6b63\u5f0f\u4ecb\u7ecdAnsible\u4e4b\u524d\uff0c\u6211\u4eec\u5148\u6765\u719f\u6089\u4e00\u4e0b\u76f8\u5173\u7684\u4e13\u7528\u672f\u8bed\uff0c\u597d\u8ba9\u5927\u5bb6\u5bf9\u672f\u8bed\u6709\u7edf\u4e00\u7684\u7406\u89e3\uff0c\u4ee5\u4fbf\u5728\u540e\u7eed\u5b9e\u9a8c\u65f6\u80fd\u76f4\u5954\u4e3b\u9898\u3002\u8fd9\u91cc\u6574\u7406\u7684\u4e0eAnsible\u76f8\u5173\u7684\u4e13\u7528\u672f\u8bed\u5982\u886816-1\u6240\u793a\u3002<\/p>\n \u886816-1\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 Ansible\u670d\u52a1\u4e13\u7528\u672f\u8bed\u5bf9\u7167\u8868<\/p>\n <\/p>\n \u7531\u4e8e\u53d7\u63a7\u8282\u70b9\u4e0d\u9700\u8981\u5b89\u88c5\u5ba2\u6237\u7aef\uff0c\u52a0\u4e4bSSH\u534f\u8bae\u662fLinux\u7cfb\u7edf\u7684\u6807\u914d\uff0c\u56e0\u6b64\u53ef\u4ee5\u76f4\u63a5\u901a\u8fc7SSH\u534f\u8bae\u8fdb\u884c\u8fdc\u7a0b\u63a7\u5236\u3002\u5728\u63a7\u5236\u8282\u70b9\u4e0a\uff0c\u4e5f\u65e0\u9700\u6bcf\u6b21\u90fd\u91cd\u590d\u542f\u52a8\u670d\u52a1\u7a0b\u5e8f\uff0c\u53ea\u9700\u4f7f\u7528ansible\u547d\u4ee4\u76f4\u63a5\u8c03\u7528\u6a21\u5757\u5373\u53ef\u8fdb\u884c\u63a7\u5236\u3002<\/p>\n RHEL 10\u7cfb\u7edf\u7684\u955c\u50cf\u6587\u4ef6\u9ed8\u8ba4\u4e0d\u5305\u542bAnsible\u670d\u52a1\u7a0b\u5e8f\uff0c\u7528\u6237\u9700\u8981\u4eceExtra Packages for Enterprise Linux\uff08EPEL\uff09\u6269\u5c55\u8f6f\u4ef6\u5305\u4ed3\u5e93\u83b7\u53d6\u3002EPEL\u8f6f\u4ef6\u5305\u4ed3\u5e93\u7531\u7ea2\u5e3d\u516c\u53f8\u63d0\u4f9b\uff0c\u662f\u4e00\u4e2a\u7528\u4e8e\u521b\u5efa\u3001\u7ef4\u62a4\u548c\u7ba1\u7406\u4f01\u4e1a\u7248Linux\u7684\u9ad8\u8d28\u91cf\u8f6f\u4ef6\u6269\u5c55\u4ed3\u5e93\uff0c\u901a\u7528\u4e8eRHEL\u3001CentOS\u3001Oracle Linux\u7b49\u591a\u79cd\u7ea2\u5e3d\u7cfb\u4f01\u4e1a\u7248\u7cfb\u7edf\uff0c\u76ee\u7684\u662f\u5bf9\u4e8e\u9ed8\u8ba4\u7cfb\u7edf\u4ed3\u5e93\u8f6f\u4ef6\u5305\u8fdb\u884c\u6269\u5c55\u3002<\/p>\n \u4e0b\u9762\u51c6\u5907\u5728\u7cfb\u7edf\u4e0a\u90e8\u7f72Ansible\u670d\u52a1\u7a0b\u5e8f\u3002<\/p>\n \u7b2c1\u6b65\uff1a<\/strong>\u5728\u201c\u865a\u62df\u673a\u8bbe\u7f6e\u201d\u754c\u9762\u4e2d\uff0c\u5c06\u201c\u7f51\u7edc\u9002\u914d\u5668\u201d\u7684\u201c\u7f51\u7edc\u8fde\u63a5\u201d\u9009\u9879\u8c03\u6574\u4e3a\u201c\u6865\u63a5\u6a21\u5f0f\u201d\uff0c\u5e76\u5c06\u7cfb\u7edf\u7684\u7f51\u5361\u8bbe\u7f6e\u6210\u201cAutomatic\uff08DHCP\uff09\u201d\u6a21\u5f0f\uff0c\u5982\u56fe16-1\u53ca\u56fe16-2\u6240\u793a\u3002<\/p>\n <\/p>\n \u3010\u6539\u6539\u6539\u3011<\/span><\/strong>\u56fe16-1 \u5c06\u201c\u7f51\u7edc\u8fde\u63a5\u201d\u8bbe\u7f6e\u4e3a\u201c\u6865\u63a5\u6a21\u5f0f\u201d<\/p>\n <\/p>\n \u3010\u6539\u6539\u6539\u3011<\/span><\/strong>\u56fe16-2 \u5c06\u7f51\u5361\u8bbe\u7f6e\u4e3a\u201cAutomatic\uff08DHCP\uff09\u201d\u6a21\u5f0f<\/p>\n \u5728\u5927\u591a\u6570\u60c5\u51b5\u4e0b\uff0c\u53ea\u8981\u628a\u865a\u62df\u673a\u8bbe\u7f6e\u6210\u6865\u63a5\u6a21\u5f0f\uff0c\u4e14Linux\u7cfb\u7edf\u7684\u7f51\u5361\u4fe1\u606f\u4e0e\u7269\u7406\u673a\u76f8\u540c\uff0c\u7136\u540e\u518d\u91cd\u542f\u7f51\u7edc\u670d\u52a1\uff0c\u5c31\u53ef\u4ee5\u8fde\u63a5\u5916\u90e8\u7f51\u7edc\u4e86\u3002\u5982\u679c\u4e0d\u653e\u5fc3\uff0c\u5c31\u901a\u8fc7ping\u547d\u4ee4\u6d4b\u8bd5\u4e0b\u5427\u3002<\/p>\n \u7b2c2\u6b65\uff1a<\/strong>\u5728\u539f\u6709\u8f6f\u4ef6\u4ed3\u5e93\u914d\u7f6e\u7684\u4e0b\u65b9\uff0c\u8ffd\u52a0EPEL\u6269\u5c55\u8f6f\u4ef6\u5305\u5b89\u88c5\u6e90\u7684\u4fe1\u606f\u3002<\/p>\n \u7b2c3\u6b65\uff1a<\/strong>\u5b89\u88c5\uff01<\/p>\n \u5b89\u88c5\u5b8c\u6bd5\u540e\uff0cAnsible\u670d\u52a1\u4fbf\u9ed8\u8ba4\u5df2\u7ecf\u542f\u52a8\u3002\u4f7f\u7528--version\u53c2\u6570\u53ef\u4ee5\u770b\u5230Ansible\u670d\u52a1\u7684\u7248\u672c\u53ca\u914d\u7f6e\u4fe1\u606f\u3002<\/p>\n \u5728\u521d\u6b21\u4f7f\u7528Ansible\u65f6\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u8fd9\u6837\u7684\u95ee\u9898\uff1a\u53c2\u6570\u660e\u660e\u5df2\u7ecf\u4fee\u6539\uff0c\u4f46\u5374\u672a\u751f\u6548\u3002\u8fd9\u901a\u5e38\u662f\u7531\u4e8eAnsible\u4e3b\u914d\u7f6e\u6587\u4ef6\u7684\u4f18\u5148\u7ea7\u987a\u5e8f\u6240\u5bfc\u81f4\u7684\u3002Ansible\u7684\u4e3b\u914d\u7f6e\u6587\u4ef6\u901a\u5e38\u5b58\u653e\u5728\/etc\/ansible\u76ee\u5f55\u4e2d\uff0c\u4f46\u5176\u4f18\u5148\u7ea7\u6700\u4f4e\u3002\u5982\u679c\u5728\u5f53\u524d\u76ee\u5f55\u6216\u7528\u6237\u5bb6\u76ee\u5f55\u4e2d\u5b58\u5728\u53e6\u4e00\u4efd\u4e3b\u914d\u7f6e\u6587\u4ef6\uff0c\u5219Ansible\u4f1a\u4f18\u5148\u4f7f\u7528\u8fd9\u4e9b\u6587\u4ef6\u3002\u5f53\u591a\u4e2a\u4e3b\u914d\u7f6e\u6587\u4ef6\u540c\u65f6\u5b58\u5728\u65f6\uff0c\u5177\u4f53\u4f18\u5148\u7ea7\u987a\u5e8f\u5982\u886816-2\u6240\u793a\u3002<\/p>\n \u886816-2\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 Ansible\u670d\u52a1\u4e3b\u914d\u7f6e\u6587\u4ef6\u4f18\u5148\u7ea7\u987a\u5e8f<\/p>\n <\/p>\n \u65e2\u7136Ansible\u670d\u52a1\u662f\u7528\u4e8e\u5b9e\u73b0\u4e3b\u673a\u6279\u91cf\u81ea\u52a8\u5316\u63a7\u5236\u7684\u7ba1\u7406\u5de5\u5177\uff0c\u53d7\u7ba1\u7684\u4e3b\u673a\u4e00\u5b9a\u4e0d\u662f\u4e00\u4e24\u53f0\u53f0\uff0c\u800c\u662f\u6570\u5341\u53f0\u751a\u81f3\u6210\u767e\u4e0a\u5343\u53f0\uff0c\u90a3\u4e48\u4e3b\u673a\u6e05\u5355\uff08inventory\uff09\u5728\u751f\u4ea7\u73af\u5883\u4e2d\u5c31\u5e2e\u4e0a\u5927\u5fd9\u4e86\u3002\u7528\u6237\u53ef\u4ee5\u628a\u8981\u7ba1\u7406\u7684\u4e3b\u673aIP\u5730\u5740\u9884\u5148\u5199\u5165\/etc\/ansible\/hosts\u6587\u4ef6\uff0c\u8fd9\u6837\u540e\u7eed\u518d\u901a\u8fc7\u6267\u884cansible\u547d\u4ee4\u6765\u6267\u884c\u4efb\u52a1\u65f6\u5c31\u81ea\u52a8\u5305\u542b\u8fd9\u4e9b\u4e3b\u673a\u4e86\uff0c\u4e5f\u5c31\u4e0d\u9700\u8981\u6bcf\u6b21\u90fd\u91cd\u590d\u8f93\u5165\u53d7\u7ba1\u4e3b\u673a\u7684\u5730\u5740\u4e86\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\u5047\u8bbe\u9700\u8981\u7ba1\u74065\u53f0\u4e3b\u673a\uff0c\u5b83\u4eec\u7684IP\u5730\u5740\u548c\u7528\u9014\u5982\u886816-3\u6240\u793a\u3002<\/p>\n \u886816-3\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u53d7\u7ba1\u4e3b\u673a\u4fe1\u606f<\/p>\n <\/p>\n \u9996\u5148\u9700\u8981\u8bf4\u660e\u7684\u662f\uff0c\u53d7\u7ba1\u4e3b\u673a\u7684\u7cfb\u7edf\u9ed8\u8ba4\u4f7f\u7528RHEL 10\uff0c\u8fd9\u662f\u4e3a\u4e86\u907f\u514d\u5927\u5bb6\u5728\u51c6\u5907\u5b9e\u9a8c\u673a\u9636\u6bb5\u4ea7\u751f\u6b67\u4e49\u800c\u7ed9\u51fa\u7684\u5efa\u8bae\u503c\uff0c\u4e5f\u53ef\u4ee5\u7528\u5176\u4ed6Linux\u7cfb\u7edf\u3002\u4e3b\u673a\u6e05\u5355\u6587\u4ef6\/etc\/ansible\/hosts\u4e2d\u9ed8\u8ba4\u5b58\u5728\u5927\u91cf\u7684\u6ce8\u91ca\u4fe1\u606f\uff0c\u5efa\u8bae\u5168\u90e8\u5220\u9664\uff0c\u7136\u540e\u66ff\u6362\u6210\u5b9e\u9a8c\u4fe1\u606f\u3002<\/p>\n \u4e3a\u4e86\u589e\u52a0\u5b9e\u9a8c\u96be\u5ea6\uff0c\u201c\u901a\u5403\u201d\u751f\u4ea7\u73af\u5883\u4e2d\u7684\u5e38\u89c1\u9700\u6c42\uff0c\u6211\u4eec\u53c8\u4e3a\u8fd95\u53f0\u4e3b\u673a\u5206\u522b\u89c4\u5212\u4e86\u529f\u80fd\u7528\u9014\uff0c\u6709\u5f00\u53d1\u673a\uff08dev\uff09\u3001\u6d4b\u8bd5\u673a\uff08test\uff09\u3001\u4ea7\u54c1\u673a\uff08prod\uff09\uff08\u4e24\u53f0\uff09\u548c\u8d1f\u8f7d\u5747\u8861\u673a\uff08balancers\uff09\u3002\u5728\u5bf9\u4e3b\u673a\u8fdb\u884c\u5206\u7ec4\u6807\u6ce8\u540e\uff0c\u540e\u671f\u5728\u7ba1\u7406\u65f6\u5c31\u65b9\u4fbf\u591a\u4e86\u3002<\/p>\n \u4e3b\u673a\u6e05\u5355\u6587\u4ef6\u5728\u4fee\u6539\u540e\u4f1a\u7acb\u5373\u751f\u6548\uff0c\u4e00\u822c\u4f7f\u7528\u201cansible-inventory --graph\u201d\u547d\u4ee4\u4ee5\u7ed3\u6784\u5316\u7684\u65b9\u5f0f\u663e\u793a\u51fa\u53d7\u7ba1\u4e3b\u673a\u7684\u4fe1\u606f\u3002\u56e0\u4e3a\u5bf9\u53d7\u7ba1\u4e3b\u673a\u8fdb\u884c\u4e86\u5206\u7ec4\uff0c\u56e0\u6b64\u8fd9\u79cd\u65b9\u5f0f\u975e\u5e38\u4fbf\u4e8e\u6211\u4eec\u9605\u8bfb\u3002<\/p>\n \u7b49\u7b49\uff01\u5148\u4e0d\u8981\u7740\u6025\u5f00\u59cb\u540e\u9762\u7684\u5b9e\u9a8c\u3002\u524d\u6587\u8bb2\u8fc7\uff0cAnsible\u670d\u52a1\u662f\u57fa\u4e8eSSH\u534f\u8bae\u8fdb\u884c\u81ea\u52a8\u5316\u63a7\u5236\u7684\uff0c\u8fd9\u662f\u5f00\u5c55\u540e\u9762\u5b9e\u9a8c\u7684\u524d\u63d0\u6761\u4ef6\u3002\u7b2c9\u7ae0\u66fe\u7ecf\u8bb2\u5230\uff0csshd\u670d\u52a1\u5728\u521d\u6b21\u8fde\u63a5\u65f6\u4f1a\u8981\u6c42\u7528\u6237\u63a5\u53d7\u4e00\u6b21\u5bf9\u65b9\u4e3b\u673a\u7684\u6307\u7eb9\u4fe1\u606f\u3002\u51c6\u5907\u8f93\u5165\u53d7\u7ba1\u4e3b\u673a\u7684\u8d26\u53f7\u548c\u5bc6\u7801\u3002\u4f8b\u5982\uff0c\u6b63\u5e38\u7684\u7b2c\u4e00\u6b21SSH\u8fdc\u7a0b\u8fde\u63a5\u8fc7\u7a0b\u662f\u8fd9\u6837\u7684\uff1a<\/p>\n \u4f17\u6240\u5468\u77e5\uff0c\u81ea\u52a8\u5316\u8fd0\u7ef4\u7684\u4e00\u4e2a\u597d\u5904\u5c31\u662f\u80fd\u63d0\u9ad8\u5de5\u4f5c\u6548\u7387\u3002\u4f46\u662f\uff0c\u5982\u679c\u6bcf\u6b21\u6267\u884c\u64cd\u4f5c\u90fd\u8981\u8f93\u5165\u53d7\u7ba1\u4e3b\u673a\u7684\u5bc6\u7801\uff0c\u4e5f\u662f\u6bd4\u8f83\u9ebb\u70e6\u7684\u4e8b\u60c5\u3002\u597d\u5728Ansible\u670d\u52a1\u5df2\u7ecf\u5bf9\u6b64\u6709\u4e86\u89e3\u51b3\u529e\u6cd5\uff0c\u90a3\u5c31\u662f\u4f7f\u7528\u5982\u886816-4\u6240\u793a\u7684\u53d8\u91cf\u3002<\/p>\n \u886816-4\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0Ansible\u5e38\u7528\u53d8\u91cf\u6c47\u603b<\/p>\n <\/p>\n \u7528\u6237\u53ea\u9700\u8981\u5c06\u5bf9\u5e94\u7684\u53d8\u91cf\u53ca\u4fe1\u606f\u586b\u5199\u5230\u4e3b\u673a\u6e05\u5355\u6587\u4ef6\u4e2d\uff0c\u5728\u6267\u884c\u4efb\u52a1\u65f6\u4fbf\u4f1a\u81ea\u52a8\u5bf9\u8d26\u53f7\u548c\u5bc6\u7801\u8fdb\u884c\u5339\u914d\uff0c\u800c\u4e0d\u7528\u6bcf\u6b21\u91cd\u590d\u8f93\u5165\u5b83\u4eec\u3002\u7ee7\u7eed\u4fee\u6539\u4e3b\u673a\u6e05\u5355\u6587\u4ef6\uff1a<\/p>\n \u8fd8\u5269\u6700\u540e\u4e00\u6b65\u3002\u5c06Ansible\u4e3b\u914d\u7f6e\u6587\u4ef6\u4e2d\u7684\u3010\u6539\u6539\u6539\u3011<\/span><\/strong>\u7b2c71\u884c\u8bbe\u7f6e\u6210\u9ed8\u8ba4\u4e0d\u9700\u8981SSH\u534f\u8bae\u7684\u6307\u7eb9\u9a8c\u8bc1\uff0c\u4ee5\u53ca\u5c06\u3010\u6539\u6539\u6539\u3011<\/span><\/strong>\u7b2c107\u884c\u8bbe\u7f6e\u6210\u9ed8\u8ba4\u6267\u884c\u5267\u672c\u65f6\u6240\u4f7f\u7528\u7684\u7ba1\u7406\u5458\u540d\u79f0\u4e3aroot\uff1a<\/p>\n \u4e0d\u9700\u8981\u91cd\u542f\u670d\u52a1\uff0c\u5728\u4ee5\u4e0a\u64cd\u4f5c\u5b8c\u5168\u641e\u5b9a\u540e\u5c31\u53ef\u4ee5\u5f00\u59cb\u540e\u9762\u7684\u5b9e\u9a8c\u4e86\u3002\u7531\u4e8e\u521a\u624d\u662f\u5c06Ansible\u670d\u52a1\u5668\u8bbe\u7f6e\u6210\u4e86\u6865\u63a5\u53caDHCP\u6a21\u5f0f\uff0c\u73b0\u5728\u8bf7\u540c\u5b66\u4eec\u81ea\u884c\u5c06\u7f51\u7edc\u9002\u914d\u5668\u4fee\u6539\u56de\u201c\u4ec5\u4e3b\u673a\u6a21\u5f0f\u201d\uff08\u89c1\u56fe16-3\uff09\u4ee5\u53ca192.168.10.10\/24\u7684IP\u5730\u5740\u3002\u5728\u4fee\u6539\u5b8c\u6210\u540e\u91cd\u542f\u7f51\u5361\uff0c\u7136\u540e\u81ea\u884c\u5728\u4e3b\u673a\u4e4b\u95f4\u6267\u884cping\u64cd\u4f5c\u3002\u4fdd\u8bc1\u4e3b\u673a\u4e4b\u95f4\u7684\u7f51\u7edc\u80fd\u591f\u4e92\u901a\u662f\u540e\u7eed\u5b9e\u9a8c\u7684\u57fa\u77f3\u3002<\/p>\n <\/p>\n \u3010\u6539\u6539\u6539\u3011<\/span><\/strong>\u56fe16-3 \u5c06\u865a\u62df\u673a\u7f51\u5361\u6539\u56de\u4ec5\u4e3b\u673a\u6a21\u5f0f<\/p>\n Ansible\u670d\u52a1\u7684\u5f3a\u5927\u4e4b\u5904\u5728\u4e8e\u53ea\u9700\u8981\u4e00\u6761\u547d\u4ee4\uff0c\u4fbf\u80fd\u591f\u64cd\u63a7\u6210\u5343\u4e0a\u4e07\u53f0\u7684\u4e3b\u673a\u8282\u70b9\uff0c\u800cansible\u547d\u4ee4\u4fbf\u662f\u6700\u5f97\u529b\u7684\u5de5\u5177\u4e4b\u4e00\u3002\u524d\u6587\u63d0\u5230\uff0cAnsible\u670d\u52a1\u5b9e\u9645\u4e0a\u53ea\u662f\u4e00\u4e2a\u6846\u67b6\uff0c\u5b9e\u9645\u5b8c\u6210\u5de5\u4f5c\u7684\u662f\u6a21\u5757\u5316\u529f\u80fd\u4ee3\u7801\u3002Ansible\u7684\u5e38\u7528\u6a21\u5757\u5927\u81f4\u670920\u591a\u4e2a\uff08\u89c1\u886816-5\uff09\uff0c\u672c\u4e66\u5c06\u4f1a\u5728\u540e\u9762\u7684\u5b9e\u9a8c\u4e2d\u9010\u4e00\u8be6\u89e3\u3002<\/p>\n \u5076\u5c14\u9047\u5230\u4e66\u4e2d\u6ca1\u6709\u63d0\u53ca\u7684\u6a21\u5757\uff0c\u5927\u5bb6\u53ef\u4ee5\u4f7f\u7528\u201cansible-doc\u6a21\u5757\u540d\u79f0\u201d\u7684\u547d\u4ee4\u683c\u5f0f\u81ea\u884c\u67e5\u8be2\uff0c\u6216\u662f\u4f7f\u7528ansible-doc -l\u547d\u4ee4\u5217\u51fa\u6240\u6709\u7684\u6a21\u5757\u4fe1\u606f\u4ee5\u4f9b\u9009\u62e9\u3002<\/p>\n \u886816-5\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0Ansible\u670d\u52a1\u5e38\u7528\u6a21\u5757\u540d\u79f0\u53ca\u4f5c\u7528<\/p>\n <\/p>\n \u5728Ansible\u670d\u52a1\u4e2d\uff0cansible\u662f\u7528\u4e8e\u6267\u884c\u4e34\u65f6\u4efb\u52a1\u7684\u547d\u4ee4\uff0c\u4e5f\u5c31\u5728\u662f\u6267\u884c\u540e\u5373\u7ed3\u675f\uff08\u4e0e\u5267\u672c\u6587\u4ef6\u7684\u53ef\u91cd\u590d\u6267\u884c\u4e0d\u540c\uff09\u3002\u5728\u4f7f\u7528ansible\u547d\u4ee4\u65f6\uff0c\u5fc5\u987b\u6307\u660e\u53d7\u7ba1\u4e3b\u673a\u7684\u4fe1\u606f\uff0c\u5982\u679c\u5df2\u7ecf\u8bbe\u7f6e\u8fc7\u4e3b\u673a\u6e05\u5355\u6587\u4ef6\uff08\/etc\/ansible\/hosts\uff09\uff0c\u5219\u53ef\u4ee5\u4f7f\u7528all\u53c2\u6570\u6765\u6307\u4ee3\u5168\u4f53\u53d7\u7ba1\u4e3b\u673a\uff0c\u6216\u662f\u7528dev\u3001test\u7b49\u4e3b\u673a\u7ec4\u540d\u79f0\u6765\u6307\u4ee3\u67d0\u4e00\u7ec4\u7684\u4e3b\u673a\u3002<\/p>\n ansible\u547d\u4ee4\u5e38\u7528\u7684\u8bed\u6cd5\u683c\u5f0f\u4e3a\u201cansible \u53d7\u7ba1\u4e3b\u673a\u8282\u70b9 -m \u6a21\u5757\u540d\u79f0 [-a \u6a21\u5757\u53c2\u6570]\u201d\uff0c\u5e38\u89c1\u7684\u53c2\u6570\u5982\u886816-6\u6240\u793a\u3002\u5176\u4e2d\uff0c-a\u662f\u8981\u4f20\u9012\u7ed9\u6a21\u5757\u7684\u53c2\u6570\uff0c\u53ea\u6709\u529f\u80fd\u6781\u5176\u7b80\u5355\u7684\u6a21\u5757\u624d\u4e0d\u9700\u8981\u989d\u5916\u53c2\u6570\uff0c\u6240\u4ee5\u5927\u591a\u60c5\u51b5\u4e0b-m\u4e0e-a\u53c2\u6570\u90fd\u4f1a\u540c\u65f6\u51fa\u73b0\u3002<\/p>\n \u886816-6\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0ansible\u547d\u4ee4\u5e38\u7528\u53c2\u6570<\/p>\n <\/p>\n \u5982\u679c\u60f3\u5b9e\u73b0\u67d0\u4e2a\u529f\u80fd\uff0c\u4f46\u662f\u5374\u4e0d\u77e5\u9053\u7528\u4ec0\u4e48\u6a21\u5757\uff0c\u53c8\u6216\u8005\u662f\u77e5\u9053\u4e86\u6a21\u5757\u540d\u79f0\uff0c\u4f46\u4e0d\u6e05\u695a\u6a21\u5757\u5177\u4f53\u7684\u4f5c\u7528\uff0c\u5219\u5efa\u8bae\u4f7f\u7528ansible-doc\u547d\u4ee4\u8fdb\u884c\u67e5\u627e\u3002\u4f8b\u5982\uff0c\u5217\u4e3e\u51fa\u5f53\u524dAnsible\u670d\u52a1\u6240\u652f\u6301\u7684\u6240\u6709\u6a21\u5757\u4fe1\u606f\uff1a<\/p>\n \u4e00\u822c\u60c5\u51b5\u4e0b\uff0c\u5f88\u96be\u901a\u8fc7\u540d\u79f0\u6765\u5224\u522b\u4e00\u4e2a\u6a21\u5757\u7684\u4f5c\u7528\uff0c\u8981\u4e48\u662f\u53c2\u8003\u6a21\u5757\u540e\u9762\u7684\u4ecb\u7ecd\u4fe1\u606f\uff0c\u8981\u4e48\u662f\u5e73\u65f6\u591a\u5b66\u591a\u7ec3\uff0c\u8fdb\u884c\u79ef\u7d2f\u3002\u4f8b\u5982\uff0c\u63a5\u4e0b\u6765\u968f\u673a\u67e5\u770b\u4e00\u4e2a\u6a21\u5757\u7684\u8be6\u7ec6\u4fe1\u606f\u3002ansible-doc\u547d\u4ee4\u4f1a\u5728\u5c4f\u5e55\u4e0a\u663e\u793a\u51fa\u8fd9\u4e2a\u6a21\u5757\u7684\u4f5c\u7528\u3001\u53ef\u7528\u53c2\u6570\u53ca\u5b9e\u4f8b\u7b49\u4fe1\u606f\uff1a<\/p>\n \u572816.2\u8282\uff0c\u5df2\u7ecf\u6210\u529f\u5730\u5c06\u53d7\u7ba1\u4e3b\u673a\u7684IP\u5730\u5740\u586b\u5199\u5230\u4e3b\u673a\u6e05\u5355\u6587\u4ef6\u4e2d\uff0c\u63a5\u4e0b\u6765\u5c0f\u8bd5\u725b\u5200\uff0c\u68c0\u67e5\u4e00\u4e0b\u8fd9\u4e9b\u4e3b\u673a\u7684\u7f51\u7edc\u8fde\u901a\u6027\u3002ping\u6a21\u5757\u7528\u4e8e\u8fdb\u884c\u7b80\u5355\u7684\u7f51\u7edc\u6d4b\u8bd5\uff08\u7c7b\u4f3c\u4e8e\u5e38\u7528\u7684ping\u547d\u4ee4\uff09\u3002\u53ef\u4ee5\u4f7f\u7528ansible\u547d\u4ee4\u76f4\u63a5\u9488\u5bf9\u6240\u6709\u4e3b\u673a\u8c03\u7528ping\u6a21\u5757\uff0c\u4e0d\u9700\u8981\u589e\u52a0\u989d\u5916\u7684\u53c2\u6570\uff0c\u8fd4\u56de\u503c\u82e5\u4e3aSUCCESS\uff0c\u5219\u8868\u793a\u4e3b\u673a\u5f53\u524d\u5728\u7ebf\u3002<\/p>\n \u7531\u4e8e5\u53f0\u53d7\u63a7\u4e3b\u673a\u7684\u8f93\u51fa\u4fe1\u606f\u5927\u81f4\u76f8\u540c\uff0c\u56e0\u6b64\u4e3a\u4e86\u63d0\u5347\u8bfb\u8005\u7684\u9605\u8bfb\u4f53\u9a8c\uff0c\u672c\u7ae0\u540e\u7eed\u7684\u8f93\u51fa\u7ed3\u679c\u9ed8\u8ba4\u4ec5\u4fdd\u7559192.168.10.20\u4e3b\u673a\u7684\u8f93\u51fa\u503c\uff0c\u5176\u4f59\u76f8\u540c\u7684\u8f93\u51fa\u4fe1\u606f\u5c06\u4f1a\u88ab\u7701\u7565\u3002<\/p>\n<\/div>\n<\/div>\n \u662f\u4e0d\u662f\u611f\u89c9\u5f88\u65b9\u4fbf\u5462\uff1f\uff01\u4e00\u6b21\u5c31\u80fd\u77e5\u9053\u6240\u6709\u4e3b\u673a\u7684\u5728\u7ebf\u60c5\u51b5\u3002\u9664\u4e86\u4f7f\u7528-m\u53c2\u6570\u76f4\u63a5\u6307\u5b9a\u6a21\u5757\u540d\u79f0\u4e4b\u5916\uff0c\u8fd8\u53ef\u4ee5\u7528-a\u53c2\u6570\u5c06\u53c2\u6570\u4f20\u9012\u7ed9\u6a21\u5757\uff0c\u8ba9\u6a21\u5757\u7684\u529f\u80fd\u66f4\u9ad8\u7ea7\uff0c\u66f4\u597d\u5730\u6ee1\u8db3\u5f53\u524d\u751f\u4ea7\u7684\u9700\u6c42\u3002\u4f8b\u5982\uff0cyum_repository\u6a21\u5757\u7684\u4f5c\u7528\u662f\u7ba1\u7406\u4e3b\u673a\u7684\u8f6f\u4ef6\u4ed3\u5e93\uff0c\u80fd\u591f\u6dfb\u52a0\u3001\u4fee\u6539\u53ca\u5220\u9664\u8f6f\u4ef6\u4ed3\u5e93\u7684\u914d\u7f6e\u4fe1\u606f\uff0c\u53c2\u6570\u76f8\u5bf9\u6bd4\u8f83\u590d\u6742\u3002\u9047\u5230\u8fd9\u79cd\u60c5\u51b5\u65f6\uff0c\u5efa\u8bae\u5148\u7528ansible-doc\u547d\u4ee4\u5bf9\u5176\u8fdb\u884c\u4e86\u89e3\u3002\u5c24\u5176\u662f\u4e0b\u9762\u7684EXAMPLES\u7ed3\u6784\u6bb5\u4f1a\u6709\u8be5\u6a21\u5757\u7684\u5b9e\u4f8b\uff0c\u5bf9\u7528\u6237\u6765\u8bf4\u6709\u975e\u5e38\u9ad8\u7684\u53c2\u8003\u4ef7\u503c\u3002<\/p>\n \u8fd8\u597d\uff0c\u53c2\u6570\u5e76\u4e0d\u662f\u5f88\u591a\uff0c\u800c\u4e14\u4e0e\u6b64\u524d\u5b66\u8fc7\u7684\/etc\/yum.repos.d\/\u76ee\u5f55\u4e2d\u7684\u914d\u7f6e\u6587\u4ef6\u57fa\u672c\u76f8\u4f3c\u3002\u73b0\u5728\uff0c\u60f3\u4e3a\u4e3b\u673a\u6e05\u5355\u4e2d\u7684\u6240\u6709\u670d\u52a1\u5668\u65b0\u589e\u4e00\u4e2a\u5982\u886816-7\u6240\u793a\u7684\u8f6f\u4ef6\u4ed3\u5e93\uff0c\u8be5\u600e\u4e48\u64cd\u4f5c\u5462\uff1f<\/p>\n \u886816-7\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u65b0\u589e\u8f6f\u4ef6\u4ed3\u5e93\u4fe1\u606f<\/p>\n <\/p>\n \u6211\u4eec\u53ef\u4ee5\u5bf9\u7167\u7740EXAMPLE\u5b9e\u4f8b\u6bb5\uff0c\u9010\u4e00\u5bf9\u5e94\u586b\u5199\u9700\u6c42\u503c\u548c\u53c2\u6570\uff0c\u5176\u6807\u51c6\u683c\u5f0f\u662f\u5728-a\u53c2\u6570\u540e\u63a5\u6574\u4f53\u53c2\u6570\uff08\u7528\u5355\u5f15\u53f7\u5708\u8d77\uff09\uff0c\u800c\u5404\u4e2a\u53c2\u6570\u5b57\u6bb5\u7684\u503c\u5219\u7528\u53cc\u5f15\u53f7\u5708\u8d77\u3002\u8fd9\u662f\u6700\u4e25\u8c28\u7684\u5199\u6cd5\u3002\u5728\u6267\u884c\u4e0b\u8ff0\u547d\u4ee4\u540e\u5982\u679c\u51fa\u73b0CHANGED\u5b57\u6837\uff0c\u5219\u8868\u793a\u4fee\u6539\u5df2\u7ecf\u6210\u529f\uff1a<\/p>\n \u5728\u547d\u4ee4\u6267\u884c\u6210\u529f\u540e\uff0c\u53ef\u4ee5\u5230\u4e3b\u673a\u6e05\u5355\u4e2d\u7684\u4efb\u610f\u673a\u5668\u4e0a\u67e5\u770b\u65b0\u5efa\u6210\u529f\u7684\u8f6f\u4ef6\u4ed3\u5e93\u914d\u7f6e\u6587\u4ef6\u3002\u5c3d\u7ba1\u8fd9\u4e2a\u5b9e\u9a8c\u7684\u53c2\u6570\u5f88\u591a\uff0c\u4f46\u662f\u5e76\u4e0d\u96be\u3002<\/p>\n \u5728\u5f88\u591a\u60c5\u51b5\u4e0b\uff0c\u4ec5\u4ec5\u6267\u884c\u5355\u4e2a\u547d\u4ee4\u6216\u8c03\u7528\u67d0\u4e00\u4e2a\u6a21\u5757\uff0c\u6839\u672c\u65e0\u6cd5\u6ee1\u8db3\u590d\u6742\u5de5\u4f5c\u7684\u9700\u8981\u3002Ansible\u670d\u52a1\u5141\u8bb8\u7528\u6237\u6839\u636e\u9700\u6c42\uff0c\u5728\u7c7b\u4f3c\u4e8eShell\u811a\u672c\u7684\u6a21\u5f0f\u4e0b\u7f16\u5199\u81ea\u52a8\u5316\u8fd0\u7ef4\u811a\u672c\uff0c\u7136\u540e\u7531\u7a0b\u5e8f\u81ea\u52a8\u3001\u91cd\u590d\u5730\u6267\u884c\uff0c\u4ece\u800c\u5927\u5927\u63d0\u9ad8\u4e86\u5de5\u4f5c\u6548\u7387\u3002<\/p>\n Ansible\u670d\u52a1\u7684\u5267\u672c\uff08playbook\uff09\u6587\u4ef6\u91c7\u7528YAML\u8bed\u8a00\u7f16\u5199\uff0c\u5177\u6709\u5f3a\u5236\u6027\u7684\u683c\u5f0f\u89c4\u8303\uff0c\u5b83\u901a\u8fc7\u7a7a\u683c\u5c06\u4e0d\u540c\u4fe1\u606f\u5206\u7ec4\uff0c\u56e0\u6b64\u6709\u65f6\u4f1a\u56e0\u4e00\u4e24\u4e2a\u7a7a\u683c\u9519\u4f4d\u800c\u5bfc\u81f4\u62a5\u9519\u3002\u5927\u5bb6\u5728\u4f7f\u7528\u65f6\u8981\u4e07\u5206\u5c0f\u5fc3\u3002YAML\u6587\u4ef6\u7684\u5f00\u5934\u9700\u8981\u5148\u51993\u4e2a\u51cf\u53f7\uff08---\uff09\uff0c\u591a\u4e2a\u5206\u7ec4\u7684\u4fe1\u606f\u9700\u8981\u95f4\u9694\u4e00\u81f4\u624d\u80fd\u6267\u884c\uff0c\u800c\u4e14\u4e0a\u4e0b\u4e5f\u8981\u5bf9\u9f50\uff0c\u540e\u7f00\u540d\u4e00\u822c\u4e3a.yml\u3002\u5267\u672c\u6587\u4ef6\u5728\u6267\u884c\u540e\uff0c\u4f1a\u5728\u5c4f\u5e55\u4e0a\u8f93\u51fa\u8fd0\u884c\u754c\u9762\uff0c\u5185\u5bb9\u4f1a\u6839\u636e\u5de5\u4f5c\u7684\u4e0d\u540c\u800c\u53d8\u5316\u3002\u5728\u8fd0\u884c\u754c\u9762\u4e2d\uff0c\u7eff\u8272\u8868\u793a\u6210\u529f\uff0c\u9ec4\u8272\u8868\u793a\u6267\u884c\u6210\u529f\u5e76\u8fdb\u884c\u4e86\u4fee\u6539\uff0c\u800c\u7ea2\u8272\u5219\u8868\u793a\u6267\u884c\u5931\u8d25\u3002<\/p>\n \u5267\u672c\u6587\u4ef6\u7684\u7ed3\u6784\u7531\u56db\u90e8\u5206\u7ec4\u6210\uff0c\u5206\u522b\u662ftarget\u3001variable\u3001task\u3001handler\uff0c\u5176\u5404\u81ea\u7684\u4f5c\u7528\u5982\u4e0b\u3002<\/p>\n target<\/strong>\uff1a\u7528\u4e8e\u5b9a\u4e49\u8981\u6267\u884c\u5267\u672c\u7684\u4e3b\u673a\u8303\u56f4\u3002<\/p>\n variable<\/strong>\uff1a\u7528\u4e8e\u5b9a\u4e49\u5267\u672c\u6267\u884c\u65f6\u8981\u7528\u5230\u7684\u53d8\u91cf\u3002<\/p>\n task<\/strong>\uff1a\u7528\u4e8e\u5b9a\u4e49\u5c06\u5728\u8fdc\u7a0b\u4e3b\u673a\u4e0a\u6267\u884c\u7684\u4efb\u52a1\u5217\u8868\u3002<\/p>\n handler<\/strong>\uff1a\u7528\u4e8e\u5b9a\u4e49\u6267\u884c\u5b8c\u6210\u540e\u9700\u8981\u8c03\u7528\u7684\u540e\u7eed\u4efb\u52a1\u3002<\/p><\/blockquote>\n YAML\u8bed\u8a00\u7f16\u5199\u7684Ansible\u5267\u672c\u6587\u4ef6\u4f1a\u6309\u7167\u4ece\u4e0a\u5230\u4e0b\u7684\u987a\u5e8f\u81ea\u52a8\u8fd0\u884c\uff0c\u5176\u5f62\u5f0f\u7c7b\u4f3c\u4e8e\u7b2c4\u7ae0\u4ecb\u7ecd\u7684Shell\u811a\u672c\uff0c\u4f46\u683c\u5f0f\u6709\u4e25\u683c\u7684\u8981\u6c42\u3002\u4f8b\u5982\uff0c\u521b\u5efa\u4e00\u4e2a\u540d\u4e3apackages.yml\u7684\u5267\u672c\uff0c\u8ba9dev\u3001test\u548cprod\u7ec4\u7684\u4e3b\u673a\u53ef\u4ee5\u81ea\u52a8\u5b89\u88c5\u6570\u636e\u5e93\u8f6f\u4ef6\uff0c\u5e76\u4e14\u5c06dev\u7ec4\u4e3b\u673a\u7684\u8f6f\u4ef6\u66f4\u65b0\u81f3\u6700\u65b0\u3002<\/p>\n \u5b89\u88c5\u548c\u66f4\u65b0\u8f6f\u4ef6\u9700\u8981\u4f7f\u7528yum\u6a21\u5757\u3002\u5148\u770b\u4e00\u4e0b\u5e2e\u52a9\u4fe1\u606f\u4e2d\u7684\u793a\u4f8b\u5427\uff1a<\/p>\n \u5728\u914d\u7f6eAnsible\u5267\u672c\u6587\u4ef6\u65f6\uff0cansible-doc\u547d\u4ee4\u63d0\u4f9b\u7684\u5e2e\u52a9\u4fe1\u606f\u771f\u662f\u597d\u7528\u3002\u5728\u77e5\u9053yum\u6a21\u5757\u7684\u4f7f\u7528\u65b9\u6cd5\u548c\u683c\u5f0f\u540e\uff0c\u5c31\u53ef\u4ee5\u5f00\u59cb\u7f16\u5199\u5267\u672c\u4e86\u3002\u521d\u6b21\u7f16\u5199\u5267\u672c\u6587\u4ef6\u65f6\uff0c\u8bf7\u52a1\u5fc5\u770b\u51c6\u683c\u5f0f\uff0c\u6a21\u5757\u53caplay\uff08\u52a8\u4f5c\uff09\u683c\u5f0f\u4e5f\u8981\u4e0a\u4e0b\u5bf9\u9f50\uff0c\u5426\u5219\u4f1a\u51fa\u73b0\u201c\u53c2\u6570\u4e00\u6a21\u4e00\u6837\uff0c\u4f46\u4e0d\u80fd\u6267\u884c\u201d\u7684\u60c5\u51b5\u3002<\/p>\n \u7efc\u4e0a\uff0c\u4e00\u4e2a\u5267\u672c\u6b63\u786e\u7684\u5199\u6cd5\u5e94\u8be5\u662f\uff1a<\/p>\n \u5176\u4e2d\uff0cname\u5b57\u6bb5\u8868\u793a\u6b64\u9879play\uff08\u52a8\u4f5c\uff09\u7684\u540d\u5b57\uff0c\u7528\u4e8e\u5728\u6267\u884c\u8fc7\u7a0b\u4e2d\u63d0\u793a\u7528\u6237\u6267\u884c\u5230\u4e86\u54ea\u4e00\u6b65\uff0c\u4ee5\u53ca\u5e2e\u52a9\u7ba1\u7406\u5458\u5728\u65e5\u540e\u9605\u8bfb\u65f6\u80fd\u60f3\u8d77\u8fd9\u6bb5\u4ee3\u7801\u7684\u4f5c\u7528\u3002\u5927\u5bb6\u53ef\u4ee5\u5728name\u5b57\u6bb5\u81ea\u884c\u547d\u540d\uff0c\u6ca1\u6709\u4efb\u4f55\u9650\u5236\u3002hosts\u5b57\u6bb5\u8868\u793a\u8981\u5728\u54ea\u4e9b\u4e3b\u673a\u4e0a\u6267\u884c\u8be5\u5267\u672c\uff0c\u591a\u4e2a\u4e3b\u673a\u7ec4\u4e4b\u95f4\u7528\u9017\u53f7\u95f4\u9694\uff1b\u5982\u679c\u9700\u8981\u5bf9\u5168\u90e8\u4e3b\u673a\u8fdb\u884c\u64cd\u4f5c\uff0c\u5219\u4f7f\u7528all\u53c2\u6570\u3002tasks\u5b57\u6bb5\u7528\u4e8e\u5b9a\u4e49\u8981\u6267\u884c\u7684\u4efb\u52a1\uff0c\u6bcf\u4e2a\u4efb\u52a1\u90fd\u8981\u6709\u4e00\u4e2a\u72ec\u7acb\u7684name\u5b57\u6bb5\u8fdb\u884c\u547d\u540d\uff0c\u5e76\u4e14\u6bcf\u4e2a\u4efb\u52a1\u7684name\u5b57\u6bb5\u548c\u6a21\u5757\u540d\u79f0\u90fd\u8981\u4e25\u683c\u4e0a\u4e0b\u5bf9\u9f50\uff0c\u53c2\u6570\u8981\u5355\u72ec\u7f29\u8fdb\u3002<\/p>\n \u800c\u9519\u8bef\u7684\u5267\u672c\u6587\u4ef6\u662f\u4e0b\u9762\u8fd9\u6837\u7684\uff1a<\/p>\n \u5927\u5bb6\u5df2\u7ecf\u611f\u53d7\u5230YAML\u8bed\u8a00\u5bf9\u683c\u5f0f\u8981\u6c42\u6709\u591a\u4e25\u683c\u5427\u3002<\/p>\n \u5728\u7f16\u5199Ansible\u5267\u672c\u6587\u4ef6\u65f6\uff0cRHEL 10\u7cfb\u7edf\u81ea\u5e26\u7684Vim\u7f16\u8f91\u5668\u5177\u6709\u81ea\u52a8\u7f29\u8fdb\u529f\u80fd\uff0c\u80fd\u7ed9\u6211\u4eec\u63d0\u4f9b\u5f88\u591a\u5e2e\u52a9\u3002\u5728\u786e\u8ba4\u65e0\u8bef\u540e\u5c31\u53ef\u4ee5\u7528ansible-playbook\u547d\u4ee4\u8fd0\u884c\u8fd9\u4e2a\u5267\u672c\u6587\u4ef6\u4e86\u3002<\/p>\n \u5728\u6267\u884c\u6210\u529f\u540e\uff0c\u6211\u4eec\u4e3b\u8981\u89c2\u5bdf\u6700\u4e0b\u65b9\u7684\u8f93\u51fa\u4fe1\u606f\u3002\u5176\u4e2d\uff0cok\u548cchanged\u8868\u793a\u6267\u884c\u53ca\u4fee\u6539\u6210\u529f\u3002\u5982\u9047\u5230unreachable\u6216failed\u5927\u4e8e0\u7684\u60c5\u51b5\uff0c\u5efa\u8bae\u624b\u52a8\u68c0\u67e5\u5267\u672c\u662f\u5426\u5728\u6240\u6709\u4e3b\u673a\u4e2d\u90fd\u6b63\u786e\u8fd0\u884c\u4e86\uff0c\u4ee5\u53ca\u6709\u65e0\u5b89\u88c5\u5931\u8d25\u7684\u60c5\u51b5\u3002\u5728\u6b63\u786e\u6267\u884c\u8fc7packages.yml\u6587\u4ef6\u540e\uff0c\u968f\u673a\u5207\u6362\u5230dev\u3001test\u3001prod\u7ec4\u4e2d\u7684\u4efb\u610f\u4e00\u53f0\u4e3b\u673a\u4e0a\uff0c\u518d\u6b21\u5b89\u88c5mariadb\u8f6f\u4ef6\u5305\uff0c\u6b64\u65f6\u4f1a\u63d0\u793a\u8be5\u670d\u52a1\u5df2\u7ecf\u5b58\u5728\u3002\u8fd9\u8bf4\u660e\u521a\u624d\u7684\u64cd\u4f5c\u4e00\u5207\u987a\u5229\uff01<\/p>\n \u5728\u7f16\u5199Ansible\u5267\u672c\u65f6\uff0c\u968f\u7740\u5185\u5bb9\u7684\u4e0d\u65ad\u589e\u52a0\uff0c\u4ee3\u7801\u53ef\u80fd\u53d8\u5f97\u5197\u957f\u3001\u590d\u6742\uff0c\u96be\u4ee5\u7ef4\u62a4\uff0c\u4e14\u5176\u4ed6\u5267\u672c\u4e5f\u96be\u4ee5\u7075\u6d3b\u8c03\u7528\u5176\u4e2d\u7684\u529f\u80fd\u3002\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e9b\u95ee\u9898\uff0cAnsible\u81ea1.2\u7248\u672c\u8d77\u5f15\u5165\u4e86\u201c\u89d2\u8272\u201d\uff08Role\uff09\u529f\u80fd\uff0c\u7528\u4e8e\u5c42\u6b21\u5316\u3001\u7ed3\u6784\u5316\u5730\u7ec4\u7ec7\u5267\u672c\u3002\u89d2\u8272\u529f\u80fd\u5c06\u53d8\u91cf\u3001\u6587\u4ef6\u3001\u4efb\u52a1\u3001\u6a21\u5757\u53ca\u5904\u7406\u5668\u5206\u522b\u653e\u7f6e\u5728\u72ec\u7acb\u7684\u76ee\u5f55\u4e2d\uff0c\u80fd\u591f\u65b9\u4fbf\u5730\u8fdb\u884c\u52a0\u8f7d\u548c\u590d\u7528\u3002\u7b80\u5355\u6765\u8bf4\uff0c\u89d2\u8272\u529f\u80fd\u5c06\u5e38\u7528\u7684\u529f\u80fd\u6a21\u5757\u5316\uff0c\u4f7f\u5176\u5728\u88ab\u9700\u8981\u65f6\u65b9\u4fbf\u5730\u8c03\u7528\u3002<\/p>\n Ansible\u7684\u89d2\u8272\u529f\u80fd\u7c7b\u4f3c\u4e8e\u7f16\u7a0b\u4e2d\u7684\u5c01\u88c5\u6280\u672f\u2014\u2014\u5c06\u5177\u4f53\u529f\u80fd\u5c01\u88c5\u8d77\u6765\uff0c\u7528\u6237\u4e0d\u4ec5\u53ef\u4ee5\u65b9\u4fbf\u5730\u8c03\u7528\uff0c\u8fd8\u4e0d\u5fc5\u6df1\u5165\u7406\u89e3\u5176\u5185\u90e8\u539f\u7406\u3002\u5c31\u50cf\u666e\u901a\u6d88\u8d39\u8005\u5728\u9a7e\u9a76\u6c7d\u8f66\u65f6\uff0c\u4e0d\u9700\u8981\u7406\u89e3\u5239\u8f66\u7cfb\u7edf\u7684\u590d\u6742\u6784\u9020\uff0c\u5982\u5236\u52a8\u603b\u6cf5\u3001\u5239\u8f66\u5206\u6cf5\u3001\u771f\u7a7a\u52a9\u529b\u5668\u3001\u5239\u8f66\u76d8\u3001\u5239\u8f66\u9f13\u3001\u5239\u8f66\u7247\u6216ABS\u6cf5\u7684\u5de5\u4f5c\u539f\u7406\uff0c\u53ea\u9700\u8f7b\u8e29\u5239\u8f66\u8e0f\u677f\u5373\u53ef\u5b9e\u73b0\u5236\u52a8\u3002\u8fd9\u4fbf\u662f\u6280\u672f\u5c01\u88c5\u5e26\u6765\u7684\u597d\u5904\u3002<\/p>\n \u89d2\u8272\u7684\u4f18\u52bf\u5728\u4e8e\u5c06\u5267\u672c\u7ec4\u7ec7\u6210\u4e00\u4e2a\u7b80\u6d01\u4e14\u53ef\u91cd\u590d\u8c03\u7528\u7684\u62bd\u8c61\u5bf9\u8c61\uff0c\u4f7f\u7528\u6237\u80fd\u591f\u5c06\u6ce8\u610f\u529b\u96c6\u4e2d\u5728\u5267\u672c\u7684\u5b8f\u89c2\u8bbe\u8ba1\u4e0a\uff0c\u7edf\u7b79\u5404\u4e2a\u5173\u952e\u4efb\u52a1\u3002\u53ea\u6709\u5728\u9700\u8981\u65f6\uff0c\u624d\u9700\u6df1\u5165\u4e86\u89e3\u7ec6\u8282\u3002\u8fd9\u79cd\u7ed3\u6784\u5316\u7684\u7ec4\u7ec7\u65b9\u5f0f\u6781\u5927\u5730\u63d0\u5347\u4e86\u5267\u672c\u7684\u53ef\u7ef4\u62a4\u6027\u548c\u53ef\u6269\u5c55\u6027\u3002<\/p>\n \u83b7\u53d6\u548c\u4f7f\u7528\u89d2\u8272\u6709\u4e09\u79cd\u4e3b\u8981\u65b9\u6cd5\uff1a\u52a0\u8f7d\u7cfb\u7edf\u5185\u7f6e\u89d2\u8272\u3001\u4ece\u5916\u90e8\u73af\u5883\u83b7\u53d6\u89d2\u8272\u4ee5\u53ca\u81ea\u884c\u521b\u5efa\u89d2\u8272\u3002\u901a\u8fc7\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u7528\u6237\u53ef\u4ee5\u6839\u636e\u9700\u6c42\u7075\u6d3b\u5730\u4f7f\u7528\u89d2\u8272\u529f\u80fd\uff0c\u4ece\u800c\u5b9e\u73b0\u9ad8\u6548\u3001\u7b80\u6d01\u7684\u81ea\u52a8\u5316\u8fd0\u7ef4\u7ba1\u7406\u3002<\/p>\n<\/div>\n \u5728\u4f7f\u7528RHEL\u7cfb\u7edf\u7684\u5185\u7f6e\u89d2\u8272\u65f6\uff0c\u6211\u4eec\u4e0d\u9700\u8981\u8054\u7f51\u5c31\u80fd\u5b9e\u73b0\u3002\u7528\u6237\u53ea\u9700\u8981\u914d\u7f6e\u597d\u8f6f\u4ef6\u4ed3\u5e93\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u7136\u540e\u5b89\u88c5\u5305\u542b\u7cfb\u7edf\u89d2\u8272\u7684\u8f6f\u4ef6\u5305rhel-system-roles\uff0c\u968f\u540e\u4fbf\u53ef\u4ee5\u5728\u7cfb\u7edf\u4e2d\u627e\u5230\u5b83\u4eec\u4e86\uff0c\u7136\u540e\u5c31\u53ef\u4ee5\u4f7f\u7528\u5267\u672c\u6587\u4ef6\u8c03\u7528\u89d2\u8272\u4e86\u3002<\/p>\n \u5b89\u88c5\u5b8c\u6bd5\u540e\uff0c\u4f7f\u7528ansible-galaxy list\u547d\u4ee4\u67e5\u770bRHEL 10\u7cfb\u7edf\u4e2d\u6709\u54ea\u4e9b\u81ea\u5e26\u7684\u89d2\u8272\u53ef\u7528\uff1a<\/p>\n \u5927\u5bb6\u5343\u4e07\u4e0d\u8981\u4f4e\u4f30\u8fd9\u4e9b\u7531\u7cfb\u7edf\u955c\u50cf\u81ea\u5e26\u7684\u89d2\u8272\uff0c\u5b83\u4eec\u5728\u65e5\u5e38\u7684\u5de5\u4f5c\u4e2d\u80fd\u6d3e\u4e0a\u5927\u7528\u573a\u3002\u8fd9\u4e9b\u89d2\u8272\u7684\u4e3b\u8981\u529f\u80fd\u5982\u886816-8\u6240\u793a\u3002<\/p>\n \u886816-8\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0ansible\u7cfb\u7edf\u89d2\u8272\u63cf\u8ff0<\/p>\n \u3010\u6539\u6539\u6539\u3011<\/span><\/strong><\/p>\n <\/p>\n \u4ee5\u3010\u6539\u6539\u6539\u3011<\/span><\/strong>rhel-system-roles.timesync\u89d2\u8272\u4e3a\u4f8b\uff0c\u5b83\u7528\u4e8e\u8bbe\u7f6e\u7cfb\u7edf\u7684\u65f6\u95f4\u548cNTP\u670d\u52a1\uff0c\u8ba9\u4e3b\u673a\u80fd\u591f\u540c\u6b65\u51c6\u786e\u7684\u65f6\u95f4\u4fe1\u606f\u3002\u5267\u672c\u6a21\u677f\u6587\u4ef6\u5b58\u653e\u5728\u3010\u6539\u6539\u6539\u3011<\/span><\/strong>\/usr\/share\/doc\/rhel-system-roles\/\u76ee\u5f55\u4e2d\uff0c\u53ef\u4ee5\u590d\u5236\u8fc7\u6765\u4fee\u6539\u4f7f\u7528\uff1a<\/p>\n NTP\u670d\u52a1\u5668\u4e3b\u8981\u7528\u4e8e\u540c\u6b65\u8ba1\u7b97\u673a\u7684\u65f6\u95f4\uff0c\u63d0\u4f9b\u9ad8\u7cbe\u5ea6\u7684\u65f6\u95f4\u6821\u51c6\u670d\u52a1\uff0c\u5e2e\u52a9\u8ba1\u7b97\u673a\u6821\u5bf9\u7cfb\u7edf\u65f6\u949f\u3002\u5728\u590d\u5236\u6765\u7684\u5267\u672c\u6a21\u677f\u6587\u4ef6\u4e2d\uff0c\u5220\u9664\u6389\u591a\u4f59\u7684\u4ee3\u7801\uff0c\u5c06NTP\u670d\u52a1\u5668\u7684\u5730\u5740\u586b\u5199\u5230timesync_ntp_servers\u53d8\u91cf\u7684hostname\u5b57\u6bb5\u4e2d\u5373\u53ef\u3002\u8be5\u53d8\u91cf\u7684\u53c2\u6570\u542b\u4e49\u5982\u886816-9\u6240\u793a\u3002\u7a0d\u540etimesync\u89d2\u8272\u5c31\u4f1a\u81ea\u52a8\u4e3a\u7528\u6237\u914d\u7f6e\u53c2\u6570\u4fe1\u606f\u4e86\u3002<\/p>\n \u886816-9\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 timesync_ntp_servers\u53d8\u91cf\u53c2\u6570\u542b\u4e49<\/p>\n <\/p>\n Ansible Galaxy\u662fAnsible\u7684\u4e00\u4e2a\u5b98\u65b9\u793e\u533a\uff0c\u7528\u4e8e\u5171\u4eab\u89d2\u8272\u548c\u529f\u80fd\u4ee3\u7801\uff0c\u7528\u6237\u53ef\u4ee5\u5728\u7f51\u7ad9\u81ea\u7531\u5730\u5171\u4eab\u548c\u4e0b\u8f7dAnsible\u89d2\u8272\u3002\u8be5\u793e\u533a\u662f\u7ba1\u7406\u548c\u4f7f\u7528\u89d2\u8272\u7684\u4e0d\u4e8c\u4e4b\u9009\u3002<\/p>\n \u5728\u56fe16-4\u6240\u793a\u7684Ansible Galaxy\u5b98\u7f51\u4e2d\uff0c\u5de6\u4fa7\u6709\u3010\u6539\u6539\u6539\u3011<\/span><\/strong>3\u4e2a\u529f\u80fd\u9009\u9879\uff0c\u3010\u6539\u6539\u6539\u3011<\/span><\/strong>\u5206\u522b\u662f\u9996\u9875\uff08Home\uff09\u3001\u641c\u7d22\uff08Search\uff09\u4ee5\u53ca\u793e\u533a\uff08Community\uff09\u3002\u5355\u51fbSearch\u6309\u94ae\u8fdb\u5165\u5230\u641c\u7d22\u754c\u9762\uff0c\u8fd9\u91cc\u4ee5nginx\u670d\u52a1\u4e3a\u4f8b\u8fdb\u884c\u641c\u7d22\uff0c\u5373\u53ef\u627e\u5230Nginx\u5b98\u65b9\u53d1\u5e03\u7684\u89d2\u8272\u4fe1\u606f\uff0c\u5982\u56fe16-5\u6240\u793a\u3002<\/p>\n <\/p>\n \u56fe 16-4 Ansible Galaxy \u5b98\u7f51\u9996\u9875<\/p>\n <\/p>\n \u56fe16-5 \u641c\u7d22\u754c\u9762\u4e2d\u627e\u5230nginx\u89d2\u8272\u4fe1\u606f<\/p>\n16.1 Ansible\u4ecb\u7ecd\u4e0e\u5b89\u88c5<\/strong><\/span><\/h5>\n
\n\n
\n \u672f\u8bed<\/td>\n \u4e2d\u6587\u53eb\u6cd5<\/td>\n \u542b\u4e49<\/td>\n<\/tr>\n \n Control node<\/td>\n \u63a7\u5236\u8282\u70b9<\/td>\n \u6307\u5b89\u88c5\u4e86Ansible\u670d\u52a1\u7684\u4e3b\u673a\uff0c\u7528\u4e8e\u53d1\u5e03\u8fd0\u884c\u4efb\u52a1\u3001\u8c03\u7528\u6a21\u5757\uff0c\u5bf9\u5176\u4ed6\u4e3b\u673a\u8fdb\u884c\u6279\u91cf\u63a7\u5236\u3002<\/td>\n<\/tr>\n \n Managed nodes<\/td>\n \u53d7\u63a7\u8282\u70b9<\/td>\n \u88abAnsible\u670d\u52a1\u7ba1\u7406\u7684\u4e3b\u673a\uff0c\u662f\u6a21\u5757\u547d\u4ee4\u7684\u6267\u884c\u5bf9\u8c61\uff0c\u4e5f\u79f0\u4e3a\u53d7\u63a7\u4e3b\u673a\u6216\u5ba2\u6237\u7aef\u3002<\/td>\n<\/tr>\n \n Inventory<\/td>\n \u4e3b\u673a\u6e05\u5355<\/td>\n \u53d7\u63a7\u8282\u70b9\u7684\u5217\u8868\uff0c\u53ef\u4ee5\u662fIP\u5730\u5740\u3001\u4e3b\u673a\u540d\u79f0\u6216\u57df\u540d\u3002<\/td>\n<\/tr>\n \n Modules<\/td>\n \u6a21\u5757<\/td>\n \u6307\u7279\u5b9a\u529f\u80fd\u4ee3\u7801\uff0cAnsible\u9ed8\u8ba4\u81ea\u5e26\u4e0a\u5343\u6b3e\u529f\u80fd\u6a21\u5757\uff0c\u4e5f\u53ef\u4ee5\u5728Ansible Galaxy\u4e2d\u9009\u62e9\u5176\u4ed6\u6a21\u5757\u3002<\/td>\n<\/tr>\n \n Task<\/td>\n \u4efb\u52a1<\/td>\n Ansible\u5ba2\u6237\u7aef\u4e0a\u8981\u6267\u884c\u7684\u64cd\u4f5c\u3002<\/td>\n<\/tr>\n \n Playbook<\/td>\n \u5267\u672c<\/td>\n \u7528YAML\u8bed\u8a00\u7f16\u5199\u7684\u53ef\u91cd\u590d\u6267\u884c\u7684\u4efb\u52a1\u5217\u8868\uff0c\u5c06\u5e38\u7528\u64cd\u4f5c\u5199\u5165\u5267\u672c\u6587\u4ef6\uff0c\u4e0b\u6b21\u53ef\u76f4\u63a5\u6267\u884c\u3002<\/td>\n<\/tr>\n \n Roles<\/td>\n \u89d2\u8272<\/td>\n Ansible 1.2\u7248\u672c\u5f15\u5165\u7684\u7279\u6027\uff0c\u7528\u4e8e\u7ed3\u6784\u5316\u7ec4\u7ec7Playbook\uff0c\u901a\u8fc7\u8c03\u7528\u89d2\u8272\u5b9e\u73b0\u4e00\u8fde\u4e32\u529f\u80fd\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n [root@linuxprobe ~]# nmcli connection up ens160 \r\nConnection successfully activated (D-Bus active path: \/org\/freedesktop\/NetworkManager\/ActiveConnection\/4)\r\n[root@linuxprobe ~]# ping -c 4 lrxjmw.cn\r\nPING lrxjmw.cn.w.kunlunno.com (124.95.157.160) 56(84) bytes of data.\r\n64 bytes from lrxjmw.cn (124.95.157.160): icmp_seq=1 ttl=53 time=17.1 ms\r\n64 bytes from lrxjmw.cn (124.95.157.160): icmp_seq=2 ttl=53 time=15.6 ms\r\n64 bytes from lrxjmw.cn (124.95.157.160): icmp_seq=3 ttl=53 time=16.8 ms\r\n64 bytes from lrxjmw.cn (124.95.157.160): icmp_seq=4 ttl=53 time=17.5 ms\r\n\r\n--- lrxjmw.cn.w.kunlunno.com ping statistics ---\r\n4 packets transmitted, 4 received, 0% packet loss, time 10ms\r\nrtt min\/avg\/max\/mdev = 15.598\/16.732\/17.452\/0.708 ms\r\n<\/pre>\n
[root@linuxprobe ~]# vim \/etc\/yum.repos.d\/rhel.repo\r\n[BaseOS]\r\nname=BaseOS\r\nbaseurl=file:\/\/\/media\/cdrom\/BaseOS\r\nenabled=1\r\ngpgcheck=0\r\n\r\n[AppStream]\r\nname=AppStream\r\nbaseurl=file:\/\/\/media\/cdrom\/AppStream\r\nenabled=1\r\ngpgcheck=0\r\n\r\n[EPEL]\r\nname=EPEL\r\nbaseurl=https:\/\/dl.fedoraproject.org\/pub\/epel\/\u3010\u6539\u6539\u6539\u3011<\/span>8\/Everything\/x86_64\/\r\nenabled=1\r\ngpgcheck=0\r\n<\/strong><\/pre>\n
[root@linuxprobe ~]# dnf install -y ansible\r\nUpdating Subscription Management repositories.\r\nUnable to read consumer identity\r\nThis system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.\r\nLast metadata expiration check: 0:01:31 ago on Sun 04 Apr 2021 02:23:32 AM CST.\r\nDependencies resolved.\r\n===========================================================================================\r\n Package Arch Version Repository Size\r\n===========================================================================================\r\nInstalling:\r\n ansible noarch 2.9.18-2.el8 EPEL 17 M\r\nInstalling dependencies:\r\n python3-babel noarch 2.5.1-3.el8 AppStream 4.8 M\r\n python3-jinja2 noarch 2.10-9.el8 AppStream 537 k\r\n python3-jmespath noarch 0.9.0-11.el8 AppStream 45 k\r\n python3-markupsafe x86_64 0.23-19.el8 AppStream 39 k\r\n python3-pyasn1 noarch 0.3.7-6.el8 AppStream 126 k\r\n libsodium x86_64 1.0.18-2.el8 EPEL 162 k\r\n python3-bcrypt x86_64 3.1.6-2.el8.1 EPEL 44 k\r\n python3-pynacl x86_64 1.3.0-5.el8 EPEL 100 k\r\n sshpass x86_64 1.06-9.el8 EPEL 27 k\r\nInstalling weak dependencies:\r\n python3-paramiko noarch 2.4.3-1.el8 EPEL 289 k\r\n\r\nTransaction Summary\r\n===========================================================================================\r\nInstall 11 Packages\r\n\r\n\u2026\u2026\u2026\u2026\u2026\u2026\u7701\u7565\u90e8\u5206\u8f93\u51fa\u4fe1\u606f\u2026\u2026\u2026\u2026\u2026\u2026\r\n\r\nInstalled:\r\n ansible-2.9.18-2.el8.noarch python3-paramiko-2.4.3-1.el8.noarch\r\n python3-babel-2.5.1-3.el8.noarch python3-jinja2-2.10-9.el8.noarch\r\n python3-jmespath-0.9.0-11.el8.noarch python3-markupsafe-0.23-19.el8.x86_64\r\n python3-pyasn1-0.3.7-6.el8.noarch libsodium-1.0.18-2.el8.x86_64 \r\n python3-bcrypt-3.1.6-2.el8.1.x86_64 python3-pynacl-1.3.0-5.el8.x86_64\r\n sshpass-1.06-9.el8.x86_64 \r\n\r\nComplete!\r\n<\/pre>\n
[root@linuxprobe ~]# ansible --version\r\nansible 2.9.18\r\n config file = \/etc\/ansible\/ansible.cfg\r\n configured module search path = ['\/root\/.ansible\/plugins\/modules', '\/usr\/share\/ansible\/plugins\/modules']\r\n ansible python module location = \/usr\/lib\/python3.6\/site-packages\/ansible\r\n executable location = \/usr\/bin\/ansible\r\n python version = 3.6.8 (default, Jan 11 2019, 02:17:16) [GCC 8.2.1 20180905 (Red Hat 8.2.1-3)]\r\n<\/pre>\n
16.2 \u8bbe\u7f6e\u4e3b\u673a\u6e05\u5355<\/strong><\/span><\/h5>\n
\n\n
\n \u4f18\u5148\u7ea7<\/td>\n \u6587\u4ef6\u4f4d\u7f6e<\/td>\n<\/tr>\n \n \u9ad8<\/td>\n .\/ansible.cfg<\/td>\n<\/tr>\n \n \u4e2d<\/td>\n ~\/.ansible.cfg<\/td>\n<\/tr>\n \n \u4f4e<\/td>\n \/etc\/ansible\/ansible.cfg<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n \n\n
\n \u64cd\u4f5c\u7cfb\u7edf<\/td>\n IP\u5730\u5740<\/td>\n \u529f\u80fd\u7528\u9014<\/td>\n<\/tr>\n \n RHEL 10<\/td>\n 192.168.10.20<\/td>\n dev<\/td>\n<\/tr>\n \n RHEL 10<\/td>\n 192.168.10.21<\/td>\n test<\/td>\n<\/tr>\n \n RHEL 10<\/td>\n 192.168.10.22<\/td>\n prod<\/td>\n<\/tr>\n \n RHEL 10<\/td>\n 192.168.10.23<\/td>\n prod<\/td>\n<\/tr>\n \n RHEL 10<\/td>\n 192.168.10.24<\/td>\n balancers <\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n [root@linuxprobe ~]# vim \/etc\/ansible\/hosts\r\n192.168.10.20\r\n192.168.10.21\r\n192.168.10.22\r\n192.168.10.23\r\n192.168.10.24<\/pre>\n
[root@linuxprobe ~]# vim \/etc\/ansible\/hosts\r\n[dev]<\/strong>\r\n192.168.10.20\r\n[test]<\/strong>\r\n192.168.10.21\r\n[prod]<\/strong>\r\n192.168.10.22\r\n192.168.10.23\r\n[balancers]<\/strong>\r\n192.168.10.24<\/pre>\n
[root@linuxprobe ~]# ansible-inventory --graph\r\n@all:\r\n |--@balancers:\r\n | |--192.168.10.24\r\n |--@dev:\r\n | |--192.168.10.20\r\n |--@prod:\r\n | |--192.168.10.22\r\n | |--192.168.10.23\r\n |--@test:\r\n | |--192.168.10.21\r\n |--@ungrouped:\r\n<\/pre>\n
[root@linuxprobe ~]# ssh 192.168.10.10\r\nThe authenticity of host '192.168.10.10 (192.168.10.10)' can't be established.\r\nECDSA key fingerprint is SHA256:QRW1wrqdwN0PI2bsUvBlW5XOIpBjE+ujCB8yiCqjMQQ.\r\nAre you sure you want to continue connecting (yes\/no)? yes<\/strong>\r\nWarning: Permanently added '192.168.10.10' (ECDSA) to the list of known hosts.\r\nroot@192.168.10.10's password: \u6b64\u5904\u5e94\u8f93\u5165\u7ba1\u7406\u5458\u5bc6\u7801\u540e\u56de\u8f66\u786e\u8ba4<\/strong>\r\nActivate the web console with: systemctl enable --now cockpit.socket\r\n\r\nLast login: Mon Mar 29 06:30:15 2021\r\n[root@linuxprobe ~]# \r\n<\/pre>\n
\n\n
\n \u53c2\u6570<\/td>\n \u4f5c\u7528<\/td>\n<\/tr>\n \n ansible_ssh_host<\/td>\n \u53d7\u7ba1\u4e3b\u673a\u540d<\/td>\n<\/tr>\n \n ansible_ssh_port<\/td>\n \u7aef\u53e3\u53f7<\/td>\n<\/tr>\n \n ansible_ssh_user<\/td>\n \u9ed8\u8ba4\u8d26\u53f7<\/td>\n<\/tr>\n \n ansible_ssh_pass<\/td>\n \u9ed8\u8ba4\u5bc6\u7801<\/td>\n<\/tr>\n \n ansible_shell_type<\/td>\n Shell\u7ec8\u7aef\u7c7b\u578b<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n [root@linuxprobe ~]# vim \/etc\/ansible\/hosts\r\n[dev]\r\n192.168.10.20\r\n[test]\r\n192.168.10.21\r\n[prod]\r\n192.168.10.22\r\n192.168.10.23\r\n[balancers]\r\n192.168.10.24\r\n[all:vars]\r\nansible_user=root\r\nansible_password=redhat<\/strong><\/pre>\n
[root@linuxprobe ~]# vim \/etc\/ansible\/ansible.cfg\r\n69\r\n70 # uncomment this to disable SSH key host checking\r\n71 host_key_checking = False<\/strong>\r\n72\r\n\u2026\u2026\u2026\u2026\u2026\u2026\u7701\u7565\u90e8\u5206\u8f93\u51fa\u4fe1\u606f\u2026\u2026\u2026\u2026\u2026\u2026\r\n104\r\n105 # default user to use for playbooks if user is not specified\r\n106 # (\/usr\/bin\/ansible will use current user as default)\r\n107 remote_user = root<\/strong>\r\n108\r\n<\/pre>\n
[root@linuxprobe ~]# ifconfig\r\nens160: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500\r\n inet 192.168.10.10 netmask 255.255.255.0 broadcast 192.168.10.255\r\n inet6 fe80::d0bb:17c8:880d:e719 prefixlen 64 scopeid 0x20\r\n ether 00:0c:29:7d:27:bf txqueuelen 1000 (Ethernet)\r\n RX packets 32 bytes 5134 (5.0 KiB)\r\n RX errors 0 dropped 0 overruns 0 frame 0\r\n TX packets 43 bytes 4845 (4.7 KiB)\r\n TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0\r\n\u2026\u2026\u2026\u2026\u2026\u2026\u7701\u7565\u90e8\u5206\u8f93\u51fa\u4fe1\u606f\u2026\u2026\u2026\u2026\u2026\u2026\r\n<\/pre>\n
16.3 \u8fd0\u884c\u4e34\u65f6\u547d\u4ee4<\/strong><\/span><\/h5>\n
\n\n
\n \u6a21\u5757\u540d\u79f0<\/td>\n \u6a21\u5757\u4f5c\u7528<\/td>\n<\/tr>\n \n ping<\/td>\n \u68c0\u67e5\u53d7\u7ba1\u8282\u70b9\u4e3b\u673a\u7f51\u7edc\u662f\u5426\u80fd\u591f\u8054\u901a\u3002<\/td>\n<\/tr>\n \n yum<\/td>\n \u5b89\u88c5\u3001\u66f4\u65b0\u53ca\u5378\u8f7d\u8f6f\u4ef6\u5305\u3002<\/td>\n<\/tr>\n \n yum_repository<\/td>\n \u7ba1\u7406\u4e3b\u673a\u7684\u8f6f\u4ef6\u4ed3\u5e93\u914d\u7f6e\u6587\u4ef6\u3002<\/td>\n<\/tr>\n \n template<\/td>\n \u590d\u5236\u6a21\u677f\u6587\u4ef6\u5230\u53d7\u7ba1\u8282\u70b9\u4e3b\u673a\u3002<\/td>\n<\/tr>\n \n copy<\/td>\n \u65b0\u5efa\u3001\u4fee\u6539\u53ca\u590d\u5236\u6587\u4ef6\u3002<\/td>\n<\/tr>\n \n user<\/td>\n \u521b\u5efa\u3001\u4fee\u6539\u53ca\u5220\u9664\u7528\u6237\u3002<\/td>\n<\/tr>\n \n group<\/td>\n \u521b\u5efa\u3001\u4fee\u6539\u53ca\u5220\u9664\u7528\u6237\u7ec4\u3002<\/td>\n<\/tr>\n \n service<\/td>\n \u542f\u52a8\u3001\u5173\u95ed\u53ca\u67e5\u770b\u670d\u52a1\u72b6\u6001\u3002<\/td>\n<\/tr>\n \n get_url<\/td>\n \u4ece\u7f51\u7edc\u4e2d\u4e0b\u8f7d\u6587\u4ef6\u3002<\/td>\n<\/tr>\n \n file<\/td>\n \u8bbe\u7f6e\u6587\u4ef6\u6743\u9650\u53ca\u521b\u5efa\u5feb\u6377\u65b9\u5f0f\u3002<\/td>\n<\/tr>\n \n cron<\/td>\n \u6dfb\u52a0\u3001\u4fee\u6539\u53ca\u5220\u9664\u8ba1\u5212\u4efb\u52a1\u3002<\/td>\n<\/tr>\n \n command<\/td>\n \u76f4\u63a5\u6267\u884c\u7528\u6237\u6307\u5b9a\u7684\u547d\u4ee4\u3002<\/td>\n<\/tr>\n \n shell<\/td>\n \u76f4\u63a5\u6267\u884c\u7528\u6237\u6307\u5b9a\u7684\u547d\u4ee4\uff08\u652f\u6301\u7279\u6b8a\u5b57\u7b26\uff09\u3002<\/td>\n<\/tr>\n \n debug<\/td>\n \u8f93\u51fa\u8c03\u8bd5\u6216\u62a5\u9519\u4fe1\u606f\u3002<\/td>\n<\/tr>\n \n mount<\/td>\n \u6302\u8f7d\u786c\u76d8\u8bbe\u5907\u6587\u4ef6\u3002<\/td>\n<\/tr>\n \n filesystem<\/td>\n \u683c\u5f0f\u5316\u786c\u76d8\u8bbe\u5907\u6587\u4ef6\u3002<\/td>\n<\/tr>\n \n lineinfile<\/td>\n \u901a\u8fc7\u6b63\u5219\u8868\u8fbe\u5f0f\u4fee\u6539\u6587\u4ef6\u5185\u5bb9\u3002<\/td>\n<\/tr>\n \n setup<\/td>\n \u6536\u96c6\u53d7\u7ba1\u8282\u70b9\u4e3b\u673a\u4e0a\u7684\u7cfb\u7edf\u53ca\u53d8\u91cf\u4fe1\u606f\u3002<\/td>\n<\/tr>\n \n firewalld<\/td>\n \u6dfb\u52a0\u3001\u4fee\u6539\u53ca\u5220\u9664\u9632\u706b\u5899\u7b56\u7565\u3002<\/td>\n<\/tr>\n \n lvg<\/td>\n \u7ba1\u7406\u4e3b\u673a\u7684\u7269\u7406\u5377\u53ca\u5377\u7ec4\u8bbe\u5907\u3002<\/td>\n<\/tr>\n \n lvol<\/td>\n \u7ba1\u7406\u4e3b\u673a\u7684\u903b\u8f91\u5377\u8bbe\u5907\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n \n\n
\n \u53c2\u6570<\/td>\n \u4f5c\u7528<\/td>\n<\/tr>\n \n -k<\/td>\n \u624b\u52a8\u8f93\u5165SSH\u534f\u8bae\u5bc6\u7801<\/td>\n<\/tr>\n \n -i<\/td>\n \u6307\u5b9a\u4e3b\u673a\u6e05\u5355\u6587\u4ef6<\/td>\n<\/tr>\n \n -m<\/td>\n \u6307\u5b9a\u8981\u4f7f\u7528\u7684\u6a21\u5757\u540d<\/td>\n<\/tr>\n \n -M<\/td>\n \u6307\u5b9a\u8981\u4f7f\u7528\u7684\u6a21\u5757\u8def\u5f84<\/td>\n<\/tr>\n \n -S<\/td>\n \u4f7f\u7528su\u547d\u4ee4<\/td>\n<\/tr>\n \n -T<\/td>\n \u8bbe\u7f6eSSH\u534f\u8bae\u8fde\u63a5\u8d85\u65f6\u65f6\u95f4<\/td>\n<\/tr>\n \n -a<\/td>\n \u8bbe\u7f6e\u4f20\u9012\u7ed9\u6a21\u5757\u7684\u53c2\u6570<\/td>\n<\/tr>\n \n --version<\/td>\n \u67e5\u770b\u7248\u672c\u4fe1\u606f<\/td>\n<\/tr>\n \n -h<\/td>\n \u5e2e\u52a9\u4fe1\u606f<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n [root@linuxprobe ~]# ansible-doc -l \r\na10_server Manage A10 Networks AX\/SoftAX\/Thunder\/v...\r\na10_server_axapi3 Manage A10 Networks AX\/SoftAX\/Thunder\/v... \r\na10_service_group Manage A10 Networks AX\/SoftAX\/Thunder\/v...\r\na10_virtual_server Manage A10 Networks AX\/SoftAX\/Thunder\/v...\r\naci_aaa_user Manage AAA users (aaa:User) \r\naci_aaa_user_certificate Manage AAA user certificates (aaa:User... \r\naci_access_port_block_to_access_port Manage port blocks of Fabric interface ...\r\naci_access_port_to_interface_policy_leaf_profile Manage Fabric interface policy leaf pro...\r\naci_access_sub_port_block_to_access_port Manage sub port blocks of Fabric interf...\r\naci_aep Manage attachable Access Entity Profile...\r\naci_aep_to_domain Bind AEPs to Physical or Virtual Domain... \r\naci_bd_subnet Manage Subnets (fv:Subnet) \r\n\u2026\u2026\u2026\u2026\u2026\u2026\u7701\u7565\u90e8\u5206\u8f93\u51fa\u4fe1\u606f\u2026\u2026\u2026\u2026\u2026\u2026<\/pre>\n
[root@linuxprobe ~]# ansible-doc a10_server\r\n> A10_SERVER (\/usr\/lib\/python3.6\/site-packages\/ansible\/modules\/network\/a10\/a10_server.py)\r\n\r\n Manage SLB (Server Load Balancer) server objects on A10 Networks devices via aXAPIv2.\r\n\r\n * This module is maintained by The Ansible Community\r\n\u2026\u2026\u2026\u2026\u2026\u2026\u7701\u7565\u90e8\u5206\u8f93\u51fa\u4fe1\u606f\u2026\u2026\u2026\u2026\u2026\u2026<\/pre>\n
[root@linuxprobe ~]# ansible all -m ping\r\n192.168.10.20 | SUCCESS<\/strong> => {\r\n \"ansible_facts\": {\r\n \"discovered_interpreter_python\": \"\/usr\/libexec\/platform-python\"\r\n },\r\n \"changed\": false,\r\n \"ping\": \"pong\"\r\n}\r\n192.168.10.21 | SUCCESS<\/strong> => {\r\n \"ansible_facts\": {\r\n \"discovered_interpreter_python\": \"\/usr\/libexec\/platform-python\"\r\n },\r\n \"changed\": false,\r\n \"ping\": \"pong\"\r\n}\r\n192.168.10.22 | SUCCESS<\/strong> => {\r\n \"ansible_facts\": {\r\n \"discovered_interpreter_python\": \"\/usr\/libexec\/platform-python\"\r\n },\r\n \"changed\": false,\r\n \"ping\": \"pong\"\r\n}\r\n192.168.10.23 | SUCCESS<\/strong> => {\r\n \"ansible_facts\": {\r\n \"discovered_interpreter_python\": \"\/usr\/libexec\/platform-python\"\r\n },\r\n \"changed\": false,\r\n \"ping\": \"pong\"\r\n}192.168.10.24 | SUCCESS<\/strong> => {\r\n \"ansible_facts\": {\r\n \"discovered_interpreter_python\": \"\/usr\/libexec\/platform-python\"\r\n },\r\n \"changed\": false,\r\n \"ping\": \"pong\"\r\n}\r\n<\/pre>\n
Tips<\/strong><\/h3>\n<\/div>\n
[root@linuxprobe ~]# ansible-doc yum_repository\r\n> YUM_REPOSITORY (\/usr\/lib\/python3.6\/site-packages\/ansible\/modules\/packaging>\r\n\r\n Add or remove YUM repositories in RPM-based Linux\r\n distributions. If you wish to update an existing repository\r\n definition use [ini_file] instead.\r\n\r\n * This module is maintained by The Ansible Core Team\r\n\r\n\u2026\u2026\u2026\u2026\u2026\u2026\u7701\u7565\u90e8\u5206\u8f93\u51fa\u4fe1\u606f\u2026\u2026\u2026\u2026\u2026\u2026\r\n\r\nEXAMPLES:\r\n\r\n- name: Add repository\r\n yum_repository:\r\n name: epel\r\n description: EPEL YUM repo\r\n baseurl: https:\/\/download.fedoraproject.org\/pub\/epel\/$releasever\/$basearch\/\r\n\r\n- name: Add multiple repositories into the same file (1\/2)\r\n yum_repository:\r\n name: epel\r\n description: EPEL YUM repo\r\n file: external_repos\r\n baseurl: https:\/\/download.fedoraproject.org\/pub\/epel\/$releasever\/$basearch\/\r\n gpgcheck: no\r\n\r\n- name: Add multiple repositories into the same file (2\/2)\r\n yum_repository:\r\n name: rpmforge\r\n description: RPMforge YUM repo\r\n file: external_repos\r\n baseurl: http:\/\/apt.sw.be\/redhat\/el7\/en\/$basearch\/rpmforge\r\n<\/pre>\n
\n\n
\n \u4ed3\u5e93\u540d\u79f0<\/td>\n EX294_BASE<\/td>\n<\/tr>\n \n \u4ed3\u5e93\u63cf\u8ff0<\/td>\n EX294 base software<\/td>\n<\/tr>\n \n \u4ed3\u5e93\u5730\u5740<\/td>\n file:\/\/\/media\/cdrom\/BaseOS<\/td>\n<\/tr>\n \n GPG\u7b7e\u540d<\/td>\n \u542f\u7528<\/td>\n<\/tr>\n \n GPG\u5bc6\u94a5\u6587\u4ef6<\/td>\n file:\/\/\/media\/cdrom\/RPM-GPG-KEY-redhat-release<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n [root@linuxprobe ~]# ansible all -m yum_repository -a 'name=\"EX294_BASE<\/span><\/strong>\" description=\"EX294 base software<\/span><\/strong>\" baseurl=\"file:\/\/\/media\/cdrom\/BaseOS<\/strong><\/span>\" gpgcheck=yes <\/strong><\/span>enabled=1<\/span><\/strong> gpgkey=\"file:\/\/\/media\/cdrom\/RPM-GPG-KEY-redhat-release<\/span><\/strong>\"'\r\n\r\n192.168.10.20 | CHANGED<\/strong> => {\r\n \"ansible_facts\": {\r\n \"discovered_interpreter_python\": \"\/usr\/libexec\/platform-python\"\r\n },\r\n \"changed\": true,\r\n \"repo\": \"EX294_BASE\",\r\n \"state\": \"present\"\r\n}\r\n<\/pre>\n
[root@linuxprobe ~]# cat \/etc\/yum.repos.d\/EX294_BASE.repo \r\n[EX294_BASE]\r\nbaseurl = file:\/\/\/media\/cdrom\/BaseOS\r\nenabled = 1\r\ngpgcheck = 1\r\ngpgkey = file:\/\/\/media\/cdrom\/RPM-GPG-KEY-redhat-release\r\nname = EX294 base software\r\n<\/pre>\n
16.4 \u5267\u672c\u6587\u4ef6\u5b9e\u6218<\/strong><\/span><\/h5>\n
[root@linuxprobe ~]# ansible-doc yum\r\n> YUM (\/usr\/lib\/python3.6\/site-packages\/ansible\/modules\/packaging\/os\/yum.py)\r\n\r\n Installs, upgrade, downgrades, removes, and lists packages and\r\n groups with the `yum' package manager. This module only works\r\n on Python 2. If you require Python 3 support see the [dnf]\r\n module.\r\n\r\n * This module is maintained by The Ansible Core Team\r\n * note: This module has a corresponding action plugin.\r\n\r\n\u2026\u2026\u2026\u2026\u2026\u2026\u7701\u7565\u90e8\u5206\u8f93\u51fa\u4fe1\u606f\u2026\u2026\u2026\u2026\u2026\u2026\r\n\r\nEXAMPLES:\r\n\r\n- name: install the latest version of Apache\r\n yum:\r\n name: httpd\r\n state: latest\r\n<\/pre>\n
[root@linuxprobe ~]# vim packages.yml\r\n---\r\n- name: \u5b89\u88c5\u8f6f\u4ef6\u5305\r\n hosts: dev,test,prod\r\n tasks:\r\n - name: one\r\n yum:\r\n name: mariadb\r\n state: latest\r\n[root@linuxprobe ~]#\r\n<\/pre>\n
[root@linuxprobe ~]# vim packages.yml\r\n---\r\n- name: \u5b89\u88c5\u8f6f\u4ef6\u5305\r\n hosts: dev,test,prod\r\n tasks:\r\n - name: one\r\n yum:\r\n name: mariadb\r\n state: latest\r\n<\/pre>\n
[root@linuxprobe ~]# ansible-playbook packages.yml \r\n\r\nPLAY [\u5b89\u88c5\u8f6f\u4ef6\u5305] *******************************************************************\r\n\r\nTASK [Gathering Facts] **************************************************************\r\nok: [192.168.10.20]\r\nok: [192.168.10.21]\r\nok: [192.168.10.22]\r\nok: [192.168.10.23]\r\n\r\nTASK [one] **************************************************************************\r\nchanged: [192.168.10.20]\r\nchanged: [192.168.10.21]\r\nchanged: [192.168.10.22]\r\nchanged: [192.168.10.23]\r\n\r\nPLAY RECAP **************************************************************************\r\n192.168.10.20 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 \r\n192.168.10.21 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 \r\n192.168.10.22 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 \r\n192.168.10.23 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 \r\n<\/pre>\n
[root@linuxprobe ~]# dnf install mariadb\r\nUpdating Subscription Management repositories.\r\nUnable to read consumer identity\r\nThis system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.\r\nLast metadata expiration check: 1:05:53 ago on Thu 15 Apr 2021 08:29:11 AM CST.\r\nPackage mariadb-3:10.3.11-1.module+el8+2765+cfa4f87b.x86_64 is already installed.\r\nDependencies resolved.\r\nNothing to do.\r\nComplete!\r\n<\/pre>\n
16.5 \u521b\u5efa\u53ca\u4f7f\u7528\u89d2\u8272<\/strong><\/span><\/h5>\n
16.5.1 \u52a0\u8f7d\u7cfb\u7edf\u5185\u7f6e\u89d2\u8272<\/span><\/strong><\/h6>\n
[root@linuxprobe ~]# dnf install -y rhel-system-roles\r\nUpdating Subscription Management repositories.\r\nUnable to read consumer identity\r\nThis system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.\r\nLast metadata expiration check: 1:06:26 ago on Tue 13 Apr 2021 07:22:03 AM CST.\r\nDependencies resolved.\r\n================================================================================\r\n Package Arch Version Repository Size\r\n================================================================================\r\nInstalling:\r\n rhel-system-roles noarch 1.0-5.el8 AppStream 127 k\r\n\r\nTransaction Summary\r\n================================================================================\r\nInstall 1 Package\r\n\r\n\u2026\u2026\u2026\u2026\u2026\u2026\u7701\u7565\u90e8\u5206\u8f93\u51fa\u4fe1\u606f\u2026\u2026\u2026\u2026\u2026\u2026 \r\n\r\nInstalled:\r\n rhel-system-roles-1.0-5.el8.noarch \r\n\r\nComplete!<\/pre>\n
[root@linuxprobe ~]# ansible-galaxy list\r\n# \/usr\/share\/ansible\/roles\r\n- linux-system-roles.kdump, (unknown version)\r\n- linux-system-roles.network, (unknown version)\r\n- linux-system-roles.postfix, (unknown version)\r\n- linux-system-roles.selinux, (unknown version)\r\n- linux-system-roles.timesync, (unknown version)\r\n- rhel-system-roles.kdump, (unknown version)\r\n- rhel-system-roles.network, (unknown version)\r\n- rhel-system-roles.postfix, (unknown version)\r\n- rhel-system-roles.selinux, (unknown version)\r\n- rhel-system-roles.timesync, (unknown version)\r\n# \/etc\/ansible\/roles\r\n[WARNING]: - the configured path \/root\/.ansible\/roles does not exist.\r\n<\/pre>\n
\n\n
\n \u89d2\u8272\u540d\u79f0<\/td>\n \u4f5c\u7528<\/td>\n<\/tr>\n \n rhel-system-roles.kdump<\/td>\n \u914d\u7f6ekdump\u5d29\u6e83\u6062\u590d\u670d\u52a1<\/td>\n<\/tr>\n \n rhel-system-roles.network<\/td>\n \u914d\u7f6e\u7f51\u7edc\u63a5\u53e3<\/td>\n<\/tr>\n \n rhel-system-roles.selinux<\/td>\n \u914d\u7f6eSELinux\u7b56\u7565\u53ca\u6a21\u5f0f<\/td>\n<\/tr>\n \n rhel-system-roles.timesync<\/td>\n \u914d\u7f6e\u7f51\u7edc\u65f6\u95f4\u534f\u8bae<\/td>\n<\/tr>\n \n rhel-system-roles.postfix<\/td>\n \u914d\u7f6e\u90ae\u4ef6\u4f20\u8f93\u670d\u52a1<\/td>\n<\/tr>\n \n rhel-system-roles.firewall<\/td>\n \u914d\u7f6e\u9632\u706b\u5899\u670d\u52a1<\/td>\n<\/tr>\n \n rhel-system-roles.tuned<\/td>\n \u914d\u7f6e\u7cfb\u7edf\u8c03\u4f18\u9009\u9879<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n [root@linuxprobe ~]# cp \/usr\/share\/doc\/rhel-system-roles\/timesync\/example-timesync-playbook.yml timesync.yml\r\n<\/pre>\n
\n\n
\n \u53c2\u6570<\/td>\n \u4f5c\u7528<\/td>\n<\/tr>\n \n hostname<\/td>\n NTP\u670d\u52a1\u5668\u4e3b\u673a\u540d<\/td>\n<\/tr>\n \n iburst<\/td>\n \u542f\u7528\u5feb\u901f\u540c\u6b65<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n [root@linuxprobe ~]# vim timesync.yml \r\n---\r\n- hosts: all\r\n vars:\r\n timesync_ntp_servers:\r\n - hostname: pool.ntp.org\r\n iburst: yes\r\n roles:\r\n - rhel-system-roles.timesync<\/pre>\n
16.5.2 \u4ece\u5916\u90e8\u83b7\u53d6\u89d2\u8272<\/strong><\/span><\/h6>\n