{"id":83229,"date":"2023-11-15T06:58:13","date_gmt":"2023-11-14T22:58:13","guid":{"rendered":"http:\/\/lrxjmw.cn\/?p=83229"},"modified":"2023-11-15T06:58:13","modified_gmt":"2023-11-14T22:58:13","slug":"ansible-deployment-serverless","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/ansible-deployment-serverless.html","title":{"rendered":"\u7528 Ansible \u90e8\u7f72\u65e0\u670d\u52a1\u5e94\u7528!"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\nAnsible \u88ab\u8bbe\u8ba1\u4e3a\u5b9e\u9645\u5de5\u4f5c\u4e2d\u7684\u6700\u7b80\u5316\u7684\u90e8\u7f72\u5de5\u5177\u3002\u8fd9\u610f\u5473\u7740\u5b83\u4e0d\u662f\u4e00\u4e2a\u5b8c\u6574\u7684\u7f16\u7a0b\u8bed\u8a00\u3002\u4f60\u9700\u8981\u7f16\u5199\u5b9a\u4e49\u4efb\u52a1\u7684 YAML \u6a21\u677f\uff0c\u5e76\u5217\u51fa\u4efb\u4f55\u9700\u8981\u81ea\u52a8\u5b8c\u6210\u7684\u4efb\u52a1\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\u5927\u591a\u6570\u4eba\u8ba4\u4e3a Ansible \u662f\u4e00\u79cd\u66f4\u5f3a\u5927\u7684\u201c\u5904\u4e8e for \u5faa\u73af\u4e2d\u7684 SSH\u201d\uff0c\u5728\u7b80\u5355\u7684\u4f7f\u7528\u573a\u666f\u4e0b\u8fd9\u662f\u771f\u7684\u3002\u4f46\u5176\u5b9e Ansible \u662f\u4efb\u52a1\uff0c\u800c\u975e SSH\u3002\u5728\u5f88\u591a\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u901a\u8fc7 SSH \u8fdb\u884c\u8fde\u63a5\uff0c\u4f46\u5b83\u4e5f\u652f\u6301 Windows \u673a\u5668\u4e0a\u7684 Windows \u8fdc\u7a0b\u7ba1\u7406\uff08WinRM\uff09\uff0c\u4ee5\u53ca\u4f5c\u4e3a\u4e91\u670d\u52a1\u7684\u901a\u7528\u8bed\u8a00\u7684 HTTPS API \u4e4b\u7c7b\u7684\u4e1c\u897f\u3002<\/p>\n

\u5728\u4e91\u4e2d\uff0cAnsible \u53ef\u4ee5\u5728\u4e24\u4e2a\u72ec\u7acb\u7684\u5c42\u9762\u4e0a\u64cd\u4f5c\uff1a\u63a7\u5236\u9762\u548c\u5b9e\u4f8b\u8d44\u6e90\u3002\u63a7\u5236\u9762\u7531\u6240\u6709\u6ca1\u6709\u8fd0\u884c\u5728\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u7684\u4e1c\u897f\u7ec4\u6210\u3002\u5305\u62ec\u8bbe\u7f6e\u7f51\u7edc\u3001\u65b0\u5efa\u5b9e\u4f8b\u3001\u4f9b\u7ed9\u66f4\u9ad8\u7ea7\u522b\u7684\u670d\u52a1\uff0c\u5982\u4e9a\u9a6c\u900a\u7684 S3 \u6216 DynamoDB\uff0c\u4ee5\u53ca\u4fdd\u6301\u4e91\u57fa\u7840\u8bbe\u65bd\u5b89\u5168\u548c\u670d\u52a1\u5ba2\u6237\u200b\u200b\u6240\u9700\u7684\u4e00\u5207\u3002<\/p>\n

\u5b9e\u4f8b\u4e0a\u7684\u5de5\u4f5c\u662f\u4f60\u5df2\u7ecf\u77e5\u9053 Ansible \u53ef\u4ee5\u505a\u7684\uff1a\u542f\u52a8\u548c\u505c\u6b62\u670d\u52a1\u3001\u914d\u7f6e\u6587\u4ef6\u6a21\u7248\u5316\u3001\u5b89\u88c5\u8f6f\u4ef6\u5305\u4ee5\u53ca\u901a\u8fc7 SSH \u6267\u884c\u7684\u6240\u6709\u4e0e\u64cd\u4f5c\u7cfb\u7edf\u76f8\u5173\u7684\u64cd\u4f5c\u3002<\/p>\n

\u73b0\u5728\uff0c\u4ec0\u4e48\u662f\u65e0\u670d\u52a1\u5462\uff1f\u8fd9\u8981\u770b\u4f60\u95ee\u8c01\uff0c\u65e0\u670d\u52a1\u8981\u4e48\u662f\u5bf9\u516c\u6709\u4e91\u7684\u65e0\u9650\u5ef6\u4f38\uff0c\u6216\u8005\u662f\u4e00\u4e2a\u5168\u65b0\u7684\u8303\u4f8b\uff0c\u5176\u4e2d\u6240\u6709\u7684\u4e1c\u897f\u90fd\u662f API \u8c03\u7528\uff0c\u4ee5\u524d\u4ece\u6765\u6ca1\u6709\u8fd9\u6837\u505a\u8fc7\u3002<\/p>\n

Ansible \u91c7\u53d6\u7b2c\u4e00\u79cd\u89c2\u70b9\u3002\u5728 \u201c\u65e0\u670d\u52a1\u201d \u662f\u4e13\u95e8\u672f\u8bed\u4e4b\u524d\uff0c\u7528\u6237\u4e0d\u5f97\u4e0d\u7ba1\u7406\u548c\u914d\u7f6e EC2 \u5b9e\u4f8b\u3001\u865a\u62df\u79c1\u6709\u4e91 \uff08VPC\uff09 \u7f51\u7edc\u4ee5\u53ca\u5176\u4ed6\u6240\u6709\u5185\u5bb9\u3002\u65e0\u670d\u52a1\u662f\u6258\u7ba1\u670d\u52a1\u65b9\u5411\u8fc8\u51fa\u7684\u53e6\u4e00\u6b65\uff0c\u5e76\u4e14\u4e0e Ansible \u7684\u65e0\u4ee3\u7406\u4f53\u7cfb\u7ed3\u6784\u76f8\u5f97\u76ca\u5f70\u3002<\/p>\n

\u5728\u6211\u4eec\u5f00\u59cb Lambda \u793a\u4f8b\u4e4b\u524d\uff0c\u8ba9\u6211\u4eec\u6765\u770b\u4e00\u4e2a\u7b80\u5355\u7684\u914d\u7f6e CloudFormation \u6808\u4efb\u52a1\uff1a<\/p>\n

- name: Build network\r\ncloudformation:\r\nstack_name: prod-vpc\r\nstate: present\r\ntemplate: base_vpc.yml<\/pre>\n

\u7f16\u5199\u8fd9\u6837\u7684\u4efb\u52a1\u53ea\u9700\u8981\u51e0\u5206\u949f\uff0c\u4f46\u5b83\u662f\u6784\u5efa\u57fa\u7840\u67b6\u6784\u6240\u6d89\u53ca\u7684\u6700\u540e\u7684\u534a\u624b\u52a8\u6b65\u9aa4 - \u70b9\u51fb \u201cCreate Stack\u201d - \u8fd9\u5c06 playbook \u4e0e\u5176\u4ed6\u653e\u5728\u4e00\u8d77\u3002\u73b0\u5728\u4f60\u7684 VPC \u53ea\u662f\u5728\u5efa\u7acb\u65b0\u533a\u57df\u65f6\u53ef\u4ee5\u8c03\u7528\u7684\u53e6\u4e00\u9879\u4efb\u52a1\u4e86\u3002<\/p>\n

\u7531\u4e8e\u4e91\u63d0\u4f9b\u5546\u662f\u4f60\u5e10\u6237\u4e2d\u53d1\u751f\u4e9b\u4ec0\u4e48\u7684\u771f\u76f8\u6765\u6e90\uff0c\u56e0\u6b64 Ansible \u6709\u8bb8\u591a\u65b9\u6cd5\u6765\u53d6\u56de\u5e76\u4f7f\u7528 ID\u3001\u540d\u79f0\u548c\u5176\u4ed6\u53c2\u6570\u6765\u8fc7\u6ee4\u548c\u67e5\u8be2\u8fd0\u884c\u7684\u5b9e\u4f8b\u6216\u7f51\u7edc\u3002\u4ee5 cloudformation_facts \u6a21\u5757\u4e3a\u4f8b\uff0c\u6211\u4eec\u53ef\u4ee5\u4ece\u6211\u4eec\u521a\u521a\u521b\u5efa\u7684\u6a21\u677f\u4e2d\u5f97\u5230\u5b50\u7f51 ID\u3001\u7f51\u7edc\u8303\u56f4\u548c\u5176\u4ed6\u6570\u636e\u3002<\/p>\n

- name: Pull all new resources back in as a variable\r\ncloudformation_facts:\r\nstack_name: prod-vpc\r\nregister: network_stack<\/pre>\n

\u5bf9\u4e8e\u65e0\u670d\u52a1\u5e94\u7528\uff0c\u9664\u4e86 DynamoDB \u8868\uff0cS3 bucket \u548c\u5176\u4ed6\u4efb\u4f55\u5176\u4ed6\u529f\u80fd\u4e4b\u5916\uff0c\u4f60\u80af\u5b9a\u8fd8\u9700\u8981\u4e00\u4e2a Lambda \u51fd\u6570\u7684\u8865\u5145\u3002\u5e78\u8fd0\u7684\u662f\uff0c\u901a\u8fc7\u4f7f\u7528 lambda \u6a21\u5757\uff0c Lambda \u51fd\u6570\u53ef\u4ee5\u4ee5\u4e0a\u6b21\u4efb\u52a1\u7684\u5806\u6808\u76f8\u540c\u7684\u65b9\u5f0f\u521b\u5efa\uff1a<\/p>\n

- lambda:\r\nname: sendReportMail\r\nzip_file: \"{{ deployment_package }}\"\r\nruntime: python3.6\r\nhandler: report.send\r\nmemory_size: 1024\r\nrole: \"{{ iam_exec_role }}\"\r\nregister: new_function<\/pre>\n

\u5982\u679c\u4f60\u6709\u5176\u4ed6\u60f3\u7528\u6765\u4ea4\u4ed8\u65e0\u670d\u52a1\u5e94\u7528\u7684\u5de5\u5177\uff0c\u8fd9\u4e5f\u662f\u53ef\u4ee5\u7684\u3002\u5f00\u6e90\u7684\u65e0\u670d\u52a1\u6846\u67b6\u6709\u81ea\u5df1\u7684 Ansible \u6a21\u5757\uff0c\u5b83\u4e5f\u53ef\u4ee5\u5de5\u4f5c\uff1a<\/p>\n

- serverless:\r\nservice_path: '{{ project_dir }}'\r\nstage: dev\r\nregister: sls\r\n- name: Serverless uses CloudFormation under the hood, so you can easily pull info back into Ansible\r\ncloudformation_facts:\r\nstack_name: \"{{ sls.service_name }}\"\r\nregister: sls_facts<\/pre>\n

\u8fd9\u4e0d\u662f\u4f60\u9700\u8981\u7684\u5168\u90e8\uff0c\u56e0\u4e3a\u65e0\u670d\u52a1\u9879\u76ee\u4e5f\u5fc5\u987b\u5b58\u5728\uff0c\u4f60\u5c06\u5728\u90a3\u91cc\u5927\u91cf\u7684\u5b9a\u4e49\u4f60\u7684\u51fd\u6570\u548c\u4e8b\u4ef6\u6e90\u3002\u5bf9\u4e8e\u6b64\u4f8b\uff0c\u6211\u4eec\u5c06\u5236\u4f5c\u4e00\u4e2a\u54cd\u5e94 HTTP \u8bf7\u6c42\u7684\u51fd\u6570\u3002\u65e0\u670d\u52a1\u6846\u67b6\u4f7f\u7528 YAML \u4f5c\u4e3a\u5176\u914d\u7f6e\u8bed\u8a00\uff08\u548c Ansible \u4e00\u6837\uff09\uff0c\u6240\u4ee5\u8fd9\u5e94\u8be5\u770b\u8d77\u6765\u5f88\u719f\u6089\u3002<\/p>\n

# serverless.yml\r\nservice: fakeservice\r\nprovider:\r\nname: aws\r\nruntime: python3.6\r\nfunctions:\r\nmain:\r\nhandler: test_function.handler\r\nevents:\r\n- http:\r\npath: \/\r\nmethod: get<\/pre>\n

\u5728 AnsibleFest \u4e2d\uff0c\u6211\u5c06\u4ecb\u7ecd\u8fd9\u4e2a\u4f8b\u5b50\u548c\u5176\u4ed6\u6df1\u5165\u7684\u90e8\u7f72\u7b56\u7565\uff0c\u4ee5\u6700\u5927\u9650\u5ea6\u5730\u5229\u7528\u4f60\u5df2\u7ecf\u62e5\u6709\u7684 playbook \u548c\u57fa\u7840\u8bbe\u65bd\uff0c\u8fd8\u6709\u65b0\u7684\u65e0\u670d\u52a1\u5b9e\u8df5\u3002\u65e0\u8bba\u4f60\u662f\u5426\u80fd\u5230\uff0c\u6211\u5e0c\u671b\u8fd9\u4e9b\u4f8b\u5b50\u53ef\u4ee5\u8ba9\u4f60\u5f00\u59cb\u4f7f\u7528 Ansible\uff0c\u65e0\u8bba\u4f60\u662f\u5426\u6709\u4efb\u4f55\u670d\u52a1\u8981\u7ba1\u7406\u3002<\/p>\n

AnsibleFest \u662f\u4e00\u4e2a\u5355\u65e5\u4f1a\u8bae\uff0c\u6c47\u96c6\u4e86\u6570\u767e\u540d Ansible \u7528\u6237\u3001\u5f00\u53d1\u4eba\u5458\u548c\u884c\u4e1a\u5408\u4f5c\u4f19\u4f34\u3002\u52a0\u5165\u6211\u4eec\u5427\uff0c\u8fd9\u91cc\u6709\u4ea7\u54c1\u66f4\u65b0\u3001\u9f13\u821e\u4eba\u5fc3\u7684\u4ea4\u8c08\u3001\u6280\u672f\u6df1\u5ea6\u6f5c\u6c34\uff0c\u52a8\u624b\u6f14\u793a\u548c\u6574\u5929\u7684\u7f51\u7edc\u3002<\/p>\n

via: https:\/\/opensource.com\/article\/17\/8\/ansible-serverless-applications<\/p>\n

\u4f5c\u8005\uff1aRyan Scott Brown \u8bd1\u8005\uff1ageekpi \u6821\u5bf9\uff1awxy<\/p>\n

\u672c\u6587\u7531 LCTT \u539f\u521b\u7f16\u8bd1\uff0cLinux\u4e2d\u56fd \u8363\u8a89\u63a8\u51fa<\/p>\n

\n

\u539f\u6587\u6765\u81ea\uff1ahttps:\/\/linux.cn\/article-8843-1.html<\/a><\/p>\n

\u672c\u6587\u5730\u5740\uff1ahttp:\/\/lrxjmw.cn\/ansible-deployment-serverless.html<\/a>\u7f16\u8f91\uff1a\u9ad8\u519b\uff0c\u5ba1\u6838\u5458\uff1a\u9004\u589e\u5b9d<\/span><\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"

\u5bfc\u8bfb Ansible \u88ab\u8bbe\u8ba1\u4e3a\u5b9e\u9645\u5de5\u4f5c\u4e2d\u7684\u6700\u7b80\u5316\u7684\u90e8\u7f72\u5de5\u5177\u3002\u8fd9\u610f\u5473\u7740\u5b83\u4e0d\u662f\u4e00\u4e2a\u5b8c\u6574\u7684\u7f16\u7a0b\u8bed\u8a00\u3002\u4f60\u9700\u8981\u7f16\u5199\u5b9a\u4e49\u4efb […]<\/p>\n","protected":false},"author":63,"featured_media":83246,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-83229","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\/83229","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\/63"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=83229"}],"version-history":[{"count":2,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/83229\/revisions"}],"predecessor-version":[{"id":83319,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/83229\/revisions\/83319"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/83246"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=83229"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=83229"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=83229"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}