{"id":163033,"date":"2019-12-01T10:25:43","date_gmt":"2019-12-01T02:25:43","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=163033"},"modified":"2019-11-04T09:27:29","modified_gmt":"2019-11-04T01:27:29","slug":"ansible-command","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/ansible-command.html","title":{"rendered":"\u5982\u4f55\u4f7f\u7528 Ansible \u5728\u5bb9\u5668\u4e2d\u6267\u884c\u547d\u4ee4"},"content":{"rendered":"
\u5bb9\u5668\u548c\u00a0Ansible\u00a0\u53ef\u4ee5\u5f88\u597d\u5730\u878d\u5408\u5728\u4e00\u8d77\uff1a\u4ece\u7ba1\u7406\u548c\u7f16\u6392\u5230\u4f9b\u5e94\u548c\u6784\u5efa\u3002\u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u5c06\u91cd\u70b9\u4ecb\u7ecd\u6784\u5efa\u90e8\u5206\u3002<\/p>\n
\u5982\u679c\u4f60\u719f\u6089 Ansible\uff0c\u5c31\u4f1a\u77e5\u9053\u4f60\u53ef\u4ee5\u7f16\u5199\u4e00\u7cfb\u5217\u4efb\u52a1\uff0cansible-playbook\u00a0\u547d\u4ee4\u5c06\u4e3a\u4f60\u6267\u884c\u8fd9\u4e9b\u4efb\u52a1\u3002\u4f60\u77e5\u9053\u5417\uff0c\u5982\u679c\u4f60\u7f16\u5199 Dockerfile \u5e76\u8fd0\u884c\u00a0podman build\uff0c\u4f60\u8fd8\u53ef\u4ee5\u5728\u5bb9\u5668\u73af\u5883\u4e2d\u6267\u884c\u6b64\u7c7b\u547d\u4ee4\uff0c\u5e76\u83b7\u5f97\u76f8\u540c\u200b\u200b\u7684\u7ed3\u679c\u3002<\/p>\n
\u8fd9\u662f\u4e00\u4e2a\u4f8b\u5b50\uff1a<\/p>\n
- name: Serve our file using httpd\r\nhosts: all\r\ntasks:\r\n- name: Install httpd\r\npackage:\r\nname: httpd\r\nstate: installed\r\n- name: Copy our file to httpd\u2019s webroot\r\ncopy:\r\nsrc: our-file.txt\r\ndest: \/var\/www\/html\/<\/pre>\n\u4f60\u53ef\u4ee5\u5728 Web \u670d\u52a1\u5668\u672c\u5730\u6216\u5bb9\u5668\u4e2d\u6267\u884c\u8fd9\u4e2a\u5267\u672c\uff0c\u5e76\u4e14\u53ea\u8981\u4f60\u8bb0\u5f97\u5148\u521b\u5efa our-file.txt\uff0c\u5b83\u5c31\u53ef\u4ee5\u5de5\u4f5c\u3002<\/p>\n
\u4f46\u662f\u8fd9\u91cc\u7f3a\u5c11\u4e86\u4e00\u4e9b\u4e1c\u897f\u3002\u4f60\u9700\u8981\u542f\u52a8\uff08\u5e76\u914d\u7f6e\uff09httpd \u4ee5\u4fbf\u63d0\u4f9b\u6587\u4ef6\u3002\u8fd9\u662f\u5bb9\u5668\u6784\u5efa\u548c\u57fa\u7840\u67b6\u6784\u4f9b\u5e94\u4e4b\u95f4\u7684\u533a\u522b\uff1a\u6784\u5efa\u955c\u50cf\u65f6\uff0c\u4f60\u53ea\u9700\u51c6\u5907\u5185\u5bb9\uff1b\u800c\u8fd0\u884c\u5bb9\u5668\u662f\u53e6\u4e00\u9879\u4efb\u52a1\u3002\u53e6\u4e00\u65b9\u9762\uff0c\u4f60\u53ef\u4ee5\u5c06\u5143\u6570\u636e\u9644\u52a0\u5230\u5bb9\u5668\u955c\u50cf\uff0c\u5b83\u4f1a\u9ed8\u8ba4\u8fd0\u884c\u547d\u4ee4\u3002<\/p>\n
\u8fd9\u6709\u4e2a\u5de5\u5177\u53ef\u4ee5\u5e2e\u52a9\u3002\u8bd5\u8bd5\u770b\u00a0ansible-bender\u00a0\u600e\u4e48\u6837\uff1f<\/p>\n
$ ansible-bender build the-playbook.yaml fedora:30 our-httpd<\/pre>\n\u8be5\u811a\u672c\u4f7f\u7528 ansible-bender \u5bf9 Fedora 30 \u5bb9\u5668\u955c\u50cf\u6267\u884c\u8be5\u5267\u672c\uff0c\u5e76\u5c06\u751f\u6210\u7684\u5bb9\u5668\u955c\u50cf\u547d\u540d\u4e3a our-httpd\u3002<\/p>\n
\u4f46\u662f\uff0c\u5f53\u4f60\u8fd0\u884c\u8be5\u5bb9\u5668\u65f6\uff0c\u5b83\u4e0d\u4f1a\u542f\u52a8 httpd\uff0c\u56e0\u4e3a\u5b83\u4e0d\u77e5\u9053\u5982\u4f55\u64cd\u4f5c\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u5411\u8be5\u5267\u672c\u6dfb\u52a0\u4e00\u4e9b\u5143\u6570\u636e\u6765\u89e3\u51b3\u6b64\u95ee\u9898\uff1a<\/p>\n
- name: Serve our file using httpd\r\nhosts: all\r\nvars:\r\nansible_bender:\r\nbase_image: fedora:30\r\ntarget_image:\r\nname: our-httpd\r\ncmd: httpd -DFOREGROUND\r\ntasks:\r\n- name: Install httpd\r\npackage:\r\nname: httpd\r\nstate: installed\r\n- name: Listen on all network interfaces.\r\nlineinfile: \r\npath: \/etc\/httpd\/conf\/httpd.conf \r\nregexp: '^Listen '\r\nline: Listen 0.0.0.0:80 \r\n- name: Copy our file to httpd\u2019s webroot\r\ncopy:\r\nsrc: our-file.txt\r\ndest: \/var\/www\/html<\/pre>\n\u73b0\u5728\u4f60\u53ef\u4ee5\u6784\u5efa\u955c\u50cf\uff08\u4ece\u8fd9\u91cc\u5f00\u59cb\uff0c\u8bf7\u4ee5 root \u7528\u6237\u8eab\u4efd\u8fd0\u884c\u6240\u6709\u547d\u4ee4\u3002\u76ee\u524d\uff0cBuildah \u548c Podman \u4e0d\u4f1a\u4e3a\u65e0 root \u5bb9\u5668\u521b\u5efa\u4e13\u7528\u7f51\u7edc\uff09\uff1a<\/p>\n
# ansible-bender build the-playbook.yaml\r\nPLAY [Serve our file using httpd] ****************************************************\r\n\r\nTASK [Gathering Facts] *************************************************************** \r\nok: [our-httpd-20191004-131941266141-cont]\r\n\r\nTASK [Install httpd] *****************************************************************\r\nloaded from cache: 'f053578ed2d47581307e9ba3f64f4b4da945579a082c6f99bd797635e62befd0'\r\nskipping: [our-httpd-20191004-131941266141-cont]\r\n\r\nTASK [Listen on all network interfaces.] *********************************************\r\nchanged: [our-httpd-20191004-131941266141-cont]\r\n\r\nTASK [Copy our file to httpd\u2019s webroot] **********************************************\r\nchanged: [our-httpd-20191004-131941266141-cont]\r\n\r\nPLAY RECAP ***************************************************************************\r\nour-httpd-20191004-131941266141-cont : ok=3 changed=2 unreachable=0 failed=0 skipped=1 rescued=0 ignored=0<\/pre>\nGetting image source signatures\r\nCopying blob sha256:4650c04b851c62897e9c02c6041a0e3127f8253fafa3a09642552a8e77c044c8\r\nCopying blob sha256:87b740bba596291af8e9d6d91e30a01d5eba9dd815b55895b8705a2acc3a825e\r\nCopying blob sha256:82c21252bd87532e93e77498e3767ac2617aa9e578e32e4de09e87156b9189a0\r\nCopying config sha256:44c6dc6dda1afe28892400c825de1c987c4641fd44fa5919a44cf0a94f58949f\r\nWriting manifest to image destination\r\nStoring signatures\r\n44c6dc6dda1afe28892400c825de1c987c4641fd44fa5919a44cf0a94f58949f\r\nImage 'our-httpd' was built successfully \\o\/<\/pre>\n\u955c\u50cf\u6784\u5efa\u5b8c\u6bd5\uff0c\u53ef\u4ee5\u8fd0\u884c\u5bb9\u5668\u4e86\uff1a<\/p>\n
# podman run our-httpd\r\nAH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 10.88.2.106. Set the 'ServerName' directive globally to suppress this message<\/pre>\n\u662f\u5426\u63d0\u4f9b\u6587\u4ef6\u4e86\uff1f\u9996\u5148\uff0c\u627e\u51fa\u4f60\u5bb9\u5668\u7684 IP\uff1a<\/p>\n
# podman inspect -f '{{ .NetworkSettings.IPAddress }}' 7418570ba5a0\r\n10.88.2.106<\/pre>\n\u4f60\u73b0\u5728\u53ef\u4ee5\u68c0\u67e5\u4e86\uff1a<\/p>\n
$ curl http:\/\/10.88.2.106\/our-file.txt\r\nAnsible is ❤<\/pre>\n\u4f60\u6587\u4ef6\u5185\u5bb9\u662f\u4ec0\u4e48\uff1f<\/p>\n
\u8fd9\u53ea\u662f\u4f7f\u7528 Ansible \u6784\u5efa\u5bb9\u5668\u955c\u50cf\u7684\u4ecb\u7ecd\u3002\u5982\u679c\u4f60\u60f3\u4e86\u89e3\u6709\u5173 ansible-bender\u00a0\u53ef\u4ee5\u505a\u4ec0\u4e48\u7684\u66f4\u591a\u4fe1\u606f\uff0c\u8bf7\u67e5\u770b\u5b83\u7684\u00a0GitHub\u00a0\u9875\u9762\u3002\u6784\u5efa\u5feb\u4e50\uff01<\/p>\n
\nvia:\u00a0https:\/\/opensource.com\/article\/19\/10\/building-container-images-ansible<\/a><\/p>\n
\u4f5c\u8005\uff1aTomas Tomecek<\/a>\u00a0\u9009\u9898\uff1alujun9972<\/a>\u00a0\u8bd1\u8005\uff1ageekpi<\/a>\u00a0\u6821\u5bf9\uff1awxy<\/a><\/p>\n
\u672c\u6587\u7531\u00a0LCTT<\/a>\u00a0\u539f\u521b\u7f16\u8bd1\uff0cLinux\u4e2d\u56fd<\/a>\u00a0\u8363\u8a89\u63a8\u51fa<\/p>\n","protected":false},"excerpt":{"rendered":"
\u5bb9\u5668\u548c Ansible \u53ef\u4ee5\u5f88\u597d\u5730\u878d\u5408\u5728\u4e00\u8d77\uff1a\u4ece\u7ba1\u7406\u548c\u7f16\u6392\u5230\u4f9b\u5e94\u548c\u6784\u5efa\u3002\u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u5c06\u91cd\u70b9\u4ecb\u7ecd\u6784\u5efa\u90e8\u5206\u3002<\/p>\n","protected":false},"author":323,"featured_media":103787,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-163033","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\/163033","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\/323"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=163033"}],"version-history":[{"count":2,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/163033\/revisions"}],"predecessor-version":[{"id":163148,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/163033\/revisions\/163148"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/103787"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=163033"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=163033"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=163033"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}