{"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

16.1 Ansible\u4ecb\u7ecd\u4e0e\u5b89\u88c5<\/strong><\/span><\/h5>\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

\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\n\n\n\n\n\n\n\n\n\n
\u672f\u8bed<\/td>\n\u4e2d\u6587\u53eb\u6cd5<\/td>\n\u542b\u4e49<\/td>\n<\/tr>\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
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
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
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
Task<\/td>\n\u4efb\u52a1<\/td>\nAnsible\u5ba2\u6237\u7aef\u4e0a\u8981\u6267\u884c\u7684\u64cd\u4f5c\u3002<\/td>\n<\/tr>\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
Roles<\/td>\n\u89d2\u8272<\/td>\nAnsible 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

<\/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

[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

\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

[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

\u7b2c3\u6b65\uff1a<\/strong>\u5b89\u88c5\uff01<\/p>\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

\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

[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

\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\n\n\n\n\n\n
\u4f18\u5148\u7ea7<\/td>\n\u6587\u4ef6\u4f4d\u7f6e<\/td>\n<\/tr>\n
\u9ad8<\/td>\n.\/ansible.cfg<\/td>\n<\/tr>\n
\u4e2d<\/td>\n~\/.ansible.cfg<\/td>\n<\/tr>\n
\u4f4e<\/td>\n\/etc\/ansible\/ansible.cfg<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\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\n\n\n\n\n\n\n\n
\u64cd\u4f5c\u7cfb\u7edf<\/td>\nIP\u5730\u5740<\/td>\n\u529f\u80fd\u7528\u9014<\/td>\n<\/tr>\n
RHEL 10<\/td>\n192.168.10.20<\/td>\ndev<\/td>\n<\/tr>\n
RHEL 10<\/td>\n192.168.10.21<\/td>\ntest<\/td>\n<\/tr>\n
RHEL 10<\/td>\n192.168.10.22<\/td>\nprod<\/td>\n<\/tr>\n
RHEL 10<\/td>\n192.168.10.23<\/td>\nprod<\/td>\n<\/tr>\n
RHEL 10<\/td>\n192.168.10.24<\/td>\nbalancers <\/td>\n<\/tr>\n<\/tbody>\n<\/table>\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

[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

\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

[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

\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

[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

\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

[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

\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\n\n\n\n\n\n\n\n
\u53c2\u6570<\/td>\n\u4f5c\u7528<\/td>\n<\/tr>\n
ansible_ssh_host<\/td>\n\u53d7\u7ba1\u4e3b\u673a\u540d<\/td>\n<\/tr>\n
ansible_ssh_port<\/td>\n\u7aef\u53e3\u53f7<\/td>\n<\/tr>\n
ansible_ssh_user<\/td>\n\u9ed8\u8ba4\u8d26\u53f7<\/td>\n<\/tr>\n
ansible_ssh_pass<\/td>\n\u9ed8\u8ba4\u5bc6\u7801<\/td>\n<\/tr>\n
ansible_shell_type<\/td>\nShell\u7ec8\u7aef\u7c7b\u578b<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\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

[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

\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

[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

\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

[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

\"\"<\/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

16.3 \u8fd0\u884c\u4e34\u65f6\u547d\u4ee4<\/strong><\/span><\/h5>\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\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
\u6a21\u5757\u540d\u79f0<\/td>\n\u6a21\u5757\u4f5c\u7528<\/td>\n<\/tr>\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
yum<\/td>\n\u5b89\u88c5\u3001\u66f4\u65b0\u53ca\u5378\u8f7d\u8f6f\u4ef6\u5305\u3002<\/td>\n<\/tr>\n
yum_repository<\/td>\n\u7ba1\u7406\u4e3b\u673a\u7684\u8f6f\u4ef6\u4ed3\u5e93\u914d\u7f6e\u6587\u4ef6\u3002<\/td>\n<\/tr>\n
template<\/td>\n\u590d\u5236\u6a21\u677f\u6587\u4ef6\u5230\u53d7\u7ba1\u8282\u70b9\u4e3b\u673a\u3002<\/td>\n<\/tr>\n
copy<\/td>\n\u65b0\u5efa\u3001\u4fee\u6539\u53ca\u590d\u5236\u6587\u4ef6\u3002<\/td>\n<\/tr>\n
user<\/td>\n\u521b\u5efa\u3001\u4fee\u6539\u53ca\u5220\u9664\u7528\u6237\u3002<\/td>\n<\/tr>\n
group<\/td>\n\u521b\u5efa\u3001\u4fee\u6539\u53ca\u5220\u9664\u7528\u6237\u7ec4\u3002<\/td>\n<\/tr>\n
service<\/td>\n\u542f\u52a8\u3001\u5173\u95ed\u53ca\u67e5\u770b\u670d\u52a1\u72b6\u6001\u3002<\/td>\n<\/tr>\n
get_url<\/td>\n\u4ece\u7f51\u7edc\u4e2d\u4e0b\u8f7d\u6587\u4ef6\u3002<\/td>\n<\/tr>\n
file<\/td>\n\u8bbe\u7f6e\u6587\u4ef6\u6743\u9650\u53ca\u521b\u5efa\u5feb\u6377\u65b9\u5f0f\u3002<\/td>\n<\/tr>\n
cron<\/td>\n\u6dfb\u52a0\u3001\u4fee\u6539\u53ca\u5220\u9664\u8ba1\u5212\u4efb\u52a1\u3002<\/td>\n<\/tr>\n
command<\/td>\n\u76f4\u63a5\u6267\u884c\u7528\u6237\u6307\u5b9a\u7684\u547d\u4ee4\u3002<\/td>\n<\/tr>\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
debug<\/td>\n\u8f93\u51fa\u8c03\u8bd5\u6216\u62a5\u9519\u4fe1\u606f\u3002<\/td>\n<\/tr>\n
mount<\/td>\n\u6302\u8f7d\u786c\u76d8\u8bbe\u5907\u6587\u4ef6\u3002<\/td>\n<\/tr>\n
filesystem<\/td>\n\u683c\u5f0f\u5316\u786c\u76d8\u8bbe\u5907\u6587\u4ef6\u3002<\/td>\n<\/tr>\n
lineinfile<\/td>\n\u901a\u8fc7\u6b63\u5219\u8868\u8fbe\u5f0f\u4fee\u6539\u6587\u4ef6\u5185\u5bb9\u3002<\/td>\n<\/tr>\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
firewalld<\/td>\n\u6dfb\u52a0\u3001\u4fee\u6539\u53ca\u5220\u9664\u9632\u706b\u5899\u7b56\u7565\u3002<\/td>\n<\/tr>\n
lvg<\/td>\n\u7ba1\u7406\u4e3b\u673a\u7684\u7269\u7406\u5377\u53ca\u5377\u7ec4\u8bbe\u5907\u3002<\/td>\n<\/tr>\n
lvol<\/td>\n\u7ba1\u7406\u4e3b\u673a\u7684\u903b\u8f91\u5377\u8bbe\u5907\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\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\n\n\n\n\n\n\n\n\n\n\n\n
\u53c2\u6570<\/td>\n\u4f5c\u7528<\/td>\n<\/tr>\n
-k<\/td>\n\u624b\u52a8\u8f93\u5165SSH\u534f\u8bae\u5bc6\u7801<\/td>\n<\/tr>\n
-i<\/td>\n\u6307\u5b9a\u4e3b\u673a\u6e05\u5355\u6587\u4ef6<\/td>\n<\/tr>\n
-m<\/td>\n\u6307\u5b9a\u8981\u4f7f\u7528\u7684\u6a21\u5757\u540d<\/td>\n<\/tr>\n
-M<\/td>\n\u6307\u5b9a\u8981\u4f7f\u7528\u7684\u6a21\u5757\u8def\u5f84<\/td>\n<\/tr>\n
-S<\/td>\n\u4f7f\u7528su\u547d\u4ee4<\/td>\n<\/tr>\n
-T<\/td>\n\u8bbe\u7f6eSSH\u534f\u8bae\u8fde\u63a5\u8d85\u65f6\u65f6\u95f4<\/td>\n<\/tr>\n
-a<\/td>\n\u8bbe\u7f6e\u4f20\u9012\u7ed9\u6a21\u5757\u7684\u53c2\u6570<\/td>\n<\/tr>\n
--version<\/td>\n\u67e5\u770b\u7248\u672c\u4fe1\u606f<\/td>\n<\/tr>\n
-h<\/td>\n\u5e2e\u52a9\u4fe1\u606f<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\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

[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

\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

[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

\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

[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
\n
\n

Tips<\/strong><\/h3>\n<\/div>\n
\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

[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

\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\n\n\n\n\n\n\n
\u4ed3\u5e93\u540d\u79f0<\/td>\nEX294_BASE<\/td>\n<\/tr>\n
\u4ed3\u5e93\u63cf\u8ff0<\/td>\nEX294 base software<\/td>\n<\/tr>\n
\u4ed3\u5e93\u5730\u5740<\/td>\nfile:\/\/\/media\/cdrom\/BaseOS<\/td>\n<\/tr>\n
GPG\u7b7e\u540d<\/td>\n\u542f\u7528<\/td>\n<\/tr>\n
GPG\u5bc6\u94a5\u6587\u4ef6<\/td>\nfile:\/\/\/media\/cdrom\/RPM-GPG-KEY-redhat-release<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\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

[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

\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

[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

\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

[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

\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

[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

\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

[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

\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

[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

\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

[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

\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

\n
16.5.1 \u52a0\u8f7d\u7cfb\u7edf\u5185\u7f6e\u89d2\u8272<\/span><\/strong><\/h6>\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

[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

\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

[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

\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\n\n\n\n\n\n\n\n\n\n
\u89d2\u8272\u540d\u79f0<\/td>\n\u4f5c\u7528<\/td>\n<\/tr>\n
rhel-system-roles.kdump<\/td>\n\u914d\u7f6ekdump\u5d29\u6e83\u6062\u590d\u670d\u52a1<\/td>\n<\/tr>\n
rhel-system-roles.network<\/td>\n\u914d\u7f6e\u7f51\u7edc\u63a5\u53e3<\/td>\n<\/tr>\n
rhel-system-roles.selinux<\/td>\n\u914d\u7f6eSELinux\u7b56\u7565\u53ca\u6a21\u5f0f<\/td>\n<\/tr>\n
rhel-system-roles.timesync<\/td>\n\u914d\u7f6e\u7f51\u7edc\u65f6\u95f4\u534f\u8bae<\/td>\n<\/tr>\n
rhel-system-roles.postfix<\/td>\n\u914d\u7f6e\u90ae\u4ef6\u4f20\u8f93\u670d\u52a1<\/td>\n<\/tr>\n
rhel-system-roles.firewall<\/td>\n\u914d\u7f6e\u9632\u706b\u5899\u670d\u52a1<\/td>\n<\/tr>\n
rhel-system-roles.tuned<\/td>\n\u914d\u7f6e\u7cfb\u7edf\u8c03\u4f18\u9009\u9879<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\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

[root@linuxprobe ~]# cp \/usr\/share\/doc\/rhel-system-roles\/timesync\/example-timesync-playbook.yml timesync.yml\r\n<\/pre>\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\n\n\n\n\n
\u53c2\u6570<\/td>\n\u4f5c\u7528<\/td>\n<\/tr>\n
hostname<\/td>\nNTP\u670d\u52a1\u5668\u4e3b\u673a\u540d<\/td>\n<\/tr>\n
iburst<\/td>\n\u542f\u7528\u5feb\u901f\u540c\u6b65<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

<\/p>\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

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>\n

\n
\n

Tips<\/strong><\/h3>\n<\/div>\n
\n

Ansible Galaxy \u5b98\u7f51\u9996\u9875\uff1ahttps:\/\/galaxy.ansible.com<\/a><\/p>\n<\/div>\n<\/div>\n

\u5f53\u5355\u51fbnginx\u89d2\u8272\u8fdb\u5165\u5230\u8be6\u60c5\u9875\u9762\u540e\uff0c\u4f1a\u663e\u793a\u8fd9\u4e2a\u9879\u76ee\u7684\u8f6f\u4ef6\u7248\u672c\u3001\u8bc4\u5206\u3001\u4e0b\u8f7d\u6b21\u6570\u7b49\u4fe1\u606f\u3002\u5728Installation\u5b57\u6bb5\u80fd\u770b\u5230\u76f8\u5e94\u7684\u5b89\u88c5\u65b9\u5f0f\uff0c\u5982\u56fe16-6\u6240\u793a\u3002\u5728\u4fdd\u6301\u865a\u62df\u673a\u6b63\u5e38\u8fde\u63a5\u5916\u7f51\u7684\u524d\u63d0\u4e0b\uff0c\u53ef\u4ee5\u6309\u8fd9\u4e2a\u9875\u9762\u63d0\u793a\u7684\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\u3002<\/p>\n

\u8fd9\u65f6\uff0c\u5982\u679c\u9700\u8981\u4f7f\u7528\u8fd9\u4e2a\u89d2\u8272\uff0c\u53ef\u4ee5\u5728\u865a\u62df\u673a\u8054\u7f51\u7684\u72b6\u6001\u4e0b\u76f4\u63a5\u6309\u7167\u201cansible-galaxy install \u89d2\u8272\u540d\u79f0\u201d\u7684\u547d\u4ee4\u683c\u5f0f\u81ea\u52a8\u83b7\u53d6\uff1a<\/p>\n

\"\"<\/p>\n

\u56fe16-6 nginx\u89d2\u8272\u8be6\u60c5\u9875<\/p>\n

[root@linuxprobe ~]# ansible-galaxy install nginxinc.nginx\r\n- downloading role 'nginx', owned by nginxinc\r\n- downloading role from https:\/\/github.com\/nginxinc\/ansible-role-nginx\/archive\/0.19.1.tar.gz\r\n- extracting nginxinc.nginx to \/etc\/ansible\/roles\/nginxinc.nginx\r\n- nginxinc.nginx (0.19.1) was installed successfully\r\n<\/pre>\n

\u6267\u884c\u5b8c\u6bd5\u540e\uff0c\u518d\u6b21\u67e5\u770b\u7cfb\u7edf\u4e2d\u5df2\u6709\u7684\u89d2\u8272\uff0c\u4fbf\u53ef\u627e\u5230nginx\u89d2\u8272\u4fe1\u606f\u4e86\uff1a<\/p>\n

[root@linuxprobe ~]# ansible-galaxy list\r\n# \/etc\/ansible\/roles\r\n- nginxinc.nginx, 0.19.1<\/strong>\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<\/pre>\n

\u8fd9\u91cc\u8fd8\u5b58\u5728\u4e24\u79cd\u7279\u6b8a\u60c5\u51b5\u3002<\/p>\n

\u5728\u56fd\u5185\u8bbf\u95eeAnsible Galaxy\u5b98\u7f51\u65f6\u53ef\u80fd\u5b58\u5728\u4e0d\u7a33\u5b9a\u7684\u60c5\u51b5\uff0c\u5bfc\u81f4\u8bbf\u95ee\u4e0d\u4e86\u6216\u8005\u7f51\u901f\u8f83\u6162\u3002<\/p>\n

\u67d0\u4f4d\u4f5c\u8005\u662f\u5c06\u4f5c\u54c1\u4e0a\u4f20\u5230\u4e86\u81ea\u5df1\u7684\u7f51\u7ad9\uff0c\u6216\u8005\u9664Ansible Galaxy\u5b98\u7f51\u4ee5\u5916\u7684\u5176\u4ed6\u5e73\u53f0\u3002<\/p><\/blockquote>\n

\u5728\u8fd9\u4e24\u79cd\u60c5\u51b5\u4e0b\uff0c\u5c31\u4e0d\u80fd\u518d\u7528\u201cansible-galaxy install\u89d2\u8272\u540d\u79f0\u201d\u7684\u547d\u4ee4\u76f4\u63a5\u52a0\u8f7d\u4e86\uff0c\u800c\u662f\u9700\u8981\u624b\u52a8\u5148\u7f16\u5199\u4e00\u4e2aYAML\u8bed\u8a00\u683c\u5f0f\u7684\u6587\u4ef6\uff0c\u6307\u660e\u7f51\u5740\u94fe\u63a5\u548c\u89d2\u8272\u540d\u79f0\uff0c\u7136\u540e\u518d\u7528-r\u53c2\u6570\u8fdb\u884c\u52a0\u8f7d\u3002<\/p>\n

\u4f8b\u5982\uff0c\u5218\u9044\u8001\u5e08\u5728\u672c\u4e66\u7684\u914d\u5957\u7f51\u7ad9\uff08lrxjmw.cn\uff09\u4e0a\u4f20\u4e86\u4e00\u4e2a\u540d\u4e3anginx_core\u7684\u89d2\u8272\u8f6f\u4ef6\u5305\uff08\u4e00\u4e2a\u7528\u4e8e\u5bf9nginx\u7f51\u7ad9\u8fdb\u884c\u4fdd\u62a4\u7684\u63d2\u4ef6\uff09\u3002\u8fd9\u65f6\u9700\u8981\u7f16\u5199\u5982\u4e0b\u6240\u793a\u7684\u4e00\u4e2ayml\u914d\u7f6e\u6587\u4ef6\uff1a<\/p>\n

[root@linuxprobe ~]# cat nginx.yml\r\n---\r\n- src: https:\/\/lrxjmw.cn\/Software\/nginxinc-nginx_core-0.3.0.tar.gz\r\n  name: nginx-core\r\n<\/pre>\n

\u968f\u540e\u4f7f\u7528ansible-galaxy\u547d\u4ee4\u7684-r\u53c2\u6570\u52a0\u8f7d\u8fd9\u4e2a\u6587\u4ef6\uff0c\u5373\u53ef\u67e5\u770b\u5230\u65b0\u89d2\u8272\u4fe1\u606f\u4e86\uff1a<\/p>\n

[root@linuxprobe ~]# ansible-galaxy install -r nginx.yml\r\n- downloading role from https:\/\/lrxjmw.cn\/nginxinc-nginx_core-0.3.0.tar.gz\r\n- extracting nginx to \/etc\/ansible\/roles\/nginx\r\n- nginx was installed successfully\r\n[root@linuxprobe ~]# ansible-galaxy list\r\n# \/etc\/ansible\/roles\r\n- nginx-core, (unknown version)<\/strong>\r\n- nginxinc.nginx, 0.19.1\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)<\/pre>\n
16.5.3 \u521b\u5efa\u65b0\u7684\u89d2\u8272<\/span><\/strong><\/h6>\n

\u9664\u4e86\u4f7f\u7528\u7cfb\u7edf\u81ea\u5e26\u7684\u89d2\u8272\u548c\u4eceAnsible Galaxy\u83b7\u53d6\u7684\u89d2\u8272\u5916\uff0c\u7528\u6237\u8fd8\u53ef\u4ee5\u6839\u636e\u5b9e\u9645\u5de5\u4f5c\u9700\u6c42\uff0c\u81ea\u884c\u521b\u5efa\u7b26\u5408\u751f\u4ea7\u73af\u5883\u7684\u5b9a\u5236\u5316\u89d2\u8272\u3002\u867d\u7136\u8fd9\u79cd\u5b9a\u5236\u5316\u7f16\u5199\u7684\u5de5\u4f5c\u80fd\u591f\u66f4\u597d\u5730\u8d34\u5408\u5b9e\u9645\u9700\u6c42\uff0c\u4f46\u96be\u5ea6\u4e5f\u76f8\u5bf9\u8f83\u9ad8\uff0c\u9700\u8981\u5177\u5907\u4e00\u5b9a\u7684Ansible\u77e5\u8bc6\u548c\u5b9e\u8df5\u7ecf\u9a8c\u3002<\/p>\n

\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u521b\u5efa\u4e00\u4e2a\u540d\u4e3aapache\u7684\u65b0\u89d2\u8272\uff0c\u8be5\u89d2\u8272\u5c06\u81ea\u52a8\u5b89\u88c5\u548c\u914d\u7f6ehttpd\u7f51\u7ad9\u670d\u52a1\uff0c\u8bbe\u7f6e\u9632\u706b\u5899\u89c4\u5219\uff0c\u5e76\u6839\u636e\u6bcf\u53f0\u4e3b\u673a\u751f\u6210\u72ec\u7acb\u7684index.html\u9996\u9875\u6587\u4ef6\u3002\u901a\u8fc7\u8c03\u7528\u8fd9\u4e2a\u89d2\u8272\uff0c\u8ba9\u7528\u6237\u4eab\u53d7\u5230\u201c\u4e00\u6761\u9f99\u201d\u5f0f\u7684\u7f51\u7ad9\u90e8\u7f72\u670d\u52a1\uff0c\u6781\u5927\u5730\u7b80\u5316\u4e86\u8fd0\u7ef4\u5de5\u4f5c\u3002<\/p>\n

\u5728Ansible\u7684\u4e3b\u914d\u7f6e\u6587\u4ef6\u4e2d\uff0c\u3010\u6539\u6539\u6539\u3011<\/span><\/strong>\u7b2c68\u884c\u5b9a\u4e49\u4e86\u89d2\u8272\u7684\u4fdd\u5b58\u8def\u5f84\u3002\u5982\u679c\u7528\u6237\u521b\u5efa\u7684\u65b0\u89d2\u8272\u4e0d\u5728\u8fd9\u4e2a\u6307\u5b9a\u76ee\u5f55\u5185\uff0c\u5219\u65e0\u6cd5\u901a\u8fc7ansible-galaxy list\u547d\u4ee4\u627e\u5230\u8be5\u89d2\u8272\u3002\u56e0\u6b64\uff0c\u7528\u6237\u9700\u8981\u624b\u52a8\u586b\u5199\u65b0\u89d2\u8272\u7684\u76ee\u5f55\u8def\u5f84\uff0c\u6216\u662f\u5728\u8fdb\u5165\/etc\/ansible\/roles\u76ee\u5f55\u540e\u518d\u8fdb\u884c\u89d2\u8272\u521b\u5efa\u3002\u4e3a\u4e86\u907f\u514d\u89d2\u8272\u4fe1\u606f\u8fc7\u4e8e\u5206\u6563\uff0c\u5bfc\u81f4\u7ba1\u7406\u4e0a\u7684\u56f0\u96be\uff0c\u5efa\u8bae\u5728\u9ed8\u8ba4\u76ee\u5f55\u4e0b\u521b\u5efa\u89d2\u8272\uff0c\u4ee5\u4fbf\u540e\u671f\u7684\u7edf\u4e00\u7ba1\u7406\u3002<\/p>\n

[root@linuxprobe roles]# vim \/etc\/ansible\/ansible.cfg\r\n 66 \r\n 67 # additional paths to search for roles in, colon separated\r\n 68 #roles_path    = \/etc\/ansible\/roles\r\n 69 \r\n<\/pre>\n

\u5728ansible-galaxy\u547d\u4ee4\u540e\u9762\u8ddf\u4e00\u4e2ainit\u53c2\u6570\uff0c\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u89d2\u8272\u4fe1\u606f\uff0c\u4e14\u5efa\u7acb\u6210\u529f\u540e\u4fbf\u4f1a\u5728\u5f53\u524d\u76ee\u5f55\u4e0b\u751f\u6210\u51fa\u4e00\u4e2a\u65b0\u7684\u76ee\u5f55\uff1a<\/p>\n

[root@linuxprobe ~]# cd \/etc\/ansible\/roles\r\n[root@linuxprobe roles]# ansible-galaxy init apache\r\n- Role apache was created successfully\r\n[root@linuxprobe roles]# ls\r\napache<\/strong> nginx nginxinc.nginx<\/pre>\n

\u6b64\u65f6\u7684apache\u5373\u662f\u89d2\u8272\u540d\u79f0\uff0c\u4e5f\u662f\u7528\u4e8e\u5b58\u5728\u89d2\u8272\u4fe1\u606f\u7684\u76ee\u5f55\u540d\u79f0\u3002\u5207\u6362\u5230\u8be5\u76ee\u5f55\u4e0b\uff0c\u67e5\u770b\u5b83\u7684\u7ed3\u6784\uff1a<\/p>\n

[root@linuxprobe roles]# cd apache\r\n[root@linuxprobe apache]# ls\r\ndefaults  files  handlers  meta  README.md  tasks  templates  tests  vars\r\n<\/pre>\n

\u5728\u521b\u5efa\u65b0\u89d2\u8272\u65f6\uff0c\u6700\u5173\u952e\u7684\u4fbf\u662f\u8981\u6b63\u786e\u7406\u89e3\u76ee\u5f55\u7ed3\u6784\u3002\u901a\u4fd7\u6765\u8bf4\uff0c\u5c31\u662f\u8981\u628a\u6b63\u786e\u7684\u4fe1\u606f\u653e\u5165\u6b63\u786e\u7684\u76ee\u5f55\u4e2d\uff0c\u8fd9\u6837\u5728\u8c03\u7528\u89d2\u8272\u65f6\u624d\u80fd\u6709\u6b63\u786e\u7684\u6548\u679c\u3002\u89d2\u8272\u4fe1\u606f\u5bf9\u5e94\u7684\u76ee\u5f55\u7ed3\u6784\u53ca\u542b\u4e49\u5982\u886816-10\u6240\u793a\u3002<\/p>\n

\u886816-10\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 Ansible\u89d2\u8272\u76ee\u5f55\u7ed3\u6784\u53ca\u542b\u4e49<\/p>\n\n\n\n\n\n\n\n\n\n\n\n
\u76ee\u5f55<\/td>\n\u542b\u4e49<\/td>\n<\/tr>\n
defaults <\/td>\n\u5305\u542b\u89d2\u8272\u53d8\u91cf\u7684\u9ed8\u8ba4\u503c\uff08\u4f18\u5148\u7ea7\u4f4e\uff09\u3002<\/td>\n<\/tr>\n
files<\/td>\n\u5305\u542b\u89d2\u8272\u6267\u884ctasks\u4efb\u52a1\u65f6\u505a\u5f15\u7528\u7684\u9759\u6001\u6587\u4ef6\u3002<\/td>\n<\/tr>\n
handlers<\/td>\n\u5305\u542b\u89d2\u8272\u7684\u5904\u7406\u7a0b\u5e8f\u5b9a\u4e49\u3002<\/td>\n<\/tr>\n
meta<\/td>\n\u5305\u542b\u89d2\u8272\u7684\u4f5c\u8005\u3001\u8bb8\u53ef\u8bc1\u3001\u9891\u53f0\u548c\u4f9d\u8d56\u5173\u7cfb\u7b49\u4fe1\u606f\u3002<\/td>\n<\/tr>\n
tasks<\/td>\n\u5305\u542b\u89d2\u8272\u6240\u6267\u884c\u7684\u4efb\u52a1\u3002<\/td>\n<\/tr>\n
templates<\/td>\n\u5305\u542b\u89d2\u8272\u4efb\u52a1\u6240\u4f7f\u7528\u7684Jinja2\u6a21\u677f\u3002<\/td>\n<\/tr>\n
tests <\/td>\n\u5305\u542b\u7528\u4e8e\u6d4b\u8bd5\u89d2\u8272\u7684\u5267\u672c\u6587\u4ef6\u3002<\/td>\n<\/tr>\n
vars<\/td>\n\u5305\u542b\u89d2\u8272\u53d8\u91cf\u7684\u9ed8\u8ba4\u503c\uff08\u4f18\u5148\u7ea7\u9ad8\uff09\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

<\/p>\n

\u4e0b\u9762\u51c6\u5907\u521b\u5efa\u65b0\u89d2\u8272\u3002<\/p>\n

\u7b2c1\u6b65<\/strong>\uff1a\u6253\u5f00\u7528\u4e8e\u5b9a\u4e49\u89d2\u8272\u4efb\u52a1\u7684tasks\/main.yml\u6587\u4ef6\u3002\u5728\u8be5\u6587\u4ef6\u4e2d\u4e0d\u9700\u8981\u5b9a\u4e49\u8981\u6267\u884c\u7684\u4e3b\u673a\u7ec4\u5217\u8868\uff0c\u56e0\u4e3a\u540e\u9762\u4f1a\u5355\u72ec\u7f16\u5199\u5267\u672c\u8fdb\u884c\u8c03\u7528\uff0c\u6b64\u65f6\u5e94\u5148\u5bf9apache\u89d2\u8272\u80fd\u505a\u7684\u4e8b\u60c5\uff08\u4efb\u52a1\uff09\u6709\u4e00\u4e2a\u660e\u786e\u7684\u601d\u8def\uff0c\u5728\u8c03\u7528\u89d2\u8272\u540eyml\u6587\u4ef6\u4f1a\u6309\u7167\u4ece\u4e0a\u5230\u4e0b\u7684\u987a\u5e8f\u81ea\u52a8\u6267\u884c\u3002<\/p>\n

\u4efb\u52a11<\/strong>\uff1a\u5b89\u88c5httpd\u7f51\u7ad9\u670d\u52a1\u3002<\/p>\n

\u4efb\u52a12<\/strong>\uff1a\u8fd0\u884chttpd\u7f51\u7ad9\u670d\u52a1\uff0c\u5e76\u52a0\u5165\u5230\u5f00\u673a\u542f\u52a8\u9879\u4e2d\u3002<\/p>\n

\u4efb\u52a13<\/strong>\uff1a\u914d\u7f6e\u9632\u706b\u5899\uff0c\u4f7f\u5176\u653e\u884cHTTP\u534f\u8bae\u3002<\/p>\n

\u4efb\u52a14<\/strong>\uff1a\u6839\u636e\u6bcf\u53f0\u4e3b\u673a\u7684\u53d8\u91cf\u503c\uff0c\u751f\u6210\u4e0d\u540c\u7684\u4e3b\u9875\u6587\u4ef6\u3002<\/p><\/blockquote>\n

\u5148\u5199\u51fa\u7b2c\u4e00\u4e2a\u4efb\u52a1\u3002\u4f7f\u7528yum\u6a21\u5757\u5b89\u88c5httpd\u7f51\u7ad9\u670d\u52a1\u7a0b\u5e8f\uff08\u6ce8\u610f\u683c\u5f0f\uff09\uff1a<\/p>\n<\/div>\n

\n
[root@linuxprobe apache]# vim tasks\/main.yml\r\n---\r\n- name: one\r\n  yum:\r\n          name: httpd\r\n          state: latest\r\n<\/pre>\n

\u7b2c2\u6b65\uff1a\u4f7f\u7528service\u6a21\u5757\u542f\u52a8httpd\u7f51\u7ad9\u670d\u52a1\u7a0b\u5e8f\uff0c\u5e76\u52a0\u5165\u5230\u542f\u52a8\u9879\u4e2d\uff0c\u8ba9\u5176\u80fd\u591f\u4e00\u76f4\u4e3a\u7528\u6237\u63d0\u4f9b\u670d\u52a1\u3002\u5728\u521d\u6b21\u4f7f\u7528\u6a21\u5757\u524d\uff0c\u5148\u7528ansible-doc\u547d\u4ee4\u67e5\u770b\u4e00\u4e0b\u5e2e\u52a9\u548c\u5b9e\u4f8b\u4fe1\u606f\u3002\u7531\u4e8e\u7bc7\u5e45\u7684\u9650\u5236\uff0c\u8fd9\u91cc\u5bf9\u4fe1\u606f\u8fdb\u884c\u4e86\u5220\u51cf\uff0c\u4ec5\u4fdd\u7559\u4e86\u6709\u7528\u7684\u5185\u5bb9\u3002<\/p>\n

[root@linuxprobe apache]# ansible-doc service\r\n> SERVICE    (\/usr\/lib\/python3.6\/site-packages\/ansible\/modules\/system\/service.py)\r\n\r\n        Controls services on remote hosts. Supported init systems\r\n        include BSD init, OpenRC, SysV, Solaris SMF, systemd, upstart.\r\n        For Windows targets, use the [win_service] module instead.\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: Start service httpd, if not started\r\n  service:\r\n    name: httpd\r\n    state: started\r\n\r\n- name: Enable service httpd, and not touch the state\r\n  service:\r\n    name: httpd\r\n    enabled: yes<\/pre>\n

\u771f\u5e78\u8fd0\uff0c\u9ed8\u8ba4\u7684EXAMPLES\u793a\u4f8b\u4f7f\u7528\u7684\u5c31\u662fhttpd\u7f51\u7ad9\u670d\u52a1\u3002\u901a\u8fc7\u8f93\u51fa\u4fe1\u606f\u53ef\u5f97\u77e5\uff0c\u542f\u52a8\u670d\u52a1\u4e3a\u201cstate: started\u201d\u53c2\u6570\uff0c\u800c\u52a0\u5165\u5230\u5f00\u673a\u542f\u52a8\u9879\u5219\u662f\u201cenabled: yes\u201d\u53c2\u6570\u3002\u7ee7\u7eed\u7f16\u5199\uff1a<\/p>\n

[root@linuxprobe apache]# vim tasks\/main.yml\r\n---\r\n- name: one\r\n  yum:\r\n          name: httpd\r\n          state: latest\r\n- name: two\r\n  service:\r\n          name: httpd\r\n          state: started\r\n          enabled: yes<\/strong><\/pre>\n

\u7b2c3\u6b65\uff1a\u914d\u7f6e\u9632\u706b\u5899\u7684\u5141\u8bb8\u7b56\u7565\uff0c\u8ba9\u5176\u4ed6\u4e3b\u673a\u80fd\u6b63\u5e38\u8bbf\u95ee\u3002\u5728\u914d\u7f6e\u9632\u706b\u5899\u65f6\uff0c\u9700\u8981\u4f7f\u7528firewalld\u6a21\u5757\u3002\u540c\u6837\u4e5f\u662f\u5148\u770b\u4e00\u4e0b\u5e2e\u52a9\u793a\u4f8b\uff1a<\/p>\n

[root@linuxprobe defaults]# ansible-doc firewalld\r\n> FIREWALLD    (\/usr\/lib\/python3.6\/site-packages\/ansible\/modules\/system\/firewalld.py)\r\n\r\n        This module allows for addition or deletion of services and\r\n        ports (either TCP or UDP) in either running or permanent\r\n        firewalld rules.\r\n\r\n  * This module is maintained by The Ansible Community\r\nOPTIONS (= is mandatory):\r\nEXAMPLES:\r\n\r\n- firewalld:\r\n    service: https\r\n    permanent: yes\r\n    state: enabled\r\n\r\n- firewalld:\r\n    port: 8081\/tcp\r\n    permanent: yes\r\n    state: disabled\r\n    immediate: yes\r\n<\/pre>\n

\u4f9d\u636e\u8f93\u51fa\u4fe1\u606f\u53ef\u5f97\u77e5\uff0c\u5728firewalld\u6a21\u5757\u8bbe\u7f6e\u9632\u706b\u5899\u7b56\u7565\u65f6\uff0c\u6307\u5b9a\u534f\u8bae\u540d\u79f0\u4e3a\u201cservice: http\u201d\u53c2\u6570\uff0c\u653e\u884c\u8be5\u534f\u8bae\u4e3a\u201cstate: enabled\u201d\u53c2\u6570\uff0c\u8bbe\u7f6e\u4e3a\u6c38\u4e45\u751f\u6548\u4e3a\u201cpermanent: yes\u201d\u53c2\u6570\uff0c\u5f53\u524d\u7acb\u5373\u751f\u6548\u4e3a\u201cimmediate: yes\u201d\u53c2\u6570\u3002\u53c2\u6570\u867d\u7136\u591a\u4e86\u4e00\u4e9b\uff0c\u4f46\u662f\u57fa\u672c\u4e0e\u5728\u7b2c8\u7ae0\u8282\u5b66\u4e60\u7684\u4e00\u81f4\uff0c\u5e76\u4e0d\u9700\u8981\u62c5\u5fc3\u3002\u7ee7\u7eed\u7f16\u5199\uff1a<\/p>\n

[root@linuxprobe apache]# vim tasks\/main.yml\r\n---\r\n- name: one\r\n  yum:\r\n          name: httpd\r\n          state: latest\r\n- name: two\r\n  service:\r\n          name: httpd\r\n          state: started\r\n          enabled: yes\r\n- name: three\r\n  firewalld:\r\n          service: http\r\n          permanent: yes\r\n          state: enabled\r\n          immediate: yes\r\n<\/strong><\/pre>\n

\u7b2c4\u6b65\uff1a\u8ba9\u6bcf\u53f0\u4e3b\u673a\u663e\u793a\u7684\u4e3b\u9875\u6587\u4ef6\u5747\u4e0d\u76f8\u540c\u3002\u5728\u4f7f\u7528Ansible\u7684\u5e38\u89c4\u6a21\u5757\u65f6\uff0c\u90fd\u662f\u91c7\u7528\u201c\u67e5\u8be2\u7248\u4e3b\u793a\u4f8b\u5e76\u6a21\u4eff\u201d\u7684\u65b9\u5f0f\u641e\u5b9a\u7684\uff0c\u8fd9\u91cc\u4e3a\u4e86\u589e\u52a0\u96be\u5ea6\uff0c\u6211\u4eec\u518d\u63d0\u51fa\u4e2a\u65b0\u9700\u6c42\uff0c\u5373\u80fd\u5426\u8ba9\u6bcf\u53f0\u4e3b\u673a\u4e0a\u8fd0\u884c\u7684httpd\u7f51\u7ad9\u670d\u52a1\u90fd\u80fd\u663e\u793a\u4e0d\u540c\u7684\u5185\u5bb9\u5462\uff1f\u4f8b\u5982\u663e\u793a\u5f53\u524d\u670d\u52a1\u5668\u7684\u4e3b\u673a\u540d\u53caIP\u5730\u5740\u3002\u8fd9\u5c31\u8981\u7528\u5230template\u6a21\u5757\u53caJinja2\u6280\u672f\u4e86\u3002<\/p>\n

\u4f9d\u65e7\u5148\u4f7f\u7528ansible-doc\u547d\u4ee4\u67e5\u8be2template\u6a21\u5757\u7684\u4f7f\u7528\u65b9\u6cd5\u3002\u793a\u4f8b\u90e8\u5206\u5927\u6709\u5e2e\u52a9\uff1a<\/p>\n

[root@linuxprobe apache]# ansible-doc template\r\n> TEMPLATE    (\/usr\/lib\/python3.6\/site-packages\/ansible\/modules\/files\/template.>\r\n\r\n        Templates are processed by the L(Jinja2 templating\r\n        language,http:\/\/jinja.pocoo.org\/docs\/). Documentation on the\r\n        template formatting can be found in the L(Template Designer\r\n        Documentation,http:\/\/jinja.pocoo.org\/docs\/templates\/).\r\n        Additional variables listed below can be used in templates.\r\n        `ansible_managed' (configurable via the `defaults' section of\r\n        `ansible.cfg') contains a string which can be used to describe\r\n        the template name, host, modification time of the template\r\n        file and the owner uid. `template_host' contains the node name\r\n        of the template's machine. `template_uid' is the numeric user\r\n        id of the owner. `template_path' is the path of the template.\r\n        `template_fullpath' is the absolute path of the template.\r\n        `template_destpath' is the path of the template on the remote\r\n        system (added in 2.8). `template_run_date' is the date that\r\n        the template was rendered.\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: Template a file to \/etc\/files.conf\r\n  template:\r\n    src: \/mytemplates\/foo.j2\r\n    dest: \/etc\/file.conf\r\n    owner: bin\r\n    group: wheel\r\n    mode: '0644'\r\n<\/pre>\n

\u4ecetemplate\u6a21\u5757\u7684\u8f93\u51fa\u4fe1\u606f\u4e2d\u53ef\u5f97\u77e5\uff0c\u8fd9\u662f\u4e00\u4e2a\u7528\u4e8e\u590d\u5236\u6587\u4ef6\u6a21\u677f\u7684\u6a21\u5757\uff0c\u80fd\u591f\u628a\u6587\u4ef6\u4eceAnsible\u670d\u52a1\u5668\u590d\u5236\u5230\u53d7\u7ba1\u4e3b\u673a\u4e0a\u3002\u5176\u4e2d\uff0csrc\u53c2\u6570\u7528\u4e8e\u5b9a\u4e49\u672c\u5730\u6587\u4ef6\u7684\u8def\u5f84\uff0cdest\u53c2\u6570\u7528\u4e8e\u5b9a\u4e49\u590d\u5236\u5230\u53d7\u7ba1\u4e3b\u673a\u7684\u6587\u4ef6\u8def\u5f84\uff0c\u800cowner\u3001group\u3001mode\u53c2\u6570\u53ef\u9009\u62e9\u6027\u5730\u8bbe\u7f6e\u6587\u4ef6\u5f52\u5c5e\u53ca\u6743\u9650\u4fe1\u606f\u3002<\/p>\n

\u6b63\u5e38\u6765\u8bf4\uff0c\u6211\u4eec\u53ef\u4ee5\u76f4\u63a5\u590d\u5236\u6587\u4ef6\u7684\u64cd\u4f5c\uff0c\u53d7\u7ba1\u4e3b\u673a\u4e0a\u4f1a\u83b7\u53d6\u5230\u4e00\u4e2a\u4e0eAnsible\u670d\u52a1\u5668\u4e0a\u7684\u6587\u4ef6\u4e00\u6a21\u4e00\u6837\u7684\u6587\u4ef6\u3002\u4f46\u6709\u65f6\u5019\u60f3\u8ba9\u6bcf\u53f0\u5ba2\u6237\u7aef\u6839\u636e\u81ea\u8eab\u7cfb\u7edf\u7684\u60c5\u51b5\u4ea7\u751f\u4e0d\u540c\u7684\u6587\u4ef6\u4fe1\u606f\uff0c\u8fd9\u5c31\u9700\u8981\u7528\u5230Jinja2\u6280\u672f\u4e86\uff0cJinja2\u683c\u5f0f\u7684\u6a21\u677f\u6587\u4ef6\u540e\u7f00\u662f.j2\u3002\u7ee7\u7eed\u7f16\u5199\uff1a<\/p>\n

[root@linuxprobe apache]# vim tasks\/main.yml\r\n---\r\n- name: one\r\n  yum:\r\n          name: httpd\r\n          state: latest\r\n- name: two\r\n  service:\r\n          name: httpd\r\n          state: started\r\n          enabled: yes\r\n- name: three\r\n  firewalld:\r\n          service: http\r\n          permanent: yes\r\n          state: enabled\r\n          immediate: yes\r\n- name: four\r\n  template:\r\n          src: index.html.j2\r\n          dest: \/var\/www\/html\/index.html<\/strong>\r\n<\/pre>\n

\"\"<\/span><\/p>\n

Jinja2\u662fPython\u8bed\u8a00\u4e2d\u5e7f\u6cdb\u4f7f\u7528\u7684\u6a21\u677f\u5f15\u64ce\uff0c\u5176\u8bbe\u8ba1\u7075\u611f\u6e90\u81eaDjango\u7684\u6a21\u677f\u5f15\u64ce\u3002Jinja2\u5728\u6b64\u57fa\u7840\u4e0a\u53d1\u5c55\u4e86\u66f4\u4e3a\u5f3a\u5927\u7684\u8bed\u6cd5\u548c\u529f\u80fd\uff0c\u4f7f\u5176\u80fd\u591f\u6839\u636e\u53d7\u7ba1\u4e3b\u673a\u7684\u53d8\u91cf\u52a8\u6001\u751f\u6210\u4e0d\u540c\u7684\u6587\u4ef6\u5185\u5bb9\u3002\u7b80\u800c\u8a00\u4e4b\uff0c\u6b63\u5e38\u60c5\u51b5\u4e0b\u7684\u6587\u4ef6\u590d\u5236\u64cd\u4f5c\u4f1a\u4f7f\u65b0\u65e7\u6587\u4ef6\u5b8c\u5168\u4e00\u81f4\uff0c\u800c\u4f7f\u7528Jinja2\u6280\u672f\u65f6\uff0c\u6587\u4ef6\u4e2d\u5e76\u4e0d\u4f1a\u76f4\u63a5\u5199\u5165\u56fa\u5b9a\u5185\u5bb9\uff0c\u800c\u662f\u5199\u5165\u4e00\u7cfb\u5217\u53d8\u91cf\u540d\u79f0\u3002<\/p>\n

\u5728\u4f7f\u7528template\u6a21\u5757\u8fdb\u884c\u6587\u4ef6\u590d\u5236\u65f6\uff0cAnsible\u670d\u52a1\u4f1a\u5728\u53d7\u7ba1\u4e3b\u673a\u4e0a\u6536\u96c6\u8fd9\u4e9b\u53d8\u91cf\u7684\u5bf9\u5e94\u503c\uff0c\u5e76\u5c06\u5176\u52a8\u6001\u5730\u586b\u5165\u5230\u6a21\u677f\u6587\u4ef6\u4e2d\u3002\u6700\u7ec8\u751f\u6210\u7684\u6587\u4ef6\u5c06\u6839\u636e\u6bcf\u53f0\u4e3b\u673a\u7684\u5177\u4f53\u60c5\u51b5\u91cf\u8eab\u5b9a\u5236\u3002\u8fd9\u79cd\u65b9\u5f0f\u6781\u5927\u5730\u63d0\u5347\u4e86\u81ea\u52a8\u5316\u8fd0\u7ef4\u7684\u7075\u6d3b\u6027\u548c\u667a\u80fd\u5316\uff0c\u4f7f\u5f97\u540c\u4e00\u6a21\u677f\u80fd\u9002\u5e94\u591a\u79cd\u73af\u5883\u548c\u9700\u6c42\u3002<\/p>\n

\u4f8b\u5982\uff0c\u60f3\u8981\u8ba9\u6bcf\u4e2a\u7f51\u7ad9\u7684\u8f93\u51fa\u4fe1\u606f\u503c\u4e3a\u201cWelcome to \u4e3b\u673a\u540d on \u4e3b\u673a\u5730\u5740\u201d\uff0c\u4e5f\u5c31\u662f\u7528\u6bcf\u4e2a\u4e3b\u673a\u81ea\u5df1\u72ec\u6709\u7684\u540d\u79f0\u548cIP\u5730\u5740\u6765\u66ff\u6362\u6587\u672c\u4e2d\u7684\u5185\u5bb9\uff0c\u8fd9\u6837\u5c31\u6709\u8da3\u592a\u591a\u4e86\u3002\u8fd9\u4e2a\u5b9e\u9a8c\u7684\u96be\u70b9\u5728\u4e8e\u67e5\u8be2\u5230\u5bf9\u5e94\u7684\u53d8\u91cf\u540d\u79f0\u3001\u4e3b\u673a\u540d\u53ca\u5730\u5740\u6240\u5bf9\u5e94\u7684\u503c\u4fdd\u5b58\u5728\u54ea\u91cc\uff1f\u53ef\u4ee5\u7528setup\u6a21\u5757\u8fdb\u884c\u67e5\u8be2\u3002<\/p>\n

[root@linuxprobe apache]# ansible-doc setup\r\n> SETUP    (\/usr\/lib\/python3.6\/site-packages\/ansible\/modules\/system\/setup.py)\r\n\r\n        This module is automatically called by playbooks to gather\r\n        useful variables about remote hosts that can be used in\r\n        playbooks. It can also be executed directly by\r\n        `\/usr\/bin\/ansible' to check what variables are available to a\r\n        host. Ansible provides many `facts' about the system,\r\n        automatically. This module is also supported for Windows\r\n        targets.\r\n<\/pre>\n

setup\u6a21\u5757\u7684\u4f5c\u7528\u662f\u81ea\u52a8\u6536\u96c6\u53d7\u7ba1\u4e3b\u673a\u4e0a\u7684\u53d8\u91cf\u4fe1\u606f\uff0c\u4f7f\u7528-a\u53c2\u6570\u5916\u52a0filter\u547d\u4ee4\u80fd\u591f\u5bf9\u6536\u96c6\u6765\u7684\u4fe1\u606f\u8fdb\u884c\u4e8c\u6b21\u8fc7\u6ee4\u3002\u76f8\u5e94\u7684\u8bed\u6cd5\u683c\u5f0f\u4e3aansible all -m setup -a 'filter=\"*\u5173\u952e\u8bcd*\"'\uff0c\u5176\u4e2d*\u53f7\u662f\u7b2c3\u7ae0\u8282\u8bb2\u5230\u7684\u901a\u914d\u7b26\uff0c\u7528\u4e8e\u8fdb\u884c\u5173\u952e\u8bcd\u67e5\u8be2\u3002\u4f8b\u5982\uff0c\u5982\u679c\u60f3\u641c\u7d22\u5404\u4e2a\u4e3b\u673a\u7684\u540d\u79f0\uff0c\u5219\u53ef\u4ee5\u4f7f\u7528\u901a\u914d\u7b26\u641c\u7d22\u6240\u6709\u5305\u542bfqdn\u5173\u952e\u8bcd\u7684\u53d8\u91cf\u503c\u4fe1\u606f\u3002<\/p>\n

FQDN\uff08Fully Qualified Domain Name\uff0c\u5b8c\u5168\u9650\u5b9a\u57df\u540d\uff09\u7528\u4e8e\u5728\u903b\u8f91\u4e0a\u51c6\u786e\u8868\u793a\u51fa\u4e3b\u673a\u7684\u4f4d\u7f6e\u3002FQDN\u5e38\u5e38\u88ab\u4f5c\u4e3a\u4e3b\u673a\u540d\u7684\u5b8c\u5168\u8868\u8fbe\u5f62\u5f0f\uff0c\u6bd4\/etc\/hostname\u6587\u4ef6\u4e2d\u5b9a\u4e49\u7684\u4e3b\u673a\u540d\u66f4\u52a0\u4e25\u8c28\u548c\u51c6\u786e\u3002\u901a\u8fc7\u8f93\u51fa\u4fe1\u606f\u53ef\u5f97\u77e5\uff0cansible_fqdn\u53d8\u91cf\u4fdd\u5b58\u6709\u4e3b\u673a\u540d\u79f0\u3002\u968f\u540e\u8fdb\u884c\u4e0b\u4e00\u6b65\u64cd\u4f5c\uff1a<\/p>\n

[root@linuxprobe ~]# ansible all -m setup -a 'filter=\"*fqdn*\"'\r\n192.168.10.20 | SUCCESS => {\r\n    \"ansible_facts\": {\r\n        \"ansible_fqdn\": \"lrxjmw.cn\",<\/strong>\r\n        \"discovered_interpreter_python\": \"\/usr\/libexec\/platform-python\"\r\n    },\r\n    \"changed\": false\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<\/pre>\n

\u7528\u4e8e\u6307\u5b9a\u4e3b\u673a\u5730\u5740\u7684\u53d8\u91cf\u53ef\u4ee5\u7528ip\u4f5c\u4e3a\u5173\u952e\u8bcd\u8fdb\u884c\u68c0\u7d22\u3002\u4e0b\u9762\u8f93\u51fa\u4fe1\u606f\u4e2d\uff0cansible_all_ipv4_addresses\u53d8\u91cf\u4e2d\u7684\u503c\u662f\u6211\u4eec\u60f3\u8981\u7684\u4fe1\u606f\u3002\u5982\u679c\u60f3\u8f93\u51faIPv6\u5f62\u5f0f\u7684\u5730\u5740\uff0c\u5219\u53ef\u7528ansible_all_ipv6_addresses\u53d8\u91cf\u3002<\/p>\n

[root@linuxprobe ~]# ansible all -m setup -a 'filter=\"*ip*\"'\r\n192.168.10.20 | SUCCESS => {\r\n    \"ansible_facts\": {\r\n        \"ansible_all_ipv4_addresses<\/strong>\": [\r\n            \"192.168.10.20\",\r\n            \"192.168.122.1\"\r\n        ],\r\n        \"ansible_all_ipv6_addresses\": [\r\n            \"fe80::d0bb:17c8:880d:e719\"\r\n        ],\r\n        \"ansible_default_ipv4\": {},\r\n        \"ansible_default_ipv6\": {},\r\n        \"ansible_fips\": false,\r\n        \"discovered_interpreter_python\": \"\/usr\/libexec\/platform-python\"\r\n    },\r\n    \"changed\": false\r\n}\r\n\u2026\u2026\u2026\u2026\u2026\u2026\u7701\u7565\u90e8\u5206\u8f93\u51fa\u4fe1\u606f\u2026\u2026\u2026\u2026\u2026\u2026<\/pre>\n

\u5728\u786e\u8ba4\u4e86\u4e3b\u673a\u540d\u4e0eIP\u5730\u5740\u6240\u5bf9\u5e94\u7684\u5177\u4f53\u53d8\u91cf\u540d\u79f0\u540e\uff0c\u5728\u89d2\u8272\u6240\u5bf9\u5e94\u7684templates\u76ee\u5f55\u5185\u65b0\u5efa\u4e00\u4e2a\u4e0e\u4e0a\u9762\u7684template\u6a21\u5757\u53c2\u6570\u76f8\u540c\u7684\u6587\u4ef6\u540d\u79f0\uff08index.html.j2\uff09\u3002Jinja2\u5728\u8c03\u7528\u53d8\u91cf\u503c\u65f6\uff0c\u683c\u5f0f\u4e3a\u5728\u53d8\u91cf\u540d\u79f0\u7684\u4e24\u4fa7\u683c\u52a0\u4e24\u4e2a\u5927\u62ec\u53f7\uff1a<\/p>\n

[root@linuxprobe apache]# vim templates\/index.html.j2\r\nWelcome to {{ ansible_fqdn }}<\/strong> on {{ ansible_all_ipv4_addresses }}<\/strong><\/pre>\n

\u8fdb\u884c\u5230\u8fd9\u91cc\uff0c\u4efb\u52a1\u57fa\u672c\u5c31\u7b97\u5b8c\u6210\u4e86\u3002\u6700\u540e\u8981\u505a\u7684\u5c31\u662f\u7f16\u5199\u4e00\u4e2a\u7528\u4e8e\u8c03\u7528apache\u89d2\u8272\u7684yml\u6587\u4ef6\uff0c\u4ee5\u53ca\u6267\u884c\u8fd9\u4e2a\u6587\u4ef6\u3002<\/p>\n

[root@linuxprobe apache]# cd ~\r\n[root@linuxprobe ~]# vim roles.yml\r\n---\r\n- name: \u8c03\u7528\u81ea\u5efa\u89d2\u8272\r\n  hosts: all\r\n  roles:\r\n          - apache\r\n[root@linuxprobe ~]# ansible-playbook roles.yml \r\nPLAY [\u8c03\u7528\u81ea\u5efa\u89d2\u8272] **************************************************************************\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\nok: [192.168.10.24]\r\n\r\nTASK [apache : 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\nchanged: [192.168.10.24]\r\n\r\nTASK [apache : two] *************************************************************************\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\nchanged: [192.168.10.24]\r\n\r\nTASK [apache : three] ***********************************************************************\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\nchanged: [192.168.10.24]\r\n\r\nTASK [apache : four] ***********************************************************************\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\nchanged: [192.168.10.24]\r\n\r\nPLAY RECAP **********************************************************************************\r\n192.168.10.20   : ok=5   changed=4  unreachable=0   failed=0   skipped=0   rescued=0   ignored=0   \r\n192.168.10.21   : ok=5   changed=4  unreachable=0   failed=0   skipped=0   rescued=0   ignored=0   \r\n192.168.10.22   : ok=5   changed=4  unreachable=0   failed=0   skipped=0   rescued=0   ignored=0   \r\n192.168.10.23   : ok=5   changed=4  unreachable=0   failed=0   skipped=0   rescued=0   ignored=0   \r\n192.168.10.24   : ok=4   changed=4  unreachable=0   failed=0   skipped=0   rescued=0   ignored=0<\/pre>\n

\u6267\u884c\u5b8c\u6bd5\u540e\uff0c\u5728\u6d4f\u89c8\u5668\u4e2d\u968f\u673a\u8f93\u5165\u51e0\u53f0\u4e3b\u673a\u7684IP\u5730\u5740\uff0c\u5373\u53ef\u8bbf\u95ee\u5230\u5305\u542b\u4e3b\u673aFQDN\u548cIP\u5730\u5740\u7684\u7f51\u9875\u4e86\uff0c\u5982\u56fe16-7\uff5e\u56fe16-9\u6240\u793a\u3002<\/p>\n

\"\"<\/p>\n

\u3010\u6539\u6539\u6539\u3011<\/span><\/strong>\u56fe16-7 \u968f\u673a\u8bbf\u95ee\u4e00\u53f0\u4e3b\u673a\u8282\u70b9\u7684\u7f51\u7ad9\u9996\u9875<\/p>\n

\"\"<\/p>\n

\u3010\u6539\u6539\u6539\u3011<\/span><\/strong>\u56fe16-8 \u968f\u673a\u8bbf\u95ee\u4e00\u53f0\u4e3b\u673a\u8282\u70b9\u7684\u7f51\u7ad9\u9996\u9875\"\"<\/p>\n

\u3010\u6539\u6539\u6539\u3011<\/span><\/strong>\u56fe16-9 \u968f\u673a\u8bbf\u95ee\u4e00\u53f0\u4e3b\u673a\u8282\u70b9\u7684\u7f51\u7ad9\u9996\u9875<\/p>\n

\u5b9e\u9a8c\u76f8\u5f53\u6210\u529f\uff01<\/p>\n

\u51fa\u73b0\u95ee\u9898?\u5927\u80c6\u63d0\u95ee!<\/strong><\/span><\/p>\n

\u56e0\u8bfb\u8005\u4eec\u786c\u4ef6\u4e0d\u540c\u6216\u64cd\u4f5c\u9519\u8bef\u90fd\u53ef\u80fd\u5bfc\u81f4\u5b9e\u9a8c\u914d\u7f6e\u51fa\u9519\uff0c\u8bf7\u8010\u5fc3\u518d\u4ed4\u7ec6\u770b\u770b\u64cd\u4f5c\u6b65\u9aa4\u5427\uff0c\u4e0d\u8981\u6c14\u9981~<\/p>\n

Linux\u6280\u672f\u4ea4\u6d41\u5b66\u4e60\u8bf7\u52a0\u8bfb\u8005\u7fa4\uff08\u63a8\u8350<\/span><\/strong>\uff09\uff1ahttps:\/\/lrxjmw.cn\/club<\/a><\/p>\n

*\u672c\u7fa4\u7279\u8272\uff1a\u786e\u4fdd\u6bcf\u4e00\u4f4d\u7fa4\u53cb\u90fd\u662f\u300aLinux\u5c31\u8be5\u8fd9\u4e48\u5b66\u300b\u7684\u8bfb\u8005\uff0c\u7b54\u7591\u66f4\u6709\u9488\u5bf9\u6027\uff0c\u4e0d\u5b9a\u671f\u9886\u53d6\u5b9a\u5236\u793c\u54c1\u3002<\/p><\/blockquote>\n

16.6 \u521b\u5efa\u548c\u4f7f\u7528\u903b\u8f91\u5377<\/strong><\/span><\/h5>\n

\u521b\u5efa\u4e00\u4e2a\u80fd\u6279\u91cf\u3001\u81ea\u52a8\u7ba1\u7406\u903b\u8f91\u5377\u8bbe\u5907\u7684\u5267\u672c\uff0c\u4e0d\u4f46\u80fd\u5927\u5927\u63d0\u9ad8\u786c\u76d8\u8bbe\u5907\u7684\u7ba1\u7406\u6548\u7387\uff0c\u800c\u4e14\u8fd8\u80fd\u907f\u514d\u624b\u52a8\u521b\u5efa\u5e26\u6765\u7684\u9519\u8bef\u3002\u4f8b\u5982\uff0c\u6211\u4eec\u60f3\u5728\u6bcf\u53f0\u53d7\u7ba1\u4e3b\u673a\u4e0a\u90fd\u521b\u5efa\u51fa\u4e00\u4e2a\u540d\u4e3adata\u7684\u903b\u8f91\u5377\u8bbe\u5907\uff0c\u5927\u5c0f\u4e3a150MB\uff0c\u5f52\u5c5e\u4e8eresearch\u5377\u7ec4\u3002\u5982\u679c\u521b\u5efa\u6210\u529f\uff0c\u5219\u8fdb\u4e00\u6b65\u7528Ext4\u6587\u4ef6\u7cfb\u7edf\u8fdb\u884c\u683c\u5f0f\u5316\u64cd\u4f5c\uff1b\u5982\u679c\u521b\u5efa\u5931\u8d25\uff0c\u5219\u7ed9\u7528\u6237\u8f93\u51fa\u4e00\u6761\u62a5\u9519\u63d0\u9192\uff0c\u4ee5\u4fbf\u6392\u67e5\u539f\u56e0\u3002<\/p>\n

\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u4f7f\u7528Ansible\u5267\u672c\u8981\u6bd4\u4f7f\u7528Shell\u811a\u672c\u7684\u4f18\u52bf\u5927\uff0c\u539f\u56e0\u4e3b\u8981\u6709\u4e0b\u9762\u4e24\u70b9\u3002<\/p>\n

Ansible\u6a21\u5757\u5316\u7684\u529f\u80fd\u8ba9\u64cd\u4f5c\u66f4\u6807\u51c6\uff0c\u53ea\u8981\u5728\u6267\u884c\u8fc7\u7a0b\u4e2d\u65e0\u62a5\u9519\uff0c\u90a3\u4e48\u4fbf\u4f1a\u4f9d\u636e\u8fdc\u7a0b\u4e3b\u673a\u7684\u7cfb\u7edf\u7248\u672c\u53ca\u914d\u7f6e\u81ea\u52a8\u505a\u51fa\u5224\u65ad\u548c\u64cd\u4f5c\uff0c\u4e0d\u7528\u62c5\u5fc3\u56e0\u7cfb\u7edf\u53d8\u5316\u800c\u5bfc\u81f4\u547d\u4ee4\u5931\u6548\u7684\u95ee\u9898\u3002<\/p>\n

Ansible\u670d\u52a1\u5728\u6267\u884c\u5267\u672c\u6587\u4ef6\u65f6\u4f1a\u8fdb\u884c\u5224\u65ad\uff1a\u5982\u679c\u8be5\u6587\u4ef6\u6216\u8be5\u8bbe\u5907\u5df2\u7ecf\u88ab\u521b\u5efa\u8fc7\uff0c\u6216\u662f\u67d0\u4e2a\u52a8\u4f5c\uff08play\uff09\u5df2\u7ecf\u88ab\u6267\u884c\u8fc7\uff0c\u5219\u7edd\u5bf9\u4e0d\u4f1a\u518d\u91cd\u590d\u6267\u884c\uff1b\u800c\u4f7f\u7528Shell\u811a\u672c\u6709\u53ef\u80fd\u5bfc\u81f4\u8bbe\u5907\u88ab\u91cd\u590d\u683c\u5f0f\u5316\uff0c\u5bfc\u81f4\u6570\u636e\u4e22\u5931\u3002<\/p><\/blockquote>\n

\u9996\u5148\u5728prod\u7ec4\u7684\u4e24\u53f0\u4e3b\u673a\u4e0a\u5206\u522b\u6dfb\u52a0\u4e00\u5757\u786c\u76d8\u8bbe\u5907\uff0c\u5927\u5c0f\u4e3a20GB\uff0c\u7c7b\u578b\u4e3aSCSI\uff0c\u5176\u4f59\u9009\u9879\u9009\u62e9\u9ed8\u8ba4\u503c\uff0c\u5982\u56fe16-10\uff5e\u56fe16-12\u6240\u793a\u3002<\/p>\n

\"\"<\/p>\n

\u56fe16-10 \u6dfb\u52a0\u4e00\u5757\u65b0\u786c\u76d8
\n\"\"<\/p>\n

\u56fe16-11 \u8bbe\u7f6e\u786c\u76d8\u7c7b\u578b<\/p>\n

\"\"<\/p>\n

\u56fe16-12 \u65b0\u786c\u76d8\u6dfb\u52a0\u5b8c\u6bd5<\/p>\n

\u901a\u8fc7\u56de\u5fc6\u7b2c7\u7ae0\u5b66\u4e60\u8fc7\u7684\u903b\u8f91\u5377\u7684\u77e5\u8bc6\uff0c\u6211\u4eec\u5e94\u8be5\u8ba9\u5267\u672c\u6587\u4ef6\u4f9d\u6b21\u521b\u5efa\u7269\u7406\u5377\uff08PV\uff09\u3001\u5377\u7ec4\uff08VG\uff09\u53ca\u903b\u8f91\u5377\uff08LV\uff09\u3002\u9700\u8981\u5148\u4f7f\u7528lvg\u6a21\u5757\u8ba9\u8bbe\u5907\u652f\u6301\u903b\u8f91\u5377\u6280\u672f\uff0c\u7136\u540e\u521b\u5efa\u4e00\u4e2a\u540d\u4e3aresearch\u7684\u5377\u7ec4\u3002lvg\u6a21\u5757\u7684\u5e2e\u52a9\u4fe1\u606f\u5982\u4e0b\uff1a<\/p>\n

[root@linuxprobe ~]# ansible-doc lvg\r\n> LVG    (\/usr\/lib\/python3.6\/site-packages\/ansible\/modules\/system\/lvg.py)\r\n\r\n        This module creates, removes or resizes volume groups.\r\n\r\n  * This module is maintained by The Ansible Community\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: Create a volume group on top of \/dev\/sda1 with physical extent size = 3>\r\n  lvg:\r\n    vg: vg.services\r\n    pvs: \/dev\/sda1\r\n    pesize: 32\r\n\r\n- name: Create a volume group on top of \/dev\/sdb with physical extent size = 12>\r\n  lvg:\r\n    vg: vg.services\r\n    pvs: \/dev\/sdb\r\n    pesize: 128K\r\n<\/pre>\n

\u901a\u8fc7\u8f93\u51fa\u4fe1\u606f\u53ef\u5f97\u77e5\uff0c\u521b\u5efaPV\u548cVG\u7684lvg\u6a21\u5757\u603b\u5171\u67093\u4e2a\u5fc5\u5907\u53c2\u6570\u3002\u5176\u4e2d\uff0cvg\u53c2\u6570\u7528\u4e8e\u5b9a\u4e49\u5377\u7ec4\u7684\u540d\u79f0\uff0cpvs\u53c2\u6570\u7528\u4e8e\u6307\u5b9a\u786c\u76d8\u8bbe\u5907\u7684\u540d\u79f0\uff0cpesize\u53c2\u6570\u7528\u4e8e\u786e\u5b9a\u6700\u7ec8\u5377\u7ec4\u7684\u5bb9\u91cf\u5927\u5c0f\uff08\u53ef\u4ee5\u7528PE\u4e2a\u6570\u6216\u5bb9\u91cf\u503c\u8fdb\u884c\u6307\u5b9a\uff09\u3002\u8fd9\u6837\u4e00\u6765\uff0c\u6211\u4eec\u5148\u521b\u5efa\u51fa\u4e00\u4e2a\u7531\/dev\/sdb\u8bbe\u5907\u7ec4\u6210\u7684\u540d\u79f0\u4e3aresearch\u3001\u5927\u5c0f\u4e3a150MB\u7684\u5377\u7ec4\u8bbe\u5907\u3002<\/p>\n

[root@linuxprobe ~]# vim lv.yml\r\n---\r\n- name: \u521b\u5efa\u548c\u4f7f\u7528\u903b\u8f91\u5377\r\n  hosts: all\r\n  tasks:\r\n          - name: one\r\n            lvg:\r\n                    vg: research\r\n                    pvs: \/dev\/sdb\r\n                    pesize: 150M\r\n<\/pre>\n

\u7531\u4e8e\u521a\u624d\u53ea\u5728prod\u7ec4\u7684\u4e24\u53f0\u4e3b\u673a\u4e0a\u6dfb\u52a0\u4e86\u65b0\u786c\u76d8\u8bbe\u5907\u6587\u4ef6\uff0c\u56e0\u6b64\u5728\u6267\u884c\u4e0a\u8ff0\u64cd\u4f5c\u65f6\u5176\u4f593\u53f0\u4e3b\u673a\u4f1a\u63d0\u793a\u672a\u521b\u5efa\u6210\u529f\uff0c\u8fd9\u5c5e\u4e8e\u6b63\u5e38\u60c5\u51b5\u3002\u63a5\u4e0b\u6765\u4f7f\u7528lvol\u6a21\u5757\u521b\u5efa\u51fa\u903b\u8f91\u5377\u8bbe\u5907\u3002\u8fd8\u662f\u6309\u7167\u60ef\u4f8b\uff0c\u5148\u67e5\u770b\u6a21\u5757\u7684\u5e2e\u52a9\u4fe1\u606f\uff1a<\/p>\n

[root@linuxprobe ~]# ansible-doc lvol\r\n> LVOL    (\/usr\/lib\/python3.6\/site-packages\/ansible\/modules\/system\/lvol.py)\r\n\r\n        This module creates, removes or resizes logical volumes.\r\n\r\n  * This module is maintained by The Ansible Community\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: Create a logical volume of 512m\r\n  lvol:\r\n    vg: firefly\r\n    lv: test\r\n    size: 512\r\n\r\n- name: Create a logical volume of 512m with disks \/dev\/sda and \/dev\/sdb\r\n  lvol:\r\n    vg: firefly\r\n    lv: test\r\n    size: 512\r\n    pvs: \/dev\/sda,\/dev\/sdb\r\n<\/pre>\n

\u901a\u8fc7\u8f93\u51fa\u4fe1\u606f\u53ef\u5f97\u77e5\uff0clvol\u662f\u7528\u4e8e\u521b\u5efa\u903b\u8f91\u5377\u8bbe\u5907\u7684\u6a21\u5757\u3002\u5176\u4e2d\uff0cvg\u53c2\u6570\u7528\u4e8e\u6307\u5b9a\u5377\u7ec4\u540d\u79f0\uff0clv\u53c2\u6570\u7528\u4e8e\u6307\u5b9a\u903b\u8f91\u5377\u540d\u79f0\uff0csize\u53c2\u6570\u5219\u7528\u4e8e\u6307\u5b9a\u6700\u7ec8\u903b\u8f91\u5377\u8bbe\u5907\u7684\u5bb9\u91cf\u5927\u5c0f\uff08\u4e0d\u7528\u52a0\u5355\u4f4d\uff0c\u9ed8\u8ba4\u4e3aMB\uff09\u3002\u586b\u5199\u597d\u53c2\u6570\uff0c\u521b\u5efa\u51fa\u4e00\u4e2a\u5927\u5c0f\u4e3a150MB\u3001\u5f52\u5c5e\u4e8eresearch\u5377\u7ec4\u4e14\u540d\u79f0\u4e3adata\u7684\u903b\u8f91\u5377\u8bbe\u5907\uff1a<\/p>\n

[root@linuxprobe ~]# vim lv.yml\r\n---\r\n- name: \u521b\u5efa\u548c\u4f7f\u7528\u903b\u8f91\u5377\r\n  hosts: all\r\n  tasks:\r\n          - name: one\r\n            lvg:\r\n                    vg: research\r\n                    pvs: \/dev\/sdb\r\n                    pesize: 150M\r\n          - name: two\r\n            lvol:\r\n                    vg: research\r\n                    lv: data\r\n                    size: 150M<\/strong>\r\n<\/pre>\n

\u8fd9\u6837\u8fd8\u4e0d\u591f\u597d\uff0c\u5982\u679c\u8fd8\u80fd\u5c06\u521b\u5efa\u51fa\u7684\/dev\/research\/data\u903b\u8f91\u5377\u8bbe\u5907\u81ea\u52a8\u7528Ext4\u6587\u4ef6\u7cfb\u7edf\u8fdb\u884c\u683c\u5f0f\u5316\u64cd\u4f5c\uff0c\u5219\u53c8\u80fd\u5e2e\u52a9\u8fd0\u7ef4\u7ba1\u7406\u5458\u51cf\u5c11\u4e00\u4e9b\u5de5\u4f5c\u91cf\u3002\u53ef\u4f7f\u7528filesystem\u6a21\u5757\u6765\u5b8c\u6210\u8bbe\u5907\u7684\u6587\u4ef6\u7cfb\u7edf\u683c\u5f0f\u5316\u64cd\u4f5c\u3002\u8be5\u6a21\u5757\u7684\u5e2e\u52a9\u4fe1\u606f\u5982\u4e0b\uff1a<\/p>\n

[root@linuxprobe ~]# ansible-doc filesystem\r\n> FILESYSTEM    (\/usr\/lib\/python3.6\/site-packages\/ansible\/modules\/system\/filesy>\r\n\r\n        This module creates a filesystem.\r\n\r\n  * This module is maintained by The Ansible Community\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: Create a ext2 filesystem on \/dev\/sdb1\r\n  filesystem:\r\n    fstype: ext2\r\n    dev: \/dev\/sdb1\r\n<\/pre>\n

filesystem\u6a21\u5757\u7684\u53c2\u6570\u771f\u662f\u7b80\u7ec3\uff0cfstype\u53c2\u6570\u7528\u4e8e\u6307\u5b9a\u6587\u4ef6\u7cfb\u7edf\u7684\u683c\u5f0f\u5316\u7c7b\u578b\uff0cdev\u53c2\u6570\u7528\u4e8e\u6307\u5b9a\u8981\u683c\u5f0f\u5316\u7684\u8bbe\u5907\u6587\u4ef6\u8def\u5f84\u3002\u7ee7\u7eed\u7f16\u5199\uff1a<\/p>\n

[root@linuxprobe ~]# vim lv.yml\r\n---\r\n- name: \u521b\u5efa\u548c\u4f7f\u7528\u903b\u8f91\u5377\r\n  hosts: all\r\n  tasks:\r\n          - name: one\r\n            lvg:\r\n                    vg: research\r\n                    pvs: \/dev\/sdb\r\n                    pesize: 150M\r\n          - name: two\r\n            lvol:\r\n                    vg: research\r\n                    lv: data\r\n                    size: 150M\r\n          - name: three\r\n            filesystem:\r\n                    fstype: ext4\r\n                    dev: \/dev\/research\/data <\/strong>\r\n<\/pre>\n

\u8fd9\u6837\u6309\u7167\u987a\u5e8f\u6267\u884c\u4e0b\u6765\uff0c\u903b\u8f91\u5377\u8bbe\u5907\u5c31\u80fd\u81ea\u52a8\u521b\u5efa\u597d\u4e86\u3002\u7b49\u4e00\u4e0b\uff0c\u8fd8\u6709\u4e2a\u95ee\u9898\u6ca1\u6709\u89e3\u51b3\u3002\u73b0\u5728\u53ea\u6709prod\u7ec4\u7684\u4e3b\u673a\u4e0a\u6dfb\u52a0\u4e86\u65b0\u7684\u786c\u76d8\u8bbe\u5907\u6587\u4ef6\uff0c\u5176\u4f59\u4e3b\u673a\u662f\u65e0\u6cd5\u6309\u7167\u65e2\u5b9a\u6a21\u5757\u987a\u5229\u5b8c\u6210\u64cd\u4f5c\u7684\u3002\u8fd9\u65f6\u5c31\u8981\u4f7f\u7528\u7c7b\u4f3c\u4e8e\u7b2c4\u7ae0\u5b66\u4e60\u7684if\u6761\u4ef6\u8bed\u53e5\u7684\u65b9\u5f0f\u8fdb\u884c\u5224\u65ad\u2014\u5982\u679c\u5931\u8d25\u2026\u2026\uff0c\u5219\u2026\u2026\u3002<\/p>\n

\u9996\u5148\u7528block\u64cd\u4f5c\u7b26\u5c06\u4e0a\u8ff0\u76843\u4e2a\u6a21\u5757\u547d\u4ee4\u4f5c\u4e3a\u4e00\u4e2a\u6574\u4f53\uff08\u76f8\u5f53\u4e8e\u5bf9\u8fd93\u4e2a\u6a21\u5757\u7684\u6267\u884c\u7ed3\u679c\u4f5c\u4e3a\u4e00\u4e2a\u6574\u4f53\u8fdb\u884c\u5224\u65ad\uff09\uff0c\u7136\u540e\u4f7f\u7528rescue\u64cd\u4f5c\u7b26\u8fdb\u884c\u6551\u63f4\uff0c\u4e14\u53ea\u6709block\u5757\u4e2d\u7684\u6a21\u5757\u6267\u884c\u5931\u8d25\u540e\u624d\u4f1a\u8c03\u7528rescue\u4e2d\u7684\u6551\u63f4\u6a21\u5757\u3002\u5176\u4e2d\uff0cdebug\u6a21\u5757\u7684msg\u53c2\u6570\u7684\u4f5c\u7528\u662f\uff0c\u5982\u679cblock\u4e2d\u7684\u6a21\u5757\u6267\u884c\u5931\u8d25\uff0c\u5219\u8f93\u51fa\u4e00\u6761\u4fe1\u606f\u5230\u5c4f\u5e55\uff0c\u7528\u4e8e\u63d0\u9192\u7528\u6237\u3002\u5b8c\u6210\u7f16\u5199\u540e\u7684\u5267\u672c\u662f\u4e0b\u9762\u8fd9\u4e2a\u6837\u5b50\uff1a<\/p>\n

[root@linuxprobe ~]# vim lv.yml\r\n---\r\n- name: \u521b\u5efa\u548c\u4f7f\u7528\u903b\u8f91\u5377\r\n  hosts: all\r\n  tasks:\r\n          - block:\r\n                  - name: one\r\n                    lvg:\r\n                            vg: research\r\n                            pvs: \/dev\/sdb\r\n                            pesize: 150M\r\n                  - name: two\r\n                    lvol:\r\n                            vg: research\r\n                            lv: data\r\n                            size: 150M\r\n                  - name: three\r\n                    filesystem:\r\n                            fstype: ext4\r\n                            dev: \/dev\/research\/data\r\n            rescue:\r\n                    - debug:\r\n                            msg: \"Could not create logical volume of that size\"\r\n<\/pre>\n

YAML\u8bed\u8a00\u5bf9\u683c\u5f0f\u6709\u7740\u786c\u6027\u7684\u8981\u6c42\uff0c\u65e2\u7136rescue\u662f\u5bf9block\u5185\u7684\u6a21\u5757\u8fdb\u884c\u6551\u63f4\u7684\u529f\u80fd\u4ee3\u7801\uff0c\u56e0\u6b64recue\u548cblock\u4e24\u4e2a\u64cd\u4f5c\u7b26\u5fc5\u987b\u4e25\u683c\u5bf9\u9f50\uff0c\u9519\u5f00\u4e00\u4e2a\u7a7a\u683c\u90fd\u4f1a\u5bfc\u81f4\u5267\u672c\u6267\u884c\u5931\u8d25\u3002\u786e\u8ba4\u65e0\u8bef\u540e\uff0c\u6267\u884clv.yml\u5267\u672c\u6587\u4ef6\u68c0\u9605\u4e00\u4e0b\u6548\u679c\uff1a<\/p>\n

[root@linuxprobe ~]# ansible-playbook lv.yml \r\n\r\nPLAY [\u521b\u5efa\u548c\u4f7f\u7528\u903b\u8f91\u5377] *********************************************************\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\nok: [192.168.10.24]\r\n\r\nTASK [one] *********************************************************************\r\nfatal: [192.168.10.20]: FAILED! => {\"changed\": false, \"msg\": \"Device \/dev\/sdb not found.\"}\r\nfatal: [192.168.10.21]: FAILED! => {\"changed\": false, \"msg\": \"Device \/dev\/sdb not found.\"}\r\nchanged: [192.168.10.22]\r\nchanged: [192.168.10.23]\r\nfatal: [192.168.10.24]: FAILED! => {\"changed\": false, \"msg\": \"Device \/dev\/sdb not found.\"}\r\n\r\nTASK [two] *********************************************************************\r\nchanged: [192.168.10.22]\r\nchanged: [192.168.10.23]\r\n\r\nTASK [three] *********************************************************************\r\nchanged: [192.168.10.22]\r\nchanged: [192.168.10.23]\r\n\r\nTASK [debug] *******************************************************************\r\nok: [192.168.10.20] => {\r\n    \"msg\": \"Could not create logical volume of that size\"\r\n}\r\nok: [192.168.10.21] => {\r\n    \"msg\": \"Could not create logical volume of that size\"\r\n}\r\nok: [192.168.10.24] => {\r\n    \"msg\": \"Could not create logical volume of that size\"\r\n}\r\n\r\nPLAY RECAP *********************************************************************\r\n192.168.10.20  : ok=2  changed=0  unreachable=0  failed=0  skipped=0  rescued=1  ignored=0   \r\n192.168.10.21  : ok=2  changed=0  unreachable=0  failed=0  skipped=0  rescued=1  ignored=0   \r\n192.168.10.22  : ok=4  changed=3  unreachable=0  failed=0  skipped=0  rescued=0  ignored=0   \r\n192.168.10.23  : ok=4  changed=3  unreachable=0  failed=0  skipped=0  rescued=0  ignored=0   \r\n192.168.10.24  : ok=2  changed=0  unreachable=0  failed=0  skipped=0  rescued=1  ignored=0 \r\n<\/pre>\n

\u5728\u5267\u672c\u8fd0\u884c\u5b8c\u6bd5\u540e\u7684\u6267\u884c\u8bb0\u5f55\uff08PLAY RECAP\uff09\u4e2d\u53ef\u5f88\u6e05\u6670\u5730\u770b\u5230\u53ea\u6709192.168.10.22\u53ca192.168.10.23\u8fd9\u4e24\u53f0prod\u7ec4\u4e2d\u7684\u4e3b\u673a\u6267\u884c\u6210\u529f\u4e86\uff0c\u5176\u4f593\u53f0\u4e3b\u673a\u5747\u89e6\u53d1\u4e86rescue\u529f\u80fd\u3002\u767b\u5f55\u5230\u4efb\u610f\u4e00\u53f0prod\u7ec4\u7684\u4e3b\u673a\u4e0a\uff0c\u627e\u5230\u65b0\u5efa\u7684\u903b\u8f91\u5377\u8bbe\u5907\u4fe1\u606f\uff1a<\/p>\n

[root@linuxprobe ~]# lvdisplay \r\n  --- Logical volume ---\r\n  LV Path                \/dev\/research\/data\r\n  LV Name                data\r\n  VG Name                research\r\n  LV UUID                EOUliC-tbkk-kOJR-8NaH-O9XQ-ijrK-TgEYGj\r\n  LV Write Access        read\/write\r\n  LV Creation host, time lrxjmw.cn, 2021-04-23 11:00:21 +0800\r\n  LV Status              available\r\n  # open                 0\r\n  LV Size                5.00 GiB\r\n  Current LE             1\r\n  Segments               1\r\n  Allocation             inherit\r\n  Read ahead sectors     auto\r\n  - currently set to     8192\r\n  Block device           253:2\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.7 \u5224\u65ad\u4e3b\u673a\u7ec4\u540d<\/span><\/strong><\/h5>\n

\u5728\u4e0a\u9762\u7684\u5267\u672c\u5b9e\u9a8c\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u8ba9\u4e0d\u540c\u7684\u4e3b\u673a\u6839\u636e\u81ea\u8eab\u4e0d\u540c\u7684\u53d8\u91cf\u4fe1\u606f\u800c\u751f\u6210\u51fa\u72ec\u7279\u7684\u7f51\u7ad9\u4e3b\u9875\u6587\u4ef6\uff0c\u4f46\u5374\u65e0\u6cd5\u5bf9\u67d0\u4e2a\u4e3b\u673a\u7ec4\u8fdb\u884c\u9488\u5bf9\u6027\u7684\u64cd\u4f5c\u3002\u5176\u5b9e\uff0c\u5728\u6bcf\u4e2a\u5ba2\u6237\u7aef\u4e2d\u90fd\u4f1a\u6709\u4e00\u4e2a\u540d\u4e3ainventory_hostname\u7684\u53d8\u91cf\uff0c\u7528\u4e8e\u5b9a\u4e49\u6bcf\u53f0\u4e3b\u673a\u6240\u5bf9\u5e94\u7684Ansible\u670d\u52a1\u7684\u4e3b\u673a\u7ec4\u540d\u79f0\uff0c\u4e5f\u5c31\u662f\/etc\/ansible\/hosts\u6587\u4ef6\u4e2d\u6240\u5bf9\u5e94\u7684\u5206\u7ec4\u4fe1\u606f\uff0c\u4f8b\u5982dev\u3001test\u3001prod\u3001balancers\u3002<\/p>\n

inventory_hostname\u662fAnsible\u670d\u52a1\u4e2d\u7684\u9b54\u6cd5\u53d8\u91cf\uff0c\u8fd9\u610f\u5473\u7740\u65e0\u6cd5\u4f7f\u7528setup\u6a21\u5757\u76f4\u63a5\u8fdb\u884c\u67e5\u8be2\uff0c\u8bf8\u5982ansible all -m setup -a 'filter=\"*\u5173\u952e\u8bcd*\"'\u8fd9\u6837\u7684\u547d\u4ee4\u5c06\u5bf9\u5b83\u5931\u6548\u3002\u9b54\u6cd5\u53d8\u91cf\u9700\u8981\u5728\u6267\u884c\u5267\u672c\u6587\u4ef6\u65f6\u7684Gathering Facts\u9636\u6bb5\u8fdb\u884c\u641c\u96c6\uff0c\u76f4\u63a5\u67e5\u8be2\u662f\u770b\u4e0d\u5230\u7684\uff0c\u53ea\u80fd\u5728\u5267\u672c\u6587\u4ef6\u4e2d\u8fdb\u884c\u8c03\u7528\u3002<\/p>\n

\u5728\u83b7\u5f97\u4e86\u5b58\u50a8\u4e3b\u673a\u7ec4\u540d\u79f0\u7684\u53d8\u91cf\u540d\u79f0\u540e\uff0c\u63a5\u4e0b\u6765\u5f00\u59cb\u5b9e\u6218\u3002\u8fd9\u91cc\u7684\u9700\u6c42\u5982\u4e0b\uff1a<\/p>\n

\u82e5\u4e3b\u673a\u5728dev\u5206\u7ec4\u4e2d\uff0c\u5219\u4fee\u6539\/etc\/issue\u6587\u4ef6\u5185\u5bb9\u4e3aDevelopment\uff1b<\/p>\n

\u82e5\u4e3b\u673a\u5728test\u5206\u7ec4\u4e2d\uff0c\u5219\u4fee\u6539\/etc\/issue\u6587\u4ef6\u5185\u5bb9\u4e3aTest\uff1b<\/p>\n

\u82e5\u4e3b\u673a\u5728prod\u5206\u7ec4\u4e2d\uff0c\u5219\u4fee\u6539\/etc\/issue\u6587\u4ef6\u5185\u5bb9\u4e3aProduction\u3002<\/p><\/blockquote>\n

\u6839\u636e\u886816-5\u6240\u63d0\u53ca\u7684Ansible\u5e38\u7528\u6a21\u5757\u540d\u79f0\u53ca\u4f5c\u7528\uff0c\u53ef\u4ee5\u770b\u5230copy\u6a21\u5757\u7684\u4e3b\u8981\u4f5c\u7528\u662f\u65b0\u5efa\u3001\u4fee\u6539\u53ca\u590d\u5236\u6587\u4ef6\uff0c\u66f4\u7b26\u5408\u5f53\u524d\u7684\u9700\u8981\uff0c\u6b64\u65f6\u4fbf\u6d3e\u4e0a\u4e86\u7528\u573a\u3002\u5148\u67e5\u8be2copy\u6a21\u5757\u7684\u5e2e\u52a9\u4fe1\u606f\uff1a<\/p>\n

[root@linuxprobe ~]# ansible-doc copy\r\n> COPY    (\/usr\/lib\/python3.6\/site-packages\/ansible\/modules\/files\/copy.py)\r\n\r\n        The `copy' module copies a file from the local or remote\r\n        machine to a location on the remote machine. Use the [fetch]\r\n        module to copy files from remote locations to the local box.\r\n        If you need variable interpolation in copied files, use the\r\n        [template] module. Using a variable in the `content' field\r\n        will result in unpredictable output. For Windows targets, use\r\n        the [win_copy] module instead.\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: Copy file with owner and permissions\r\n  copy:\r\n    src: \/srv\/myfiles\/foo.conf\r\n    dest: \/etc\/foo.conf\r\n    owner: foo\r\n    group: foo\r\n    mode: '0644'\r\n\r\n- name: Copy using inline content\r\n  copy:\r\n    content: '# This file was moved to \/etc\/other.conf'\r\n    dest: \/etc\/mine.conf\r\n<\/pre>\n

\u5728\u8f93\u51fa\u4fe1\u606f\u4e2d\u5217\u4e3e\u4e86\u4e24\u79cd\u7ba1\u7406\u6587\u4ef6\u5185\u5bb9\u7684\u793a\u4f8b\u3002\u7b2c\u4e00\u79cd\u7528\u4e8e\u6587\u4ef6\u7684\u590d\u5236\u884c\u4e3a\uff0c\u7b2c\u4e8c\u79cd\u662f\u901a\u8fc7content\u53c2\u6570\u5b9a\u4e49\u5185\u5bb9\uff0c\u901a\u8fc7dest\u53c2\u6570\u6307\u5b9a\u65b0\u5efa\u6587\u4ef6\u7684\u540d\u79f0\u3002\u663e\u7136\uff0c\u7b2c\u4e8c\u79cd\u66f4\u52a0\u7b26\u5408\u5f53\u524d\u7684\u5b9e\u9a8c\u573a\u666f\u3002\u7f16\u5199\u5267\u672c\u6587\u4ef6\u5982\u4e0b\uff1a<\/p>\n

[root@linuxprobe ~]# vim issue.yml\r\n---\r\n- name: \u4fee\u6539\u6587\u4ef6\u5185\u5bb9\r\n  hosts: all\r\n  tasks:\r\n          - name: one\r\n            copy:\r\n                    content: 'Development'\r\n                    dest: \/etc\/issue\r\n          - name: two\r\n            copy:\r\n                    content: 'Test'\r\n                    dest: \/etc\/issue\r\n          - name: three\r\n            copy:\r\n                    content: 'Production'\r\n                    dest: \/etc\/issue\r\n<\/pre>\n

\u4f46\u662f\uff0c\u5982\u679c\u6309\u7167\u8fd9\u79cd\u987a\u5e8f\u6267\u884c\u4e0b\u53bb\uff0c\u6bcf\u4e00\u53f0\u4e3b\u673a\u7684\/etc\/issue\u6587\u4ef6\u90fd\u4f1a\u88ab\u91cd\u590d\u4fee\u65393\u6b21\uff0c\u6700\u7ec8\u5b9a\u683c\u5728\u201cProduction\u201d\u5b57\u6837\uff0c\u8fd9\u663e\u7136\u7f3a\u5c11\u4e86\u4e00\u4e9b\u4e1c\u897f\u3002\u6211\u4eec\u5e94\u8be5\u4f9d\u636einventory_hostname\u53d8\u91cf\u4e2d\u7684\u503c\u8fdb\u884c\u5224\u65ad\u3002\u82e5\u4e3b\u673a\u4e3adev\u7ec4\uff0c\u5219\u6267\u884c\u7b2c\u4e00\u4e2a\u52a8\u4f5c\uff1b\u82e5\u4e3b\u673a\u4e3atest\u7ec4\uff0c\u5219\u6267\u884c\u7b2c\u4e8c\u4e2a\u52a8\u4f5c\uff1b\u82e5\u4e3b\u673a\u4e3aprod\u7ec4\uff0c\u5219\u6267\u884c\u7b2c\u4e09\u4e2a\u52a8\u4f5c\u3002\u56e0\u6b64\uff0c\u8981\u8fdb\u884c3\u6b21\u5224\u65ad\u3002<\/p>\n

when\u662f\u7528\u4e8e\u5224\u65ad\u7684\u8bed\u6cd5\uff0c\u5c06\u5176\u7528\u5728\u6bcf\u4e2a\u52a8\u4f5c\u7684\u4e0b\u65b9\u8fdb\u884c\u5224\u65ad\uff0c\u4f7f\u5f97\u53ea\u6709\u5728\u6ee1\u8db3\u6761\u4ef6\u624d\u4f1a\u6267\u884c\uff1a<\/p>\n

[root@linuxprobe ~]# vim issue.yml\r\n---\r\n- name: \u4fee\u6539\u6587\u4ef6\u5185\u5bb9\r\n  hosts: all\r\n  tasks:\r\n          - name: one\r\n            copy:\r\n                    content: 'Development'\r\n                    dest: \/etc\/issue\r\n            when: \"inventory_hostname in groups.dev\"<\/strong>\r\n          - name: two\r\n            copy:\r\n                    content: 'Test'\r\n                    dest: \/etc\/issue\r\n            when: \"inventory_hostname in groups.test\"<\/strong>\r\n          - name: three\r\n            copy:\r\n                    content: 'Production'\r\n                    dest: \/etc\/issue\r\n            when: \"inventory_hostname in groups.prod\"\r\n<\/strong><\/pre>\n

\u6267\u884c\u5267\u672c\u6587\u4ef6\uff0c\u5728\u8fc7\u7a0b\u4e2d\u53ef\u6e05\u6670\u5730\u770b\u5230\u7531\u4e8ewhen\u8bed\u6cd5\u7684\u4f5c\u7528\uff0c\u672a\u5728\u6307\u5b9a\u4e3b\u673a\u7ec4\u4e2d\u7684\u4e3b\u673a\u5c06\u88ab\u8df3\u8fc7\uff08skipping\uff09\uff1a<\/p>\n

[root@linuxprobe ~]# ansible-playbook issue.yml \r\n\r\nPLAY [\u4fee\u6539\u6587\u4ef6\u5185\u5bb9] ************************************************************************\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\nok: [192.168.10.24]\r\n\r\nTASK [one] ********************************************************************************\r\nchanged: [192.168.10.20]\r\nskipping: [192.168.10.21]\r\nskipping: [192.168.10.22]\r\nskipping: [192.168.10.23] \r\nskipping: [192.168.10.24]\r\n\r\nTASK [two] ********************************************************************************\r\nskipping: [192.168.10.20]\r\nchanged: [192.168.10.21]\r\nskipping: [192.168.10.23]\r\nskipping: [192.168.10.24]\r\nskipping: [192.168.10.25]\r\n\r\nTASK [three] ******************************************************************************\r\nskipping: [192.168.10.20]\r\nskipping: [192.168.10.21]\r\nchanged: [192.168.10.22]\r\nchanged: [192.168.10.23]\r\nskipping: [192.168.10.24]\r\n\r\nPLAY RECAP ********************************************************************************\r\n192.168.10.20   : ok=2  changed=1  unreachable=0  failed=0  skipped=2  rescued=0  ignored=0   \r\n192.168.10.21   : ok=2  changed=1  unreachable=0  failed=0  skipped=2  rescued=0  ignored=0   \r\n192.168.10.22   : ok=2  changed=1  unreachable=0  failed=0  skipped=2  rescued=0  ignored=0   \r\n192.168.10.23   : ok=2  changed=1  unreachable=0  failed=0  skipped=2  rescued=0  ignored=0 \r\n192.168.10.24   : ok=1  changed=0  unreachable=0  failed=0  skipped=3  rescued=0  ignored=0 \r\n<\/pre>\n

\u767b\u5f55\u5230dev\u7ec4\u7684192.168.10.20\u4e3b\u673a\u4e0a\uff0c\u67e5\u770b\u6587\u4ef6\u5185\u5bb9\uff1a<\/p>\n

[root@linuxprobe ~]# cat \/etc\/issue \r\nDevelopment<\/pre>\n

\u767b\u5f55\u5230test\u7ec4\u7684192.168.10.21\u4e3b\u673a\u4e0a\uff0c\u67e5\u770b\u6587\u4ef6\u5185\u5bb9\uff1a<\/p>\n

[root@linuxprobe ~]# cat \/etc\/issue \r\nTest<\/pre>\n

\u767b\u5f55\u5230prod\u7ec4\u7684192.168.10.22\/23\u4e3b\u673a\u4e0a\uff0c\u67e5\u770b\u6587\u4ef6\u5185\u5bb9\uff1a<\/p>\n

[root@linuxprobe ~]# cat \/etc\/issue \r\nProduction<\/pre>\n
16.8 \u7ba1\u7406\u6587\u4ef6\u5c5e\u6027<\/span><\/strong><\/h5>\n

\u6211\u4eec\u5b66\u4e60\u5267\u672c\u7684\u76ee\u7684\u662f\u4e3a\u4e86\u6ee1\u8db3\u65e5\u5e38\u7684\u5de5\u4f5c\u9700\u6c42\uff0c\u628a\u91cd\u590d\u7684\u4e8b\u60c5\u5199\u5165\u5230\u811a\u672c\u4e2d\uff0c\u7136\u540e\u518d\u6279\u91cf\u6267\u884c\u4e0b\u53bb\uff0c\u4ece\u800c\u63d0\u9ad8\u8fd0\u7ef4\u5de5\u4f5c\u7684\u6548\u7387\u3002\u5176\u4e2d\uff0c\u521b\u5efa\u6587\u4ef6\u3001\u7ba1\u7406\u6743\u9650\u4ee5\u53ca\u8bbe\u7f6e\u5feb\u6377\u65b9\u5f0f\u51e0\u4e4e\u662f\u6bcf\u5929\u90fd\u7528\u5230\u7684\u6280\u80fd\u3002\u5c24\u5176\u662f\u5728\u7b2c5\u7ae0\u5b66\u4e60\u6587\u4ef6\u7684\u4e00\u822c\u6743\u9650\u3001\u7279\u6b8a\u6743\u9650\u3001\u9690\u85cf\u6743\u9650\u65f6\uff0c\u5f80\u5f80\u8fd8\u4f1a\u56e0\u547d\u4ee4\u7684\u683c\u5f0f\u95ee\u9898\u800c\u5bfc\u81f4\u51fa\u9519\u3002\u8fd9\u4e48\u591a\u547d\u4ee4\u8be5\u600e\u4e48\u8bb0\u5462\uff1f<\/p>\n

Ansible\u670d\u52a1\u5c06\u5e38\u7528\u7684\u6587\u4ef6\u7ba1\u7406\u529f\u80fd\u90fd\u5408\u5e76\u5230\u4e86file\u6a21\u5757\u4e2d\uff0c\u5927\u5bb6\u4e0d\u7528\u518d\u4e3a\u4e86\u5bfb\u627e\u6a21\u5757\u800c\u201c\u4e1c\u5954\u897f\u8dd1\u201d\u4e86\u3002\u5148\u6765\u770b\u4e00\u4e0bfile\u6a21\u5757\u7684\u5e2e\u52a9\u4fe1\u606f\uff1a<\/p>\n

[root@linuxprobe ~]# ansible-doc file\r\n> FILE    (\/usr\/lib\/python3.6\/site-packages\/ansible\/modules\/files\/file.py)\r\n\r\n        Set attributes of files, symlinks or directories.\r\n        Alternatively, remove files, symlinks or directories. Many\r\n        other modules support the same options as the `file' module -\r\n        including [copy], [template], and [assemble]. For Windows\r\n        targets, use the [win_file] module 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: Change file ownership, group and permissions\r\n  file:\r\n    path: \/etc\/foo.conf\r\n    owner: foo\r\n    group: foo\r\n    mode: '0644'\r\n\r\n- name: Create a symbolic link\r\n  file:\r\n    src: \/file\/to\/link\/to\r\n    dest: \/path\/to\/symlink\r\n    owner: foo\r\n    group: foo\r\n    state: link\r\n\r\n- name: Create a directory if it does not exist\r\n  file:\r\n    path: \/etc\/some_directory\r\n    state: directory\r\n    mode: '0755'\r\n\r\n- name: Remove file (delete file)\r\n  file:\r\n    path: \/etc\/foo.txt\r\n    state: absent<\/pre>\n

\u901a\u8fc7\u4e0a\u9762\u7684\u8f93\u51fa\u793a\u4f8b\uff0c\u5927\u5bb6\u5df2\u7ecf\u80fd\u591f\u4e86\u89e3file\u6a21\u5757\u7684\u57fa\u672c\u53c2\u6570\u4e86\u3002\u5176\u4e2d\uff0cpath\u53c2\u6570\u5b9a\u4e49\u4e86\u6587\u4ef6\u7684\u8def\u5f84\uff0cowner\u53c2\u6570\u5b9a\u4e49\u4e86\u6587\u4ef6\u6240\u6709\u8005\uff0cgroup\u53c2\u6570\u5b9a\u4e49\u4e86\u6587\u4ef6\u6240\u5c5e\u7ec4\uff0cmode\u53c2\u6570\u5b9a\u4e49\u4e86\u6587\u4ef6\u6743\u9650\uff0csrc\u53c2\u6570\u5b9a\u4e49\u4e86\u6e90\u6587\u4ef6\u7684\u8def\u5f84\uff0cdest\u53c2\u6570\u5b9a\u4e49\u4e86\u76ee\u6807\u6587\u4ef6\u7684\u8def\u5f84\uff0cstate\u53c2\u6570\u5219\u5b9a\u4e49\u4e86\u6587\u4ef6\u7c7b\u578b\u3002<\/p>\n

\u53ef\u89c1\uff0cfile\u6a21\u5757\u57fa\u672c\u4e0a\u628a\u7b2c5\u7ae0\u5b66\u4e60\u8fc7\u7684\u7ba1\u7406\u6587\u4ef6\u6743\u9650\u7684\u529f\u80fd\u90fd\u5305\u542b\u5728\u5185\u4e86\u3002\u6211\u4eec\u73b0\u5728\u6765\u6311\u6218\u4e0b\u9762\u7684\u5b9e\u9a8c\u5427\uff1a<\/p>\n

\u8bf7\u521b\u5efa\u51fa\u4e00\u4e2a\u540d\u4e3a\/linuxprobe\u7684\u65b0\u76ee\u5f55\uff0c\u6240\u6709\u8005\u53ca\u6240\u5c5e\u7ec4\u5747\u4e3aroot\u7ba1\u7406\u5458\u8eab\u4efd\uff1b<\/p>\n

\u8bbe\u7f6e\u6240\u6709\u8005\u548c\u6240\u5c5e\u4e8e\u7ec4\u62e5\u6709\u5bf9\u6587\u4ef6\u7684\u5b8c\u5168\u63a7\u5236\u6743\uff0c\u800c\u5176\u4ed6\u4eba\u5219\u53ea\u6709\u9605\u8bfb\u548c\u6267\u884c\u6743\u9650\uff1b<\/p>\n

\u7ed9\u4e88SGID\u7279\u6b8a\u6743\u9650\uff1b<\/p>\n

\u4ec5\u5728dev\u4e3b\u673a\u7ec4\u7684\u4e3b\u673a\u4e0a\u5b9e\u65bd\u3002<\/p><\/blockquote>\n

\u7b2c\u4e8c\u6761\u8981\u6c42\u662f\u7b97\u672f\u9898\uff0c\u5373\u5c06\u6743\u9650\u63cf\u8ff0\u8f6c\u6362\u4e3a\u6570\u5b57\u8868\u793a\u6cd5\uff0c\u5373\u53ef\u8bfb\u4e3a4\u3001\u53ef\u5199\u4e3a2\u3001\u53ef\u6267\u884c\u4e3a1\u3002\u5927\u5bb6\u5148\u81ea\u884c\u9ed8\u9ed8\u8ba1\u7b97\u4e00\u4e0b\u7b54\u6848\u3002\u6b64\u524d\u5728\u7f16\u5199\u5267\u672c\u6587\u4ef6\u65f6\uff0chosts\u53c2\u6570\u5bf9\u5e94\u7684\u4e00\u76f4\u662fall\uff0c\u5373\u5168\u4f53\u4e3b\u673a\uff0c\u8fd9\u6b21\u9700\u8981\u4fee\u6539\u4e3a\u4ec5\u5bf9dev\u4e3b\u673a\u7ec4\u6210\u5458\u751f\u6548\uff0c\u8bf7\u5c0f\u5fc3\u8c28\u614e\u3002\u7f16\u5199\u6a21\u5757\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n

[root@linuxprobe ~]# vim chmod.yml\r\n---\r\n- name: \u7ba1\u7406\u6587\u4ef6\u5c5e\u6027\r\n  hosts: dev\r\n  tasks:\r\n          - name: one\r\n            file:\r\n                    path: \/linuxprobe\r\n                    state: directory \r\n                    owner: root\r\n                    group: root\r\n                    mode: '2775'\r\n<\/pre>\n

\u4e00\u4e0d\u5c0f\u5fc3\u628a\u9898\u76ee\u51fa\u7b80\u5355\u4e86\uff0c\u8fd9\u91cc\u6ca1\u80fd\u5b8c\u5168\u5c55\u793a\u51fafile\u6a21\u5757\u7684\u5f3a\u5927\u4e4b\u5904\u3002\u6211\u4eec\u4e34\u65f6\u6dfb\u52a0\u4e00\u4e2a\u9700\u6c42\uff1a\u8bf7\u518d\u521b\u5efa\u4e00\u4e2a\u540d\u79f0\u4e3a\/linuxcool\u7684\u5feb\u6377\u65b9\u5f0f\u6587\u4ef6\uff0c\u6307\u5411\u521a\u521a\u5efa\u7acb\u7684\/linuxprobe\u76ee\u5f55\u3002\u8fd9\u6837\u7528\u6237\u5728\u8bbf\u95ee\u4e24\u4e2a\u76ee\u5f55\u65f6\u5c31\u80fd\u6709\u76f8\u540c\u7684\u5185\u5bb9\u4e86\u3002\u5728\u4f7f\u7528file\u6a21\u5757\u8bbe\u7f6e\u5feb\u6377\u65b9\u5f0f\u65f6\uff0c\u4e0d\u9700\u8981\u518d\u5355\u72ec\u521b\u5efa\u76ee\u6807\u6587\u4ef6\uff0cAnsible\u670d\u52a1\u4f1a\u5e2e\u6211\u4eec\u5b8c\u6210\uff1a<\/p>\n

[root@linuxprobe ~]# vim chmod.yml\r\n---\r\n- name: \u7ba1\u7406\u6587\u4ef6\u5c5e\u6027\r\n  hosts: dev\r\n  tasks:\r\n          - name: one\r\n            file:\r\n                    path: \/linuxprobe\r\n                    state: directory \r\n                    owner: root\r\n                    group: root\r\n                    mode: '2775'\r\n          - name: two\r\n            file:\r\n                    src: \/linuxprobe\r\n                    dest: \/linuxcool\r\n                    state: link<\/strong>\r\n<\/pre>\n

\u5267\u672c\u6587\u4ef6\u7684\u6267\u884c\u8fc7\u7a0b\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n

[root@linuxprobe ~]# ansible-playbook chmod.yml \r\n\r\nPLAY [\u7ba1\u7406\u6587\u4ef6\u5c5e\u6027] ***************************************************************\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\nok: [192.168.10.24]\r\n\r\nTASK [one] ***********************************************************************\r\nchanged: [192.168.10.20]\r\nskipping: [192.168.10.21]\r\nskipping: [192.168.10.22]\r\nskipping: [192.168.10.23]\r\nskipping: [192.168.10.24]\r\n\r\nTASK [two] ***********************************************************************\r\nchanged: [192.168.10.20]\r\nskipping: [192.168.10.21]\r\nskipping: [192.168.10.22]\r\nskipping: [192.168.10.23]\r\nskipping: [192.168.10.24]\r\n\r\nPLAY RECAP ***********************************************************************\r\n192.168.10.20   : ok=3  changed=2  unreachable=0  failed=0  skipped=0  rescued=0  ignored=0   \r\n192.168.10.22   : ok=1  changed=0  unreachable=0  failed=0  skipped=3  rescued=0  ignored=0\r\n192.168.10.22   : ok=1  changed=0  unreachable=0  failed=0  skipped=3  rescued=0  ignored=0\r\n192.168.10.22   : ok=1  changed=0  unreachable=0  failed=0  skipped=3  rescued=0  ignored=0\r\n192.168.10.22   : ok=1  changed=0  unreachable=0  failed=0  skipped=3  rescued=0  ignored=0\r\n<\/pre>\n

\u8fdb\u5165\u5230dev\u7ec4\u7684\u4e3b\u673a\u4e2d\uff0c\u770b\u5230\/linuxprobe\u76ee\u5f55\u53ca\/linuxcool\u7684\u5feb\u6377\u65b9\u5f0f\u5747\u5df2\u7ecf\u88ab\u987a\u5229\u521b\u5efa\uff1a<\/p>\n

[root@linuxprobe ~]# ls -ld \/linuxprobe\r\ndrwxrwsr-x. 2 root root 6 Apr 20 09:52 \/linuxprobe\r\n[root@linuxprobe ~]# ls -ld \/linuxcool\r\nlrwxrwxrwx. 1 root root 11 Apr 20 09:52 \/linuxcool -> \/linuxprobe\r\n<\/pre>\n
16.9 \u7ba1\u7406\u5bc6\u7801\u5e93\u6587\u4ef6<\/span><\/strong><\/h5>\n

\u81eaAnsible 1.5\u7248\u672c\u53d1\u5e03\u540e\uff0cvault\u4f5c\u4e3a\u4e00\u9879\u65b0\u529f\u80fd\u8fdb\u5165\u5230\u4e86\u8fd0\u7ef4\u4eba\u5458\u7684\u89c6\u91ce\u3002\u5b83\u4e0d\u4ec5\u80fd\u5bf9\u5bc6\u7801\u3001\u5267\u672c\u7b49\u654f\u611f\u4fe1\u606f\u8fdb\u884c\u52a0\u5bc6\uff0c\u800c\u4e14\u8fd8\u80fd\u52a0\u5bc6\u53d8\u91cf\u540d\u79f0\u548c\u53d8\u91cf\u503c\uff0c\u4ece\u800c\u786e\u4fdd\u6570\u636e\u4e0d\u4f1a\u88ab\u4ed6\u4eba\u8f7b\u6613\u9605\u8bfb\u3002\u4f7f\u7528ansible-vault\u547d\u4ee4\u53ef\u4ee5\u5b9e\u73b0\u5185\u5bb9\u7684\u65b0\u5efa\uff08create\uff09\u3001\u52a0\u5bc6\uff08encrypt\uff09\u3001\u89e3\u5bc6\uff08decrypt\uff09\u3001\u4fee\u6539\u5bc6\u7801\uff08rekey\uff09\u53ca\u67e5\u770b\uff08view\uff09\u7b49\u529f\u80fd\u3002<\/p>\n

\u4e0b\u9762\u901a\u8fc7\u793a\u4f8b\u6765\u5b66\u4e60vault\u7684\u5177\u4f53\u7528\u6cd5\u3002<\/p>\n

\u7b2c1\u6b65\uff1a\u521b\u5efa\u51fa\u4e00\u4e2a\u540d\u4e3alocker.yml\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u5176\u4e2d\u4fdd\u5b58\u4e86\u4e24\u4e2a\u53d8\u91cf\u503c\uff1a<\/p>\n<\/div>\n

\n
[root@linuxprobe ~]# vim locker.yml\r\n---\r\npw_developer: Imadev\r\npw_manager: Imamgr<\/pre>\n

\u7b2c2\u6b65\uff1a\u4f7f\u7528ansible-vault\u547d\u4ee4\u5bf9\u6587\u4ef6\u8fdb\u884c\u52a0\u5bc6\u3002\u7531\u4e8e\u9700\u8981\u6bcf\u6b21\u8f93\u5165\u5bc6\u7801\u6bd4\u8f83\u9ebb\u70e6\uff0c\u56e0\u6b64\u8fd8\u5e94\u65b0\u5efa\u4e00\u4e2a\u7528\u4e8e\u4fdd\u5b58\u5bc6\u7801\u503c\u7684\u6587\u672c\u6587\u4ef6\uff0c\u4ee5\u4fbf\u8ba9ansible-vault\u547d\u4ee4\u81ea\u52a8\u8c03\u7528\u3002\u4e3a\u4e86\u4fdd\u8bc1\u6570\u636e\u7684\u5b89\u5168\u6027\uff0c\u5728\u65b0\u5efa\u5bc6\u7801\u6587\u4ef6\u540e\u5c06\u8be5\u6587\u4ef6\u7684\u6743\u9650\u8bbe\u7f6e\u4e3a600\uff0c\u786e\u4fdd\u4ec5\u7ba1\u7406\u5458\u53ef\u8bfb\u53ef\u5199\uff1a<\/p>\n

[root@linuxprobe ~]# vim \/root\/secret.txt\r\nwhenyouwishuponastar\r\n[root@linuxprobe ~]# chmod 600 \/root\/secret.txt\r\n<\/pre>\n

\u5728Ansible\u670d\u52a1\u7684\u4e3b\u914d\u7f6e\u6587\u4ef6\u4e2d\uff0c\u5728\u7b2c140\u884c\u7684vault_password_file\u53c2\u6570\u540e\u6307\u5b9a\u5bc6\u7801\u503c\u4fdd\u5b58\u7684\u6587\u4ef6\u8def\u5f84\uff0c\u51c6\u5907\u8fdb\u884c\u8c03\u7528\uff1a<\/p>\n

[root@linuxprobe ~]# vim \/etc\/ansible\/ansible.cfg\r\n137 \r\n138 # If set, configures the path to the Vault password file as an alternative to\r\n139 # specifying --vault-password-file on the command line.\r\n140 vault_password_file = \/root\/secret.txt\r\n141 \r\n<\/pre>\n

\u7b2c3\u6b65\uff1a\u5728\u8bbe\u7f6e\u597d\u5bc6\u7801\u6587\u4ef6\u7684\u8def\u5f84\u540e\uff0cAnsible\u670d\u52a1\u4fbf\u4f1a\u81ea\u52a8\u8fdb\u884c\u52a0\u8f7d\u3002\u7528\u6237\u4e5f\u5c31\u4e0d\u7528\u5728\u6bcf\u6b21\u52a0\u5bc6\u6216\u89e3\u5bc6\u65f6\u90fd\u91cd\u590d\u8f93\u5165\u5bc6\u7801\u4e86\u3002\u4f8b\u5982\uff0c\u5728\u52a0\u5bc6\u521a\u521a\u521b\u5efa\u7684locker.yml\u6587\u4ef6\u65f6\uff0c\u53ea\u9700\u8981\u4f7f\u7528encrypt\u53c2\u6570\u5373\u53ef\uff1a<\/p>\n

[root@linuxprobe ~]# ansible-vault encrypt locker.yml\r\nEncryption successful\r\n<\/pre>\n

\u6587\u4ef6\u5c06\u4f7f\u7528AES 256\u52a0\u5bc6\u65b9\u5f0f\u8fdb\u884c\u52a0\u5bc6\uff0c\u4e5f\u5c31\u662f\u610f\u5473\u7740\u5bc6\u94a5\u67092256<\/sup>\u79cd\u53ef\u80fd\u3002\u67e5\u770b\u5230\u52a0\u5bc6\u540e\u7684\u5185\u5bb9\u4e3a\uff1a<\/p>\n

[root@linuxprobe ~]# cat locker.yml \r\n$ANSIBLE_VAULT;1.1;AES256\r\n38653234313839336138383931663837333533396161343730353530313038313631653439366335\r\n3432346333346239386334663836643432353434373733310a306662303565633762313232663763\r\n38366334316239376262656230643531656665376166663635656436363338626464333430343162\r\n6664643035316133650a333331393538616130656136653630303239663561663237373733373638\r\n62383234303061623865633466336636363961623039343236356336356361613736333739623961\r\n6334303865663838623363333339396637363061626363383266\r\n<\/pre>\n

\u5982\u679c\u4e0d\u60f3\u4f7f\u7528\u539f\u59cb\u5bc6\u7801\u4e86\u5462\uff1f\u4e5f\u53ef\u4ee5\u4f7f\u7528rekey\u53c2\u6570\u624b\u52a8\u5bf9\u6587\u4ef6\u8fdb\u884c\u6539\u5bc6\u64cd\u4f5c\uff0c\u540c\u65f6\u5e94\u7ed3\u5408--ask-vault-pass\u53c2\u6570\u8fdb\u884c\u4fee\u6539\uff0c\u5426\u5219Ansible\u670d\u52a1\u4f1a\u56e0\u63a5\u6536\u4e0d\u5230\u7528\u6237\u8f93\u5165\u7684\u65e7\u5bc6\u7801\u503c\u800c\u62d2\u7edd\u65b0\u7684\u5bc6\u7801\u53d8\u66f4\u8bf7\u6c42\uff1a<\/p>\n

[root@linuxprobe ~]# ansible-vault rekey --ask-vault-pass locker.yml \r\nVault password: \u8f93\u5165\u65e7\u7684\u5bc6\u7801<\/strong>\r\nNew Vault password: \u8f93\u5165\u65b0\u7684\u5bc6\u7801<\/strong>\r\nConfirm New Vault password: \u518d\u8f93\u5165\u65b0\u7684\u5bc6\u7801<\/strong>\r\nRekey successful\r\n<\/pre>\n

\u7b2c4\u6b65\uff1a\u5982\u679c\u60f3\u67e5\u770b\u548c\u4fee\u6539\u52a0\u5bc6\u6587\u4ef6\u4e2d\u7684\u5185\u5bb9\uff0c\u8be5\u600e\u4e48\u64cd\u4f5c\u5462\uff1f\u5bf9\u4e8e\u5df2\u7ecf\u52a0\u5bc6\u8fc7\u7684\u6587\u4ef6\uff0c\u9700\u8981\u4f7f\u7528ansible-vault\u547d\u4ee4\u7684edit\u53c2\u6570\u8fdb\u884c\u4fee\u6539\uff0c\u968f\u540e\u7528view\u53c2\u6570\u5373\u53ef\u67e5\u770b\u5230\u4fee\u6539\u540e\u7684\u5185\u5bb9\u3002ansible-vault\u547d\u4ee4\u5bf9\u52a0\u5bc6\u6587\u4ef6\u7684\u7f16\u8f91\u64cd\u4f5c\u9ed8\u8ba4\u4f7f\u7528\u7684\u662fVim\u7f16\u8f91\u5668\uff0c\u5728\u4fee\u6539\u5b8c\u6bd5\u540e\u8bf7\u8bb0\u5f97\u6267\u884cwq\u64cd\u4f5c\u4fdd\u5b58\u540e\u9000\u51fa\uff1a<\/p>\n

[root@linuxprobe ~]# ansible-vault edit locker.yml\r\n---\r\npw_developer: Imadev\r\npw_manager: Imamgr\r\npw_production: Imaprod\r\n<\/pre>\n

\u6700\u540e\uff0c\u518d\u7528view\u53c2\u6570\u8fdb\u884c\u67e5\u770b\uff0c\u4fbf\u662f\u6700\u65b0\u7684\u5185\u5bb9\u4e86\uff1a<\/p>\n

[root@linuxprobe ~]# ansible-vault view locker.yml\r\nVault password: \u8f93\u5165\u5bc6\u7801\u540e\u6572\u51fb\u56de\u8f66\u786e\u8ba4<\/strong>\r\n--- \r\npw_developer: Imadev \r\npw_manager: Imamgr \r\npw_production: Imaprod<\/pre>\n

\u51fa\u73b0\u95ee\u9898?\u5927\u80c6\u63d0\u95ee!<\/strong><\/span><\/p>\n

\u56e0\u8bfb\u8005\u4eec\u786c\u4ef6\u4e0d\u540c\u6216\u64cd\u4f5c\u9519\u8bef\u90fd\u53ef\u80fd\u5bfc\u81f4\u5b9e\u9a8c\u914d\u7f6e\u51fa\u9519\uff0c\u8bf7\u8010\u5fc3\u518d\u4ed4\u7ec6\u770b\u770b\u64cd\u4f5c\u6b65\u9aa4\u5427\uff0c\u4e0d\u8981\u6c14\u9981~<\/p>\n

Linux\u6280\u672f\u4ea4\u6d41\u5b66\u4e60\u8bf7\u52a0\u8bfb\u8005\u7fa4\uff08\u63a8\u8350<\/span><\/strong>\uff09\uff1ahttps:\/\/lrxjmw.cn\/club<\/a><\/p>\n

*\u672c\u7fa4\u7279\u8272\uff1a\u786e\u4fdd\u6bcf\u4e00\u4f4d\u7fa4\u53cb\u90fd\u662f\u300aLinux\u5c31\u8be5\u8fd9\u4e48\u5b66\u300b\u7684\u8bfb\u8005\uff0c\u7b54\u7591\u66f4\u6709\u9488\u5bf9\u6027\uff0c\u4e0d\u5b9a\u671f\u9886\u53d6\u5b9a\u5236\u793c\u54c1\u3002<\/p><\/blockquote>\n

\u672c\u7ae0\u8282\u7684\u590d\u4e60\u4f5c\u4e1a<\/span>(\u7b54\u6848\u5c31\u5728\u95ee\u9898\u7684\u4e0b\u4e00\u884c\u54e6\uff0c\u7528\u9f20\u6807\u9009\u4e2d\u5373\u53ef\u770b\u5230\u7684~)<\/strong><\/span><\/p>\n

1\uff0e\u5f53\u524d\u5df2\u7ecf\u642d\u5efa\u597d\u8f6f\u4ef6\u4ed3\u5e93\uff0c\u4f46\u5374\u4e0d\u80fd\u7528dnf\u547d\u4ee4\u5b89\u88c5Ansible\u670d\u52a1\u3002\u8fd9\u6709\u53ef\u80fd\u662f\u4ec0\u4e48\u539f\u56e0\u5462\uff1f<\/p>\n

\u7b54\uff1a<\/strong>RHEL 10\u7cfb\u7edf\u4e2d\u9ed8\u8ba4\u7684BaseOS\u548cAppStream\u8f6f\u4ef6\u4ed3\u5e93\u4e0d\u5305\u542bAnsible\u670d\u52a1\u8f6f\u4ef6\u5305\uff0c\u9700\u8981\u989d\u5916\u914d\u7f6eEPEL\u5b89\u88c5\u6e90\u3002<\/span><\/p>\n

2\uff0e\u5f53\/etc\/ansible\/ansible.cfg\u4e0e\uff5e\/.ansible.cfg\u4e24\u4e2a\u4e3b\u914d\u7f6e\u6587\u4ef6\u90fd\u540c\u65f6\u5b58\u5728\u65f6\uff0c\u4ee5\u54ea\u4e2a\u4e3a\u51c6\uff1f<\/p>\n

\u7b54\uff1a<\/strong>\u4e2a\u4eba\u5bb6\u76ee\u5f55\u4e2d\u7684\u4e3b\u914d\u7f6e\u6587\u4ef6\u7684\u4f18\u5148\u7ea7\u66f4\u9ad8\u3002<\/span><\/p>\n

3\uff0e\u4f7f\u7528Ansible\u7684\u54ea\u4e2a\u6a21\u5757\u80fd\u542f\u52a8\u670d\u52a1\uff0c\u4f7f\u7528Ansbile\u7684\u54ea\u4e2a\u6a21\u5757\u80fd\u6302\u8f7d\u786c\u76d8\u8bbe\u5907\u6587\u4ef6\uff1f<\/p>\n

\u7b54\uff1a<\/strong>\u4f7f\u7528service\u6a21\u5757\u542f\u52a8\u670d\u52a1\uff0c\u4f7f\u7528mount\u6a21\u5757\u6302\u8f7d\u8bbe\u5907\u6587\u4ef6\u3002<\/span><\/p>\n

4\uff0e\u6211\u4eec\u60f3\u4e86\u89e3\u4e00\u4e2a\u6a21\u5757\u7684\u4f5c\u7528\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ec0\u4e48\u547d\u4ee4\u6765\u67e5\u8be2\u5b83\u7684\u5e2e\u52a9\u4fe1\u606f\uff1f<\/p>\n

\u7b54\uff1a<\/strong>\u53ef\u4ee5\u4f7f\u7528ansible-doc\u547d\u4ee4\u67e5\u8be2\u6a21\u5757\u7684\u5e2e\u52a9\u4fe1\u606f\u3002<\/span><\/p>\n

5\uff0eAnsible\u89d2\u8272\u6709\u51e0\u79cd\u83b7\u53d6\u65b9\u6cd5\uff1f<\/p>\n

\u7b54\uff1a<\/strong>\u67093\u79cd\uff0c\u5206\u522b\u662f\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<\/span><\/p>\n

6\uff0e\u5728\u6267\u884c\u5267\u672c\u6587\u4ef6\u65f6\uff0c\u51fa\u73b0\u4e86\u9ec4\u8272\u663e\u793a\u7684changed\u5b57\u6837\uff0c\u8fd9\u8868\u793a\u4ec0\u4e48\u610f\u601d\uff1f<\/p>\n

\u7b54\uff1a<\/strong>\u8868\u793a\u5267\u672c\u6587\u4ef6\u6267\u884c\u6210\u529f\u5e76\u8fdb\u884c\u4e86\u4fee\u6539\u3002<\/span><\/p>\n

7\uff0eJinja2\u4e0ecopy\u590d\u5236\u6a21\u5757\u6709\u4ec0\u4e48\u533a\u522b\uff1f<\/p>\n

\u7b54\uff1a<\/strong>Copy\u6a21\u5757\u662f\u4e00\u6bd4\u4e00\u7684\u590d\u5236\uff0c\u6e90\u6587\u4ef6\u4e0e\u76ee\u6807\u6587\u4ef6\u5185\u5bb9\u5b8c\u5168\u76f8\u540c\u3002\u800cJinja2\u5219\u4f1a\u5c06\u6e90\u6587\u4ef6\u4e2d\u7684\u53d8\u91cf\u540d\u66ff\u6362\u6210\u53d7\u63a7\u8282\u70b9\u4e0a\u7684\u5b9e\u9645\u53d8\u91cf\u503c\u3002<\/span><\/p>\n

8\uff0e\u60f3\u8981\u8ba9\u5267\u672c\u5185\u5bb9\u5bf9\u4e3b\u673a\u6e05\u5355\u4e2d\u6240\u6709\u53d7\u63a7\u8282\u70b9\u90fd\u751f\u6548\uff0c\u5e94\u5982\u4f55\u64cd\u4f5c\uff1f<\/p>\n

\u7b54\uff1a<\/strong>\u5e94\u4f7f\u7528\u53c2\u6570hosts: all\u3002<\/span><\/p>\n

9\uff0e\u53ea\u8bb0\u5f97\u67d0\u4e2a\u53d8\u91cf\u4e2d\u7684\u4e00\u90e8\u5206\u540d\u79f0\uff0c\u5e94\u5982\u4f55\u901a\u8fc7\u5173\u952e\u8bcd\u641c\u7d22\uff1f<\/p>\n

\u7b54\uff1a<\/strong>\u53ef\u6267\u884c\u547d\u4ee4\uff1aansible all -m setup -a 'filter=\"*\u5173\u952e\u8bcd*\"'\u3002<\/span><\/p>\n

10\uff0e\u5728\u4f7f\u7528ansible-vault\u547d\u4ee4\u8fdb\u884c\u52a0\u5bc6\u65f6\uff0c\u9ed8\u8ba4\u4f7f\u7528\u7684\u662f\u54ea\u79cd\u52a0\u5bc6\u65b9\u5f0f\uff1f<\/p>\n

\u7b54\uff1a<\/strong>AES 256\u3002<\/span><\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"

\u7ae0\u8282\u7b80\u8ff0\uff1a 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 […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[2632],"tags":[],"class_list":["post-291367","post","type-post","status-publish","format-standard","hentry","category-rhel10"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/291367","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=291367"}],"version-history":[{"count":11,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/291367\/revisions"}],"predecessor-version":[{"id":292577,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/291367\/revisions\/292577"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=291367"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=291367"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=291367"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}