{"id":457,"date":"2022-07-14T23:06:28","date_gmt":"2022-07-14T15:06:28","guid":{"rendered":"https:\/\/frogvps.com\/?p=457"},"modified":"2022-07-14T23:06:29","modified_gmt":"2022-07-14T15:06:29","slug":"ansible-playbook%e7%9a%84%e6%a0%b8%e5%bf%83%e7%bb%84%e4%bb%b6%e8%af%a6%e8%a7%a3","status":"publish","type":"post","link":"https:\/\/frogvps.com\/?p=457","title":{"rendered":"Ansible Playbook\u7684\u6838\u5fc3\u7ec4\u4ef6\u8be6\u89e3"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"370\" src=\"https:\/\/frogvps.com\/wp-content\/uploads\/2022\/07\/20220714a1-1024x370.jpg\" alt=\"\" class=\"wp-image-458\" srcset=\"https:\/\/frogvps.com\/wp-content\/uploads\/2022\/07\/20220714a1-1024x370.jpg 1024w, https:\/\/frogvps.com\/wp-content\/uploads\/2022\/07\/20220714a1-300x108.jpg 300w, https:\/\/frogvps.com\/wp-content\/uploads\/2022\/07\/20220714a1-768x277.jpg 768w, https:\/\/frogvps.com\/wp-content\/uploads\/2022\/07\/20220714a1.jpg 1199w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Playbook\u5267\u672c\u662f\u7531\u4e00\u4e2a\u6216\u591a\u4e2a&#8221;play&#8221;\u7ec4\u6210\u7684\u5217\u8868\u3002\u5b83\u7684\u4e3b\u8981\u529f\u80fd\u5728\u4e8e\uff0c\u5c06\u9884\u5b9a\u4e49\u7684\u4e00\u7ec4\u4e3b\u673a\uff0c\u88c5\u626e\u6210\u4e8b\u5148\u901a\u8fc7ansible\u4e2d\u7684task\u5b9a\u4e49\u597d\u7684\u89d2\u8272\u3002Task\u5b9e\u9645\u662f\u8c03\u7528ansible\u7684\u4e00\u4e2amodule\uff0c\u5c06\u591a\u4e2aplay\u7ec4\u7ec7\u5728\u4e00\u4e2aplaybook\u4e2d\uff0c\u5373\u53ef\u4ee5\u8ba9\u5b83\u4eec\u8054\u5408\u8d77\u6765\uff0c\u6309\u4e8b\u5148\u7f16\u6392\u7684\u673a\u5236\u6267\u884c\u9884\u5b9a\u4e49\u7684\u52a8\u4f5c\u3002Playbook\u6587\u4ef6\u4f7f\u7528Yaml\u8bed\u8a00\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">YAML \u8bed\u8a00<\/h2>\n\n\n\n<p><strong>YAML \u8bed\u8a00\u4ecb\u7ecd<\/strong><\/p>\n\n\n\n<p>\u5b98\u65b9\u7f51\u7ad9\uff1ahttp:\/\/www.yaml.org<\/p>\n\n\n\n<p>YAML\uff1aYAML Ain&#8217;t Markup Language\uff0c\u5373YAML\u4e0d\u662f\u6807\u8bb0\u8bed\u8a00\u3002\u4e0d\u8fc7\uff0c\u5728\u5f00\u53d1\u7684\u8fd9\u79cd\u8bed\u8a00\u65f6\uff0cYAML\u7684\u610f\u601d\u5176\u5b9e\u662f\uff1a&#8221;Yet Another Markup Language&#8221;\uff08\u4ecd\u662f\u4e00\u79cd\u6807\u8bb0\u8bed\u8a00\uff09\u3002<\/p>\n\n\n\n<p>YAML\u662f\u4e00\u4e2a\u53ef\u8bfb\u6027\u9ad8\u7684\u7528\u6765\u8868\u8fbe\u8d44\u6599\u5e8f\u5217\u7684\u683c\u5f0f\u3002YAML\u53c2\u8003\u4e86\u5176\u4ed6\u591a\u79cd\u8bed\u8a00\uff0c\u5305\u62ec\uff1aXML\u3001C\u8bed\u8a00\u3001Python\u3001Perl\u4ee5\u53ca\u7535\u5b50\u90ae\u4ef6\u683c\u5f0fRFC2822\u7b49\u3002Clark Evans\u57282001\u5e74\u5728\u9996\u6b21\u53d1\u8868\u4e86\u8fd9\u79cd\u8bed\u8a00\uff0c\u53e6\u5916Ingyd\u00f6t Net\u4e0eOren Ben-Kiki\u4e5f\u662f\u8fd9\u8bed\u8a00\u7684\u5171\u540c\u8bbe\u8ba1\u8005\uff0c\u76ee\u524d\u5f88\u591a\u6700\u65b0\u7684\u8f6f\u4ef6\u6d41\u884c\u91c7\u7528YAML\u683c\u5f0f\u7684\u6587\u4ef6\u5b58\u653e\u914d\u7f6e\u4fe1\u606f\uff0c\u5982:ubuntu\uff0canisble\uff0cdocker\uff0ckubernetes\u7b49\u3002<\/p>\n\n\n\n<p><strong>YAML \u8bed\u8a00\u7279\u6027<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>YAML\u7684\u53ef\u8bfb\u6027\u597d<\/li><li>YAML\u548c\u811a\u672c\u8bed\u8a00\u7684\u4ea4\u4e92\u6027\u597d<\/li><li>YAML\u4f7f\u7528\u5b9e\u73b0\u8bed\u8a00\u7684\u6570\u636e\u7c7b\u578b<\/li><li>YAML\u6709\u4e00\u4e2a\u4e00\u81f4\u7684\u4fe1\u606f\u6a21\u578b<\/li><li>YAML\u6613\u4e8e\u5b9e\u73b0<\/li><li>YAML\u53ef\u4ee5\u57fa\u4e8e\u6d41\u6765\u5904\u7406<\/li><li>YAML\u8868\u8fbe\u80fd\u529b\u5f3a\uff0c\u6269\u5c55\u6027\u597d<\/li><\/ul>\n\n\n\n<p><strong>YAML\u8bed\u6cd5\u7b80\u4ecb<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u5728\u5355\u4e00\u6587\u4ef6\u7b2c\u4e00\u884c\uff0c\u7528\u8fde\u7eed\u4e09\u4e2a\u8fde\u5b57\u53f7&#8221;-&#8221; \u5f00\u59cb\uff0c\u8fd8\u6709\u9009\u62e9\u6027\u7684\u8fde\u7eed\u4e09\u4e2a\u70b9\u53f7( \u2026 )\u7528\u6765\u8868\u793a\u6587\u4ef6\u7684\u7ed3\u5c3e<\/li><li>\u6b21\u884c\u5f00\u59cb\u6b63\u5e38\u5199Playbook\u7684\u5185\u5bb9\uff0c\u4e00\u822c\u5efa\u8bae\u5199\u660e\u8be5Playbook\u7684\u529f\u80fd<\/li><li>\u4f7f\u7528#\u53f7\u6ce8\u91ca\u4ee3\u7801<\/li><li>\u7f29\u8fdb\u5fc5\u987b\u662f\u7edf\u4e00\u7684\uff0c\u4e0d\u80fd\u7a7a\u683c\u548ctab\u6df7\u7528<\/li><li>\u7f29\u8fdb\u7684\u7ea7\u522b\u4e5f\u5fc5\u987b\u662f\u4e00\u81f4\u7684\uff0c\u540c\u6837\u7684\u7f29\u8fdb\u4ee3\u8868\u540c\u6837\u7684\u7ea7\u522b\uff0c\u7a0b\u5e8f\u5224\u522b\u914d\u7f6e\u7684\u7ea7\u522b\u662f\u901a\u8fc7\u7f29\u8fdb\u7ed3\u5408\u6362\u884c\u6765\u5b9e\u73b0\u7684<\/li><li>YAML\u6587\u4ef6\u5185\u5bb9\u662f\u533a\u522b\u5927\u5c0f\u5199\u7684\uff0ckey\/value\u7684\u503c\u5747\u9700\u5927\u5c0f\u5199\u654f\u611f<\/li><li>\u591a\u4e2akey\/value\u53ef\u540c\u884c\u5199\u4e5f\u53ef\u6362\u884c\u5199\uff0c\u540c\u884c\u4f7f\u7528\uff0c\u5206\u9694<\/li><li>key\u540e\u9762\u5192\u53f7\u8981\u52a0\u4e00\u4e2a\u7a7a\u683c \u6bd4\u5982: key: value<\/li><li>value\u53ef\u662f\u4e2a\u5b57\u7b26\u4e32\uff0c\u4e5f\u53ef\u662f\u53e6\u4e00\u4e2a\u5217\u8868<\/li><li>YAML\u6587\u4ef6\u6269\u5c55\u540d\u901a\u5e38\u4e3ayml\u6216yaml<\/li><\/ul>\n\n\n\n<p><strong>\u652f\u6301\u7684\u6570\u636e\u7c7b\u578b<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u6807\u91cf\uff1a\u5355\u4e2a\u7684\u3001\u4e0d\u53ef\u518d\u5206\u7684\u503c<\/li><li>\u5bf9\u8c61\uff1a\u952e\u503c\u5bf9\u7684\u96c6\u5408\uff0c\u53c8\u79f0\u4e3a\u6620\u5c04\uff08mapping\uff09\/ \u54c8\u5e0c\uff08hashes\uff09 \/ \u5b57\u5178\uff08dictionary\uff09<\/li><li>\u6570\u7ec4\uff1a\u4e00\u7ec4\u6309\u6b21\u5e8f\u6392\u5217\u7684\u503c\uff0c\u53c8\u79f0\u4e3a\u5e8f\u5217\uff08sequence\uff09 \/ \u5217\u8868\uff08list\uff09<\/li><\/ul>\n\n\n\n<p><strong>scalar \u6807\u91cf<\/strong><\/p>\n\n\n\n<p>key\u5bf9\u5e94value<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>name: qinwa\nage: 20<\/code><\/pre>\n\n\n\n<p>\u4f7f\u7528\u7f29\u8fdb\u7684\u65b9\u5f0f<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>name:\n  qinwa\nage:\n  20<\/code><\/pre>\n\n\n\n<p><strong>Dictionary \u5b57\u5178<\/strong><\/p>\n\n\n\n<p>\u5b57\u5178\u7531\u591a\u4e2akey\u4e0evalue\u6784\u6210\uff0ckey\u548cvalue\u4e4b\u95f4\u7528 \u5192\u53f7\u5206\u9694\uff0c\u5e76\u4e14\u5192\u53f7\u540e\u9762\u6709\u4e00\u4e2a\u7a7a\u683c\u3002<\/p>\n\n\n\n<p>\u53ef\u4ee5\u5199\u5728\u540c\u4e00\u884c\u4e5f\u53ef\u4ee5\u4e0d\u540c\u884c\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>account: {name: root, password: 123456}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>account:\n  name: root\n  password: 123456<\/code><\/pre>\n\n\n\n<p><strong>List\u5217\u8868<\/strong><\/p>\n\n\n\n<p>\u5217\u8868\u7531\u591a\u4e2a\u5143\u7d20\u7ec4\u6210\uff0c\u6bcf\u4e2a\u5143\u7d20\u653e\u5728\u4e0d\u540c\u884c\uff0c\u4e14\u5143\u7d20\u524d\u5747\u4f7f\u7528&#8221;-&#8220;\u6253\u5934\uff0c\u5e76\u4e14 &#8211; \u540e\u6709\u4e00\u4e2a\u7a7a\u683c\uff0c\u6216\u8005\u5c06\u6240\u6709\u5143\u7d20\u7528 [ ] \u62ec\u8d77\u6765\u653e\u5728\u540c\u4e00\u884c\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>course: &#91;linux,golang,python]<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>course: \n  - linux\n  - golang\n  - python<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">playbook \u547d\u4ee4<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>ansible-playbook &lt;filename.yml&gt; ... &#91;options]<\/code><\/pre>\n\n\n\n<p><strong>\u9009\u9879<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>--syntax-check #\u8bed\u6cd5\u68c0\u67e5,\u53ef\u7f29\u5199\u6210--syntax,\u76f8\u5f53\u4e8ebash -n\n-C --check #\u6a21\u62df\u6267\u884c,\u53ea\u68c0\u6d4b\u53ef\u80fd\u4f1a\u53d1\u751f\u7684\u6539\u53d8,\u4f46\u4e0d\u771f\u6b63\u6267\u884c\u64cd\u4f5c,dry run\n--list-hosts #\u5217\u51fa\u8fd0\u884c\u4efb\u52a1\u7684\u4e3b\u673a\n--list-tags #\u5217\u51fa\u6240\u6709\u6807\u7b7e\n--list-tasks #\u5217\u51fa\u6240\u6709\u4efb\u52a1\n--limit \u4e3b\u673a\u5217\u8868 #\u53ea\u9488\u5bf9\u4e3b\u673a\u5217\u8868\u4e2d\u7684\u7279\u5b9a\u4e3b\u673a\u6267\u884c\n-i INVENTORY #\u6307\u5b9a\u4e3b\u673a\u6e05\u5355\u6587\u4ef6,\u901a\u5e38\u4e00\u4e2a\u9879\u76ee\u5bf9\u5e94\u4e00\u4e2a\u4e3b\u673a\u6e05\u5355\u6587\u4ef6\n--start-at-task START_AT_TASK #\u4ece\u6307\u5b9atask\u5f00\u59cb\u6267\u884c,\u800c\u975e\u4ece\u5934\u5f00\u59cb,START_AT_TASK\u4e3a\u4efb\u52a1\u7684name\n-v -vv -vvv #\u663e\u793a\u8fc7\u7a0b <\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Playbook \u6838\u5fc3\u7ec4\u4ef6<\/h2>\n\n\n\n<p>\u5b98\u65b9\u6587\u6863\uff1ahttps:\/\/docs.ansible.com\/ansible\/latest\/reference_appendices\/playbooks_keywords.html<\/p>\n\n\n\n<p>\u4e0b\u9762\u4f1a\u5217\u4e3eanible-playbook\u4e2d\u7684\u5e38\u7528\u7ec4\u4ef6\u3002<\/p>\n\n\n\n<p><strong>hosts \u7ec4\u4ef6<\/strong><\/p>\n\n\n\n<p>A list of groups, hosts or host pattern that translates into a list of hosts that are the play\u2019s target.<\/p>\n\n\n\n<p>\u6307\u5b9a\u8981\u6267\u884c\u4efb\u52a1\u7684\u4e3b\u673a\uff0c\u9700\u8981\u5728\u4e3b\u673a\u6e05\u5355\u4e2d\u63d0\u524d\u5b9a\u4e49\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>- hosts: webservers<\/code><\/pre>\n\n\n\n<p><strong>remote_user \u7ec4\u4ef6<\/strong><\/p>\n\n\n\n<p>User used to log into the target via the connection plugin.<\/p>\n\n\n\n<p>\u7528\u6765\u767b\u5f55\u76ee\u6807\u4e3b\u673a\u7684\u7528\u6237\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>- hosts: webservers\n  remote_user: root<\/code><\/pre>\n\n\n\n<p><strong>tasks\u7ec4\u4ef6<\/strong><\/p>\n\n\n\n<p>Main list of tasks to execute in the play, they run after <a rel=\"nofollow\" href=\"https:\/\/docs.ansible.com\/ansible\/latest\/reference_appendices\/glossary.html#term-Roles\">roles<\/a> and before <a rel=\"nofollow\" href=\"https:\/\/docs.ansible.com\/ansible\/4\/reference_appendices\/playbooks_keywords.html#term-post_tasks\">post_tasks<\/a>.<\/p>\n\n\n\n<p>PLAY\u4e2d\u6267\u884c\u7684\u4e3b\u8981\u4efb\u52a1\u6e05\u5355\u3002<\/p>\n\n\n\n<p>task\u6309\u6b21\u5e8f\u5728hosts\u4e2d\u6307\u5b9a\u7684\u6240\u6709\u4e3b\u673a\u4e0a\u6267\u884c\uff0c\u5373\u5728\u6240\u6709\u4e3b\u673a\u4e0a\u5b8c\u6210\u7b2c\u4e00\u4e2atask\u540e\uff0c\u518d\u5f00\u59cb\u7b2c\u4e8c\u4e2atask\u3002<\/p>\n\n\n\n<p>task\u7684\u76ee\u7684\u662f\u4f7f\u7528\u6307\u5b9a\u7684\u53c2\u6570\u6267\u884c\u6a21\u5757\uff0c\u800c\u5728\u6a21\u5757\u53c2\u6570\u4e2d\u53ef\u4ee5\u4f7f\u7528\u53d8\u91cf\u3002\u6a21\u5757\u6267\u884c\u662f\u5e42\u7b49\u7684\uff0c\u8fd9\u610f\u5473\u7740\u591a\u6b21\u6267\u884c\u662f\u5b89\u5168\u7684\u3002<\/p>\n\n\n\n<p>\u6bcf\u4e2atask\u90fd\u5e94\u8be5\u6709\u5b83\u7684name\uff0c\u7528\u4e8eplaybook\u6267\u884c\u7ed3\u679c\u7684\u8f93\u51fa\uff0c\u5982\u679c\u672a\u63d0\u4f9b\uff0c\u5219action\u7684\u7ed3\u679c\u5c06\u7528\u4e8e\u8f93\u51fa\u3002<\/p>\n\n\n\n<p>\u652f\u6301\u4e24\u79cd\u683c\u5f0f<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>action: module arguments\nmodule: arguments<\/code><\/pre>\n\n\n\n<p>\u8303\u4f8b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>action: shell wall \"hello world\"\nshell: wall \"hello world\"<\/code><\/pre>\n\n\n\n<p><strong>ignore_errors\u7ec4\u4ef6<\/strong><\/p>\n\n\n\n<p>Boolean that allows you to ignore task failures and continue with play. It does not affect connection errors.<\/p>\n\n\n\n<p>\u5f53\u67d0\u4e2atask\u6267\u884c\u5931\u8d25\uff0c\u5ffd\u7565\u8fd9\u6b21\u5931\u8d25\uff0c\u7ee7\u7eed\u5f80\u4e0b\u6267\u884c\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>---\n- hosts: webservers\n  tasks:\n    - name: error\n      command: \/bin\/false\n      ignore_errors: yes\n    - name: continue\n      command: wall continue<\/code><\/pre>\n\n\n\n<p>\/bin\/false \u4f1a\u8f93\u51fa\u5931\u8d25\u4fe1\u606f\u5bfc\u81f4\u4e0b\u9762\u7684\u4efb\u52a1\u65e0\u6cd5\u6267\u884c\uff0c\u53ef\u4ee5\u7528ignore_errors\u8df3\u8fc7\u5931\u8d25\u7684\u4efb\u52a1\uff0c\u7136\u540e\u7ee7\u7eed\u5f80\u4e0b\u6267\u884c\u3002<\/p>\n\n\n\n<p><strong>handlers\u7ec4\u4ef6<\/strong><\/p>\n\n\n\n<p>A section with tasks that are treated as handlers, these won\u2019t get executed normally, only when notified after each section of tasks is complete. A handler\u2019s listen field is not templatable.<\/p>\n\n\n\n<p>\u53ea\u6709\u88ab\u89e6\u53d1\u624d\u4f1a\u6267\u884c\u7684\u4efb\u52a1\u3002<\/p>\n\n\n\n<p>\u6ce8\u610f\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u5982\u679c\u591a\u4e2atask\u901a\u77e5\u4e86\u76f8\u540c\u7684handlers\uff0c \u6b64handlers\u4ec5\u4f1a\u5728\u6240\u6709tasks\u7ed3\u675f\u540e\u8fd0\u884c\u4e00 \u6b21<\/li><li>\u53ea\u6709notify\u5bf9\u5e94\u7684task\u53d1\u751f\u6539\u53d8\u4e86\u624d\u4f1a\u901a\u77e5handlers\uff0c \u6ca1\u6709\u6539\u53d8\u5219\u4e0d\u4f1a\u89e6\u53d1handlers<\/li><li>handlers \u662f\u5728\u6240\u6709\u524d\u9762\u7684tasks\u90fd\u6210\u529f\u6267\u884c\u624d\u4f1a\u6267\u884c\uff0c\u5982\u679c\u524d\u9762\u4efb\u4f55\u4e00\u4e2atask\u5931\u8d25\uff0c\u4f1a\u5bfc\u81f4handler\u8df3\u8fc7\u6267\u884c\uff0c\u53ef\u4ee5\u4f7f\u7528force_handlers: yes \u5f3a\u5236\u6267\u884chandler<\/li><\/ul>\n\n\n\n<p>\u6848\u4f8b\uff1a<\/p>\n\n\n\n<p>\u5f53httpd\u7684\u914d\u7f6e\u6587\u4ef6\u5185\u5bb9\u53d1\u751f\u6539\u53d8\uff0c\u4f1a\u89e6\u53d1\u91cd\u542f\u670d\u52a1\u548c\u5e7f\u64ad\u6d88\u606f\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>---\n- hosts: webservers\n  gather_facts: no\n  force_handlers: yes\n  tasks: \n    - name: Install Httpd\n      yum: name=httpd state=present\n    - name: Copy Config File\n      copy: src=\/tmp\/httpd.conf dest=\/etc\/httpd\/conf\n      notify: \n        - restart service\n        - wall\n\n  handlers:\n    - name: restart service\n      service: name=httpd state=restarted \n    - name: wall\n      shell: wall \"Config File changed\"<\/code><\/pre>\n\n\n\n<p><strong>tags\u7ec4\u4ef6<\/strong><\/p>\n\n\n\n<p>Tags applied to the task or included tasks, this allows selecting subsets of tasks from the command line.<\/p>\n\n\n\n<p>tags\u7528\u4e8e\u4e3a\u7279\u5b9a\u7684\u4efb\u52a1\u8bbe\u7f6e\u6807\u7b7e\uff0c\u8fd0\u884cplaybook\u65f6\u53ef\u4ee5\u53ea\u8fd0\u884c\u6307\u5b9a\u6807\u7b7e\u7684\u4efb\u52a1\u3002<\/p>\n\n\n\n<p>\u4e00\u4e2atask\u53ef\u4ee5\u6709\u591a\u4e2atag\uff0c\u4e5f\u53ef\u4ee5\u591a\u4e2atask\u5bf9\u5e94\u4e00\u4e2atag\u3002<\/p>\n\n\n\n<p>\u5173\u952e\u5b57\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>tagged \u8fd0\u884c\u5df2\u6807\u8bb0<\/li><li>untagged \u8fd0\u884c\u672a\u6807\u8bb0<\/li><li>all \u8fd0\u884c\u6240\u6709\u4efb\u52a1<\/li><\/ul>\n\n\n\n<p>\u6848\u4f8b\uff1a<\/p>\n\n\n\n<p>\u5047\u8bbe\u6211\u5199\u4e86\u4e00\u4e2ahttpd.yml<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>---\n- hosts: webservers\n  gather_facts: no\n  force_handlers: yes\n  tasks: \n    - name: Install Httpd\n      yum: name=httpd state=present\n      tags: yum\n    - name: Copy Config File\n      copy: src=\/tmp\/httpd.conf dest=\/etc\/httpd\/conf\n      notify: \n        - restart service\n        - wall\n      tags: config  \n  handlers:\n    - name: restart service\n      service: name=httpd state=restarted \n    - name: wall\n      shell: wall \"Config File changed\"<\/code><\/pre>\n\n\n\n<p>\u5217\u51fa\u6240\u6709\u7684tags<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ansible-playbook --list-tags httpd.yml <\/code><\/pre>\n\n\n\n<p>\u53ea\u5b89\u88c5\u670d\u52a1\u4e0d\u4fee\u6539\u914d\u7f6e<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ansible-playbook -t yum httpd.yml<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Playbook\u5267\u672c\u662f\u7531\u4e00\u4e2a\u6216\u591a\u4e2a&#8221;play&#8221;\u7ec4\u6210\u7684\u5217\u8868\u3002\u5b83\u7684\u4e3b\u8981\u529f\u80fd\u5728\u4e8e\uff0c\u5c06\u9884\u5b9a\u4e49\u7684\u4e00\u7ec4\u4e3b\u673a\uff0c\u88c5\u626e\u6210\u4e8b\u5148\u901a\u8fc7ansible\u4e2d\u7684task\u5b9a\u4e49\u597d\u7684\u89d2\u8272\u3002Task\u5b9e\u9645\u662f\u8c03\u7528ansible\u7684\u4e00\u4e2amodule\uff0c\u5c06\u591a\u4e2aplay&#8230;<\/p>\n","protected":false},"author":1,"featured_media":439,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[43],"tags":[44],"topic":[],"class_list":["post-457","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ansible","tag-ansible"],"_links":{"self":[{"href":"https:\/\/frogvps.com\/index.php?rest_route=\/wp\/v2\/posts\/457","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/frogvps.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/frogvps.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/frogvps.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/frogvps.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=457"}],"version-history":[{"count":1,"href":"https:\/\/frogvps.com\/index.php?rest_route=\/wp\/v2\/posts\/457\/revisions"}],"predecessor-version":[{"id":459,"href":"https:\/\/frogvps.com\/index.php?rest_route=\/wp\/v2\/posts\/457\/revisions\/459"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/frogvps.com\/index.php?rest_route=\/wp\/v2\/media\/439"}],"wp:attachment":[{"href":"https:\/\/frogvps.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=457"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/frogvps.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=457"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/frogvps.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=457"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/frogvps.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftopic&post=457"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}