{"id":252356,"date":"2022-09-27T10:45:34","date_gmt":"2022-09-27T02:45:34","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=252356"},"modified":"2022-09-21T14:49:49","modified_gmt":"2022-09-21T06:49:49","slug":"linux-ansible","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/linux-ansible.html","title":{"rendered":"\u4e00\u6b3e\u5f00\u6e90\u7684IT\u914d\u7f6e\u7ba1\u7406\u5de5\u5177\u2014Ansible"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\nAnsible\u662f\u4e00\u6b3e\u5f00\u6e90\u7684IT\u914d\u7f6e\u7ba1\u7406\u5de5\u5177\uff0c\u5e38\u88abIT\u754c\u7684\u5c0f\u4f19\u4f34\u4eec\u7528\u4e8e\u670d\u52a1\u90e8\u7f72\u3001\u914d\u7f6e\u7ba1\u7406\u7b49\u5de5\u4f5c\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
\u4e00\u3001Ansible\u53d1\u5c55\u548c\u8d77\u6e90<\/strong><\/div>\n

Ansible\u662f\u4e00\u6b3e\u5f00\u6e90\u7684IT\u914d\u7f6e\u7ba1\u7406\u5de5\u5177\uff0c\u5e38\u88abIT\u754c\u7684\u5c0f\u4f19\u4f34\u4eec\u7528\u4e8e\u670d\u52a1\u90e8\u7f72\u3001\u914d\u7f6e\u7ba1\u7406\u7b49\u5de5\u4f5c\u3002\u914d\u7f6e\u6587\u4ef6\u91c7\u7528\u6700\u5e38\u89c1\u7684yaml\u683c\u5f0f\uff0c\u5b66\u4e60\u8d77\u6765\u4e5f\u662f\u6bd4\u8f83\u5bb9\u6613\uff0c\u5e76\u4e14\u4e0d\u50cfSaltStack\uff0cAnsible\u5e76\u4e0d\u9700\u8981\u4e5f\u6ca1\u6709agent\uff0c\u53ea\u6709\u4e00\u4e2a\u63a7\u5236\u7aef\u3002\u8be5\u5de5\u5177\u4f7f\u7528\u7b80\u5355\u4f46\u529f\u80fd\u975e\u5e38\u5f3a\u5927\uff0c\u53ef\u4ee5\u89e3\u51b3\u4f17\u591a\u5de5\u4f5c\u4e2d\u7e41\u7410\u7684\u670d\u52a1\u5b89\u88c5\u3001\u914d\u7f6e\u7b49\u95ee\u9898\u3002<\/p>\n

Ansible\u7684\u7b2c\u4e00\u4e2a\u7248\u672c\u662f0.0.1\uff0c\u53d1\u5e03\u4e8e2012\u5e743\u67089\u65e5\uff0c\u5176\u4f5c\u8005\u517c\u521b\u59cb\u4eba\u662fMichael DeHaan\u3002\u8fc4\u4eca\u4e3a\u6b62\u5df2\u7ecf\u53d1\u5c55\u5230\u4e862.9\u7248\u672c\u3002\u5e76\u4e14\u5b83\u7684\u5173\u6ce8\u5ea6\u3001Star\u6570\u4ee5\u53caFork\u7684\u6b21\u6570\u90fd\u4f4d\u5c45\u699c\u9996\u3002\u5c31\u8fde\u5f3a\u5927\u7684SaltStack\u4e5f\u53ea\u80fd\u6392\u5230\u7b2c\u4e8c\u3002<\/p>\n

Michael DeHaan\u5728\u914d\u7f6e\u7ba1\u7406\u548c\u67b6\u6784\u8bbe\u8ba1\u65b9\u9762\u6709\u4e30\u5bcc\u7684\u7ecf\u9a8c\uff0c\u66fe\u5c31\u804c\u4e8eRedHat\u516c\u53f8\uff0c\u5728RedHat\u4efb\u804c\u671f\u95f4\u4e3b\u8981\u5f00\u53d1\u4e86Cobble\u3002\u5728\u4ed6\u5c1d\u8bd5\u4e86\u5404\u79cd\u81ea\u52a8\u5316\u5de5\u5177Puppet\u3001Chef\u4e4b\u540e\uff0c\u51b3\u5b9a\u81ea\u5df1\u6253\u9020\u4e00\u6b3e\u80fd\u591f\u7ed3\u5408\u4f17\u591a\u6709\u70b9\u7684\u81ea\u52a8\u5316\u5de5\u5177\u3002\u7531\u6b64\uff0c\u4fbf\u6709\u4e86Ansible\u8fd9\u6b3e\u6613\u7406\u89e3\u3001\u6613\u4e0a\u624b\u3001\u53d7\u4f17\u4eba\u559c\u7231\u7684\u81ea\u52a8\u5316\u5de5\u5177\u3002<\/p>\n

\u4e8c\u3001\u4e3a\u4ec0\u4e48\u9700\u8981Ansible<\/strong><\/div>\n

\u524d\u9762\u8bf4\u8fc7\uff0cansible\u901a\u5e38\u7528\u4e8e\u81ea\u52a8\u5316\u7684\u573a\u666f\uff0c\u591a\u7528\u5728\u670d\u52a1\u90e8\u7f72\u3001\u914d\u7f6e\u7ba1\u7406\u65b9\u9762\u3002\u968f\u7740\u65f6\u95f4\u63a8\u79fb\u548c\u516c\u53f8\u53d1\u5c55\uff0c\u9879\u76ee\u8d8a\u6765\u8d8a\u591a\uff0c\u56e2\u961f\u65e5\u76ca\u58ee\u5927\uff0c\u5404\u79cd\u516c\u53f8\u5185\u90e8\u5f00\u53d1\u7684\u5e94\u7528\u3001\u7b2c\u4e09\u65b9\u5f00\u6e90\u7684\u4e2d\u95f4\u4ef6\u7b49\u670d\u52a1\u8d8a\u6765\u8d8a\u591a\uff0c\u90a3\u4e48\u7ba1\u7406\u8d77\u6765\u5c31\u76f8\u5bf9\u6bd4\u8f83\u56f0\u96be\uff0c\u4eba\u8089\u64cd\u4f5c\u5df2\u7ecf\u5b8c\u5168\u6ee1\u8db3\u4e0d\u4e86\u4f20\u7edf\u7684\u8fd0\u7ef4\u5de5\u4f5c\uff0c\u9700\u8981\u6d88\u8017\u76f8\u5f53\u591a\u7684\u65f6\u95f4\u6765\u8fdb\u884c\u53d8\u66f4\uff0c\u8fdb\u800c\u963b\u788d\u4e86\u5f00\u53d1\u4eba\u5458\u7684\u901f\u5ea6\uff0c\u6781\u5927\u7684\u964d\u4f4e\u4e86\u5de5\u4f5c\u6548\u7387\u3002\u663e\u7136\u53ef\u8003\u53c8\u9ad8\u6548\u7684\u90e8\u7f72\u548c\u7ba1\u7406\u6210\u4e3a\u4e86\u516c\u53f8\u7684\u4e00\u5927\u96be\u70b9\u4e0e\u6311\u6218\u3002\u90a3\u4e48\u4e00\u6b3e\u9ad8\u6548\u4e14\u53ef\u9760\u7684\u670d\u52a1\u90e8\u7f72\u548c\u7ba1\u7406\u5de5\u5177\u5c31\u663e\u5f97\u5c24\u4e3a\u91cd\u8981\u3002\u800c\u5728\u5f88\u957f\u4e00\u6bb5\u65f6\u95f4\u91cc\uff0cDocker\u5bb9\u5668\u4e0ekubernetes\u5bb9\u5668\u7f16\u6392\u7cfb\u7edf\u6ca1\u6709\u88ab\u5e7f\u6cdb\u7684\u666e\u53ca\u4e4b\u524d\uff0c\u6709\u5f88\u5927\u4e00\u90e8\u5206\u4eba\u5728\u4f7f\u7528Jenkins + Ansible\u8fdb\u884cCICD\u3002<\/p>\n

\u4e09\u3001Ansible\u7684\u4e3b\u8981\u529f\u80fd<\/strong><\/div>\n
    \n\u6279\u91cf\u6267\u884c\u8fdc\u7a0b\u547d\u4ee4\uff1a\u53ef\u4ee5\u5bf9\u4efb\u610f\u591a\u53f0\u4e3b\u673a\u540c\u65f6\u8fdb\u884c\u547d\u4ee4\u7684\u6267\u884c\u3002
    \n\u6279\u91cf\u914d\u7f6e\u8f6f\u4ef6\u670d\u52a1\uff1a\u53ef\u4ee5\u8fdb\u884c\u81ea\u52a8\u5316\u7684\u65b9\u5f0f\u90e8\u7f72\u3001\u914d\u7f6e\u53ca\u7ba1\u7406\u670d\u52a1\u3002
    \n\u7f16\u6392\u9ad8\u7ea7\u7684IT\u4efb\u52a1\uff1aAnsible \u53ef\u4ee5\u4f7f\u7528yaml\u6765\u7f16\u5199\u4e00\u5957\u5b8c\u6574\u7684Playbook\uff0c\u7528\u6765\u90e8\u7f72\u7ef4\u62a4\u4e00\u5957\u5b8c\u5168\u7684\u57fa\u7840\u67b6\u6784\u3002\n<\/ol>\n
    \u56db\u3001Ansible\u7684\u76f8\u5173\u7279\u6027<\/strong><\/div>\n

    Ansible\u662f\u57fa\u4e8e\u6bcf\u4e2a\u6a21\u5757\u8fdb\u884c\u5de5\u4f5c\uff0c\u81ea\u8eab\u5e76\u6ca1\u6709\u6279\u91cf\u90e8\u7f72\u7684\u80fd\u529b\uff0cansible\u81ea\u8eab\u53ea\u662f\u63d0\u4f9b\u4e86\u4e00\u79cd\u6846\u67b6\u3002<\/p>\n

      \nAnsible\u7531Python\u8bed\u8a00\u5f00\u53d1\uff0c\u6ca1\u6709agent\uff0c\u4e0d\u9700\u8981\u5728\u88ab\u7ba1\u7406\u8282\u70b9\u5b89\u88c5\u4efb\u4f55\u5ba2\u6237\u7aef\u3002
      \n\u6a21\u5757\u5316\uff1a\u57fa\u4e8e\u6a21\u5757\u5de5\u4f5c\uff0c\u79e9\u5e8f\u8c03\u7528\u7279\u5b9a\u7684\u6a21\u5757\u6765\u5b8c\u6210\u7279\u5b9a\u5de5\u4f5c\u3002
      \n\u57fa\u4e8eSSH\u534f\u8bae\u3002
      \n\u4e09\u5927\u5173\u952e\u7ec4\u6210\u6a21\u5757\uff1aParamiko\uff0c PyYAML\uff0c Jinja2\u3002
      \n\u5e42\u7b49\u6027\uff1a\u4e00\u4e2a\u4efb\u52a1\u6267\u884c1\u904d\u548c\u6267\u884cn\u904d\u6548\u679c\u4e00\u6837\uff0c\u4e0d\u56e0\u91cd\u590d\u6267\u884c\u5e26\u6765\u610f\u5916\u60c5\u51b5\u3002
      \n\u53ef\u4ee5\u4f7f\u7528\u547d\u4ee4\u884cad-hoc\u65b9\u5f0f\u6765\u6267\u884c\u6279\u91cf\u4efb\u52a1\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528yaml\u683c\u5f0f\u7684\u6587\u4ef6\u6765\u5b9a\u5236Playbook\u5267\u672c\u5b9e\u73b0\u6279\u91cf\u4efb\u52a1\u3002
      \n\u53ef\u4ee5\u4f7f\u7528Role\u7ec4\u7ec7\u6279\u91cf\u4efb\u52a1\u3002\n<\/ol>\n
      \u4e94\u3001Ansible\u7684\u4f18\u70b9<\/strong><\/div>\n
        \n\u5bb9\u6613\u5b66\u4e60\u4e14\u8f7b\u91cf\uff1a\u65e0\u9700\u5728\u88ab\u63a7\u5236\u8282\u70b9\u5b89\u88c5agent\uff0c\u505a\u6279\u91cf\u64cd\u4f5c\u65f6\u53ea\u9700\u8981\u5728\u64cd\u4f5c\u673a\u64cd\u4f5c\u5373\u53ef(\u524d\u63d0\uff1a\u9700\u8981\u914d\u7f6e\u597d\u514d\u5bc6\u767b\u5f55)\u3002
        \n\u64cd\u4f5c\u7075\u6d3b\uff1a\u5177\u6709\u4f17\u591a\u7684\u6a21\u5757\uff0c\u53ef\u4f7f\u7528\u547d\u4ee4\u884cad-hoc\u65b9\u5f0f\u6216\u8005Playbook\u5267\u672c\u7684\u65b9\u5f0f\u6765\u5b9e\u73b0\u6279\u91cf\u4efb\u52a1\u6267\u884c\u3002
        \n\u53ef\u79fb\u690d\u6027\u9ad8\uff1a\u53ef\u4ee5\u57fa\u4e8eyaml\u6587\u4ef6\u7f16\u5199\u4e00\u5957Playbook\uff0c\u53ea\u8981\u505a\u597d\u903b\u8f91\u5224\u65ad\uff0c\u5c31\u53ef\u4ee5\u5728\u591a\u79cd\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u62ff\u6765\u5373\u7528\u3002
        \n\u5e42\u7b49\u6027\uff1a\u4e00\u4e2a\u4efb\u52a1\u6267\u884c1\u904d\u548c\u6267\u884cn\u904d\u6548\u679c\u4e00\u6837\uff0c\u4e0d\u56e0\u91cd\u590d\u6267\u884c\u5e26\u6765\u610f\u5916\u60c5\u51b5\u3002
        \n\u652f\u6301\u666e\u901a\u7528\u6237sudo\u63d0\u6743\u3002\n<\/ol>\n

        \u4f46\u662f\u4efb\u4f55\u4e8b\u7269\u90fd\u5177\u6709\u4e24\u9762\u6027\u3002SSH\u867d\u597d\uff0c\u4f46\u5982\u679c\u88ab\u7ba1\u7406\u7684\u673a\u5668\u6570\u91cf\u4f17\u591a\u7684\u8bdd\uff0c\u6267\u884c\u7684\u901f\u5ea6\u5c31\u4f1a\u6bd4\u8f83\u6162\uff0c\u5c31\u9700\u8981\u8fdb\u884c\u4e00\u5b9a\u7684\u4f18\u5316\u548c\u5206\u6279\u4efb\u52a1\u6765\u7f13\u89e3\u901f\u5ea6\u95ee\u9898\u3002<\/p>\n

        \u516d\u3001Ansible\u7684\u67b6\u6784<\/strong><\/div>\n

        Ansible\u7531\u4ee5\u4e0b\u51e0\u4e2a\u6838\u5fc3\u5de5\u5177\u7ec4\u6210\uff1a<\/p>\n

          \nINVENTORY\uff1aAnsible\u7ba1\u7406\u4e3b\u673a\u7684\u6e05\u5355\/etc\/anaible\/hosts\u3002
          \nMODULES\uff1aAnsible\u6267\u884c\u547d\u4ee4\u7684\u529f\u80fd\u6a21\u5757\uff0c\u591a\u6570\u4e3a\u5185\u7f6e\u6838\u5fc3\u6a21\u5757\uff0c\u4e5f\u53ef\u81ea\u5b9a\u4e49\u3002
          \nPLUGINS\uff1a\u6a21\u5757\u529f\u80fd\u7684\u8865\u5145\uff0c\u5982\u8fde\u63a5\u7c7b\u578b\u63d2\u4ef6\u3001\u5faa\u73af\u63d2\u4ef6\u3001\u53d8\u91cf\u63d2\u4ef6\u3001\u8fc7\u6ee4\u63d2\u4ef6\u7b49\u3002
          \nAPl\uff1a\u4f9b\u7b2c\u4e09\u65b9\u7a0b\u5e8f\u8c03\u7528\u7684\u5e94\u7528\u7a0b\u5e8f\u7f16\u7a0b\u63a5\u53e3\u3002
          \n\u5728\u65e5\u5e38\u5de5\u4f5c\u4e2d\uff0c\u6211\u4eec\u5927\u591a\u6570\u7528\u5230\u7684\u4e14\u4f7f\u7528\u6bd4\u8f83\u9891\u7e41\u7684\u4e3b\u8981\u662f\uff1aInventory \u548c Modules\u3002\u901a\u5e38\u6211\u4eec\u4f1a\u6839\u636e\u9879\u76ee\u7684\u9700\u6c42\u6765\u5b9a\u5236\u5316\u6211\u4eec\u7684Inventory\uff0c\u4e0d\u4f1a\u5c06\u5b83\u653e\u5728\u9ed8\u8ba4\u7684\/etc\/anaible\/hosts\u6587\u4ef6\u4e2d\u3002\n<\/ol>\n

          \u9700\u8981\u63d0\u9192\u5927\u5bb6\u7684\u662f\uff1a<\/p>\n

          Ansible\u66f4\u65b0\u540e\uff0c\u5f88\u591a\u4e4b\u524d\u7684\u65b9\u6cd5\u5728\u4e00\u6bb5\u65f6\u95f4\u540e\u6216\u8005\u8bf4\u5728\u67d0\u4e2a\u7248\u672c\u540e\u5c31\u4f1a\u5b8c\u5168\u5e9f\u5f03\u6389\uff0c\u8fd9\u70b9\u548c\u76ee\u524dKubernetes\u7684API\u5e9f\u5f03\u6709\u70b9\u50cf\u3002\u4f46\u662f\u5f53\u4f60\u5728\u67d0\u4e2a\u9ad8\u7248\u672c\u53bb\u4f7f\u7528\u4f4e\u7248\u672c\u63d0\u4f9b\u7684\u65b9\u6cd5\u65f6\uff0c\u5b83\u4f1a\u5728\u4f60\u6267\u884cplaybook\u7684\u65f6\u5019\u7ed9\u51fawarning\u8b66\u544a\uff0c\u53ef\u4ee5\u6839\u636e\u8b66\u544a\u518d\u53bb\u67e5\u8be2\u5b98\u65b9\u6587\u6863\u4e0a\u5bf9\u5e94\u7248\u672c\u7684\u4f7f\u7528\u65b9\u6cd5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

          Ansible\u662f\u4e00\u6b3e\u5f00\u6e90\u7684IT\u914d\u7f6e\u7ba1\u7406\u5de5\u5177\uff0c\u5e38\u88abIT\u754c\u7684\u5c0f\u4f19\u4f34\u4eec\u7528\u4e8e\u670d\u52a1\u90e8\u7f72\u3001\u914d\u7f6e\u7ba1\u7406\u7b49\u5de5\u4f5c\u3002\u914d\u7f6e\u6587\u4ef6\u91c7\u7528\u6700\u5e38 […]<\/p>\n","protected":false},"author":370,"featured_media":238555,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-252356","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/252356","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\/370"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=252356"}],"version-history":[{"count":7,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/252356\/revisions"}],"predecessor-version":[{"id":253156,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/252356\/revisions\/253156"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/238555"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=252356"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=252356"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=252356"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}