{"id":2713,"date":"2017-02-05T21:43:54","date_gmt":"2017-02-05T12:43:54","guid":{"rendered":"http:\/\/tech.akat.info\/?p=2713"},"modified":"2017-02-05T22:06:35","modified_gmt":"2017-02-05T13:06:35","slug":"ansible-best-practices","status":"publish","type":"post","link":"https:\/\/tech.akat.info\/?p=2713","title":{"rendered":"Ansible Best Practices"},"content":{"rendered":"<p><a href=\"http:\/\/docs.ansible.com\/ansible\/playbooks_best_practices.html\">Best Practices<\/a>\u3092\u610f\u8a33\u3057\u3066\u307f\u305f\u3002<br \/>\n\u305f\u3076\u3093\u8aa4\u8a33\u3082\u3042\u308b\u3002Google\u7ffb\u8a33\u306e\u7cbe\u5ea6\u304c\u5411\u4e0a\u3057\u305f\u3053\u3068\u3092\u3059\u3054\u304f\u611f\u3058\u305f\u3002<\/p>\n<h2>Content Organization<\/h2>\n<p>\u6b21\u306e\u7ae0\u3067\u306f\u3001playbook\u3092\u69cb\u6210\u3059\u308b\u3055\u307e\u3056\u307e\u306a\u65b9\u6cd5\u306e1\u3064\u3092\u793a\u3057\u307e\u3059\u3002<br \/>\n\u8981\u671b\u306b\u5408\u3046\u5f62\u3067\u6539\u5909\u3057\u3066\u304f\u3060\u3055\u3044\u3002<br \/>\n\u306a\u306b\u304c\u3069\u3046\u3042\u3063\u3066\u3082role\u306f\u5fc5\u305a\u5229\u7528\u3057\u3066\u304f\u3060\u3055\u3044\uff01<\/p>\n<h3>Directory Layout<\/h3>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nproduction                # inventory file for production servers\r\nstaging                   # inventory file for staging environment\r\n\r\ngroup_vars\/\r\n   group1                 # here we assign variables to particular groups\r\n   group2                 # &quot;&quot;\r\nhost_vars\/\r\n   hostname1              # if systems need specific variables, put them here\r\n   hostname2              # &quot;&quot;\r\n\r\nlibrary\/                  # if any custom modules, put them here (optional)\r\nfilter_plugins\/           # if any custom filter plugins, put them here (optional)\r\n\r\nsite.yml                  # master playbook\r\nwebservers.yml            # playbook for webserver tier\r\ndbservers.yml             # playbook for dbserver tier\r\n\r\nroles\/\r\n    common\/               # this hierarchy represents a &quot;role&quot;\r\n        tasks\/            #\r\n            main.yml      #  &lt;-- tasks file can include smaller files if warranted\r\n        handlers\/         #\r\n            main.yml      #  &lt;-- handlers file\r\n        templates\/        #  &lt;-- files for use with the template resource\r\n            ntp.conf.j2   #  &lt;------- templates end in .j2\r\n        files\/            #\r\n            bar.txt       #  &lt;-- files for use with the copy resource\r\n            foo.sh        #  &lt;-- script files for use with the script resource\r\n        vars\/             #\r\n            main.yml      #  &lt;-- variables associated with this role\r\n        defaults\/         #\r\n            main.yml      #  &lt;-- default lower priority variables for this role\r\n        meta\/             #\r\n            main.yml      #  &lt;-- role dependencies\r\n        library\/          # roles can also include custom modules\r\n        lookup_plugins\/   # or other types of plugins, like lookup in this case\r\n\r\n    webtier\/              # same kind of structure as &quot;common&quot; was above, done for the webtier role\r\n    monitoring\/           # &quot;&quot;\r\n    fooapp\/               # &quot;&quot;\r\n<\/pre>\n<h3>Alternative Directory Layout<\/h3>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\ninventories\/\r\n   production\/\r\n      hosts               # inventory file for production servers\r\n      group_vars\/\r\n         group1           # here we assign variables to particular groups\r\n         group2           # &quot;&quot;\r\n      host_vars\/\r\n         hostname1        # if systems need specific variables, put them here\r\n         hostname2        # &quot;&quot;\r\n\r\n   staging\/\r\n      hosts               # inventory file for staging environment\r\n      group_vars\/\r\n         group1           # here we assign variables to particular groups\r\n         group2           # &quot;&quot;\r\n      host_vars\/\r\n         stagehost1       # if systems need specific variables, put them here\r\n         stagehost2       # &quot;&quot;\r\n\r\nlibrary\/\r\nfilter_plugins\/\r\n\r\nsite.yml\r\nwebservers.yml\r\ndbservers.yml\r\n\r\nroles\/\r\n    common\/\r\n    webtier\/\r\n    monitoring\/\r\n    fooapp\/\r\n<\/pre>\n<p>\u5225\u306e\u65b9\u6cd5\u3068\u3057\u3066inventory\u30d5\u30a1\u30a4\u30eb\u3068group_vars\/host_vars\u3092\u5206\u5272\u3059\u308b\u3053\u3068\u304c\u53ef\u80fd\u3002<br \/>\ngroup_vars\/host_vars \u304cproduction\u3068staging\u3067\u5171\u901a\u3067\u3042\u308b\u5fc5\u8981\u304c\u7121\u3044\u6642\u306f\u3053\u3061\u3089\u306e\u69cb\u6210\u306e\u307b\u3046\u304c\u4fbf\u5229\u3002<\/p>\n<p>\u30e1\u30ea\u30c3\u30c8\u306f\u3001\u3088\u308a\u5e83\u3044\u74b0\u5883\u3067\u306e\u67d4\u8edf\u6027\u3068\u7570\u306a\u308b\u74b0\u5883\u9593\u3067\u306e\u5909\u6570\u306e\u5b8c\u5168\u306a\u5206\u96e2\u304c\u53ef\u80fd\u3067\u3042\u308b\u3053\u3068\u3002<br \/>\n\u30c7\u30e1\u30ea\u30c3\u30c8\u306f\u3001\u30d5\u30a1\u30a4\u30eb\u304c\u5897\u3048\u3066\u3044\u308b\u305f\u3081\u4fdd\u5b88\u304c\u96e3\u3057\u3044\u3053\u3068\u3002<\/p>\n<h3>Use Dynamic Inventory With Clouds<\/h3>\n<p>\u30af\u30e9\u30a6\u30c9\u3092\u5229\u7528\u3057\u3066\u3044\u308b\u306e\u3067\u3042\u308c\u3070\u3001Dynamic Inventory\u3092\u5229\u7528\u3057\u305f\u307b\u3046\u304c\u3088\u3044\u3002<br \/>\n\u30af\u30e9\u30a6\u30c9\u3060\u3051\u3067\u306a\u304f\u30b7\u30b9\u30c6\u30e0\u304b\u3089\u30b5\u30fc\u30d0\u30ea\u30b9\u30c8\u3092\u51fa\u529b\u3067\u304d\u308b\u3088\u3046\u306a\u5834\u5408\u3082\u3001<br \/>\nDynamic Inventory\u3092\u5229\u7528\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3002<br \/>\n(\u53c2\u8003:<a href=\"http:\/\/qiita.com\/shufo\/items\/0e8b11b8777c5ed24e0b\">Ansible dynamic inventory + Zabbix API\u3067\u76e3\u8996\u5bfe\u8c61\u3092\u52d5\u7684\u306b\u69cb\u6210\u7ba1\u7406<\/a>)<\/p>\n<h3>How to Differentiate Staging vs Production<\/h3>\n<p>inventory\u30d5\u30a1\u30a4\u30eb\u5206\u985e\u65b9\u6cd5\u3092\u3088\u304f\u805e\u304b\u308c\u308b\u3002\u4ee5\u4e0b\u306f\u305d\u306e\u3088\u3044\u4f8b\u3067\u3042\u308b\u3002<br \/>\n\u30b0\u30eb\u30fc\u30d7\u5316\u65b9\u6cd5\u3092\u52d5\u7684\u30a4\u30f3\u30d9\u30f3\u30c8\u30ea\u306b\u9069\u7528\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u4ee5\u4e0b\u306e\u4f8b\u3067\u306f\u3059\u3079\u3066\u306e\u672c\u756a\u30db\u30b9\u30c8\u304c\u3072\u3068\u3064\u306einventory\u30d5\u30a1\u30a4\u30eb\u306b\u542b\u307e\u308c\u3066\u3044\u307e\u3059\u3002<br \/>\n\u30db\u30b9\u30c8\u306e\u76ee\u7684\u3001\u30c7\u30fc\u30bf\u30bb\u30f3\u30bf\u30fc\u306e\u5834\u6240\u306a\u3069\u306b\u57fa\u3065\u3044\u3066\u306e\u30b0\u30eb\u30fc\u30d7\u5b9a\u7fa9\u3092\u30aa\u30b9\u30b9\u30e1\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n# file: production\r\n\r\n&#x5B;atlanta-webservers]\r\nwww-atl-1.example.com\r\nwww-atl-2.example.com\r\n\r\n&#x5B;boston-webservers]\r\nwww-bos-1.example.com\r\nwww-bos-2.example.com\r\n\r\n&#x5B;atlanta-dbservers]\r\ndb-atl-1.example.com\r\ndb-atl-2.example.com\r\n\r\n&#x5B;boston-dbservers]\r\ndb-bos-1.example.com\r\n\r\n# webservers in all geos\r\n&#x5B;webservers:children]\r\natlanta-webservers\r\nboston-webservers\r\n\r\n# dbservers in all geos\r\n&#x5B;dbservers:children]\r\natlanta-dbservers\r\nboston-dbservers\r\n\r\n# everything in the atlanta geo\r\n&#x5B;atlanta:children]\r\natlanta-webservers\r\natlanta-dbservers\r\n\r\n# everything in the boston geo\r\n&#x5B;boston:children]\r\nboston-webservers\r\nboston-dbservers\r\n<\/pre>\n<h3>Group And Host Variables<\/h3>\n<p>\u30b0\u30eb\u30fc\u30d7\u5316\u3059\u308b\u3053\u3068\u3067\u3059\u3079\u3066\u3046\u307e\u304f\u3044\u304f\u308f\u3051\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002\u5909\u6570\u3092\u5272\u308a\u5f53\u3066\u308b\u3053\u3068\u3082\u53ef\u80fd\u3067\u3059\u3002<br \/>\n\u4f8b\u3048\u3070\u30a2\u30c8\u30e9\u30f3\u30bf\u306b\u306f\u72ec\u81ea\u306eNTP\u30b5\u30fc\u30d0\u304c\u3042\u308b\u5834\u5408\u3001<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n---\r\n# file: group_vars\/atlanta\r\nntp: ntp-atlanta.example.com\r\nbackup: backup-atlanta.example.com\r\n<\/pre>\n<p>WEB\u30b5\u30fc\u30d0\u5c02\u7528\u306e\u5909\u6570\u306f<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n---\r\n# file: group_vars\/webservers\r\napacheMaxRequestsPerChild: 3000\r\napacheMaxClients: 900\r\n<\/pre>\n<p>\u3082\u3057\u30c7\u30d5\u30a9\u30eb\u30c8\u5024\u304c\u5b58\u5728\u3059\u308b\u5834\u5408\u306f<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n---\r\n# file: group_vars\/all\r\nntp: ntp-boston.example.com\r\nbackup: backup-boston.example.com\r\n<\/pre>\n<p>\u7279\u5b9a\u306e\u30cf\u30fc\u30c9\u30a6\u30a7\u30a2\u306e\u307f\u306b\u9069\u7528\u3059\u308b\u5834\u5408\u306f(\u5fc5\u8981\u304c\u306a\u3051\u308c\u3070\u907f\u3051\u305f\u307b\u3046\u304c\u3088\u3044\u304c)<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n---\r\n# file: host_vars\/db-bos-1.example.com\r\nfoo_agent_port: 86\r\nbar_agent_port: 99\r\n<\/pre>\n<p>Dynamic Inventory\u3092\u5229\u7528\u3059\u308b\u5834\u5408\u306f\u3001\u81ea\u52d5\u7684\u306b\u30b0\u30eb\u30fc\u30d7\u304c\u4f5c\u6210\u3055\u308c\u308b\u305f\u3081\u8981\u6ce8\u610f\u3002<\/p>\n<h3>Top Level Playbooks Are Separated By Role<\/h3>\n<p>site.yml:\u30a4\u30f3\u30d5\u30e9\u30b9\u30c8\u30e9\u30af\u30c1\u30e3\u5168\u4f53\u3092\u5b9a\u7fa9\u3059\u308bplaybook\u304c\u542b\u307e\u308c\u3066\u3044\u308b\u3002\u305d\u306e\u305f\u3081\u3068\u3066\u3082\u77ed\u3044\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n---\r\n# file: site.yml\r\n- include: webservers.yml\r\n- include: dbservers.yml\r\n<\/pre>\n<p>webservers.yml\u306a\u3069\u306f\u30b0\u30eb\u30fc\u30d7\u3068role\u3092\u6307\u5b9a\u3059\u308b\u3060\u3051\u306b\u3059\u308b\u3053\u3068\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n---\r\n# file: webservers.yml\r\n- hosts: webservers\r\n  roles:\r\n    - common\r\n    - webtier\r\n<\/pre>\n<p>webservers\u3067\u306e\u5b9f\u884c\u306f2\u3064\u306e\u65b9\u6cd5\u304c\u3042\u308b<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nansible-playbook site.yml --limit webservers\r\nansible-playbook webservers.yml\r\n<\/pre>\n<h3>Task And Handler Organization For A Role<\/h3>\n<p>\u4ee5\u4e0b\u306fNTP\u30b5\u30fc\u30d0\u3092\u8a2d\u5b9a\u3059\u308btask\u30d5\u30a1\u30a4\u30eb\u3067\u3059\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n---\r\n# file: roles\/common\/tasks\/main.yml\r\n\r\n- name: be sure ntp is installed\r\n  yum: name=ntp state=installed\r\n  tags: ntp\r\n\r\n- name: be sure ntp is configured\r\n  template: src=ntp.conf.j2 dest=\/etc\/ntp.conf\r\n  notify:\r\n    - restart ntpd\r\n  tags: ntp\r\n\r\n- name: be sure ntpd is running and enabled\r\n  service: name=ntpd state=started enabled=yes\r\n  tags: ntp\r\n<\/pre>\n<p>\u4ee5\u4e0b\u304chandler\u30d5\u30a1\u30a4\u30eb\u3068\u306a\u308a\u307e\u3059\u3002\u30bf\u30b9\u30af\u306b\u5909\u66f4\u304c\u3042\u3063\u305f\u5834\u5408\u6700\u5f8c\u306b\u5b9f\u884c\u3055\u308c\u307e\u3059\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n---\r\n# file: roles\/common\/handlers\/main.yml\r\n- name: restart ntpd\r\n  service: name=ntpd state=restarted\r\n<\/pre>\n<h3>What This Organization Enables (Examples)<\/h3>\n<p>\u5b9f\u884c\u4f8b\u306b\u3064\u3044\u3066\u3002<br \/>\n\u3059\u3079\u3066\u306e\u69cb\u6210\u3092\u53cd\u6620\u3055\u305b\u308b\u5834\u5408<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nansible-playbook -i production site.yml\r\n<\/pre>\n<p>NTP\u306e\u307f\u3092\u518d\u69cb\u6210\u3059\u308b\u5834\u5408<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nansible-playbook -i production site.yml --tags ntp\r\n<\/pre>\n<p>webservers\u3092\u518d\u69cb\u6210\u3059\u308b\u5834\u5408<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nansible-playbook -i production webservers.yml\r\n<\/pre>\n<p>\u30dc\u30b9\u30c8\u30f3\u306ewebservers\u3092\u518d\u69cb\u6210\u3059\u308b\u5834\u5408<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nansible-playbook -i production webservers.yml --limit boston\r\n<\/pre>\n<p>10\u30db\u30b9\u30c8\u305a\u3064\u518d\u69cb\u6210\u3059\u308b\u5834\u5408<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nansible-playbook -i production webservers.yml --limit boston&#x5B;1-10]\r\nansible-playbook -i production webservers.yml --limit boston&#x5B;11-20]\r\n<\/pre>\n<p>\u57fa\u672c\u7684\u306a\u4f7f\u3044\u65b9\u3082\u53ef\u80fd<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nansible boston -i production -m ping\r\nansible boston -i production -m command -a '\/sbin\/reboot'\r\n<\/pre>\n<p>\u6709\u7528\u306a\u30b3\u30de\u30f3\u30c9\u3082\u899a\u3048\u3066\u304a\u304f\u3079\u304d<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n# confirm what task names would be run if I ran this command and said &quot;just ntp tasks&quot;\r\nansible-playbook -i production webservers.yml --tags ntp --list-tasks\r\n\r\n# confirm what hostnames might be communicated with if I said &quot;limit to boston&quot;\r\nansible-playbook -i production webservers.yml --limit boston --list-hosts\r\n<\/pre>\n<h3>Deployment vs Configuration Organization<\/h3>\n<p>\u4e0a\u8a18\u306e\u8a2d\u8a08\u30e2\u30c7\u30eb\u306f\u5178\u578b\u7684\u306a\u3082\u306e\u3002\u8907\u6570\u5c64\u3067\u306e\u30c7\u30d7\u30ed\u30a4\u304c\u5fc5\u8981\u306a\u5834\u5408\u306fplaybook\u304c\u8ffd\u52a0\u3055\u308c\u3001<br \/>\nsite.yml \u306f deploy_exampledotcom.yml \u3068\u3044\u3063\u305fplaybook\u304c\u8ffd\u52a0\u3055\u308c\u308b\u304b\u3082\u3057\u308c\u306a\u3044\u304c\u3001\u4e0a\u8a18\u8a2d\u8a08\u30e2\u30c7\u30eb\u3068\u69cb\u6210\u306f\u5909\u308f\u3089\u306a\u3044\u3002<\/p>\n<p>1\u3064\u306eplays\u306b\u3053\u3060\u308f\u3089\u305a\u3001\u72b6\u6cc1\u3084\u76ee\u7684\u306b\u5408\u308f\u305b\u3066plays\u3092\u4f5c\u6210\u3057\u305f\u307b\u3046\u304c\u3088\u3044\u3002<\/p>\n<p>\u540c\u3058\u30c4\u30fc\u30eb\u3092\u5229\u7528\u3057\u3066\u30c7\u30d7\u30ed\u30a4\u3067\u304d\u308b\u305f\u3081\u3001\u30b0\u30eb\u30fc\u30d7\u3092\u518d\u5229\u7528\u3057\u3001\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u8a2d\u5b9a\u3068\u306f\u5225\u306eplaybook\u306bOS\u8a2d\u5b9a\u3092\u4fdd\u5b58\u3059\u308c\u3070\u3088\u3044\u3002<\/p>\n<h3>Staging vs Production<\/h3>\n<p>\u3059\u3067\u306b\u8a18\u8f09\u3057\u3066\u3044\u308b\u304c\u30b9\u30c6\u30fc\u30b8\u30f3\u30b0\u74b0\u5883\u3068\u672c\u756a\u74b0\u5883\u3092\u5225\u3005\u306b\u3059\u308b\u305f\u3081\u306b\u306f inventory \u30d5\u30a1\u30a4\u30eb\u3092\u5225\u3005\u306b\u3057\u305f\u307b\u3046\u304c\u3088\u3044\u3002<br \/>\n1\u3064\u306einventory\u30d5\u30a1\u30a4\u30eb\u306b\u3057\u3066\u3057\u307e\u3046\u3068\u3001\u4e88\u671f\u305b\u306c\u52d5\u4f5c\u3092\u3059\u308b\u53ef\u80fd\u6027\u304c\u3042\u308b\u3002<\/p>\n<p>\u672c\u756a\u74b0\u5883\u306e\u524d\u306b\u30b9\u30c6\u30fc\u30b8\u30f3\u30b0\u74b0\u5883\u3067\u8a66\u3059\u3053\u3068\u306f\u975e\u5e38\u306b\u826f\u3044\u3053\u3068\u3002\u30b5\u30a4\u30ba\u304c\u9055\u3046\u5834\u5408\u306f\u3001\u30b0\u30eb\u30fc\u30d7\u5909\u6570\u3067\u5236\u5fa1\u3059\u308b\u3053\u3068\u3002<\/p>\n<h3>Rolling Updates<\/h3>\n<p>\u2018serial\u2019 \u30ad\u30fc\u30ef\u30fc\u30c9\u3092\u7406\u89e3\u3059\u308b\u3053\u3068\u3002\u3053\u308c\u3092\u5229\u7528\u3057\u3066\u3001\u5236\u5fa1\u3059\u308b\u3053\u3068\u3002<br \/>\n<a href=\"http:\/\/docs.ansible.com\/ansible\/playbooks_delegation.html\">Delegation, Rolling Updates, and Local Actions<\/a><\/p>\n<h3>Always Mention The State<\/h3>\n<p>state\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u306f\u591a\u304f\u306e\u30e2\u30b8\u30e5\u30fc\u30eb\u3067\u5229\u7528\u3055\u308c\u3066\u3044\u308b\u3002<br \/>\n\u2018state=present\u2019\u3084\u2018state=absent\u2019\u306b\u3064\u3044\u3066playbook\u306b\u660e\u793a\u7684\u306b\u8a18\u8f09\u3057\u3066\u304a\u3044\u305f\u307b\u3046\u304c\u3088\u3044\u3002<\/p>\n<h3>Group By Roles<\/h3>\n<p>\u30b7\u30b9\u30c6\u30e0\u306b\u306f\u8907\u6570\u306e\u30b0\u30eb\u30fc\u30d7\u304c\u3042\u308b\u3002<br \/>\nplaybook\u306f\u5f79\u5272\u3054\u3068\u306b\u4f5c\u6210\u3059\u308b\u3053\u3068\u304c\u5927\u5207\u3002<\/p>\n<h3>Operating System and Distribution Variance<\/h3>\n<p>\u7570\u306a\u308bOS\u9593\u3067\u3053\u3068\u306a\u308b\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u3092\u5229\u7528\u3059\u308b\u5834\u5408\u3001group_by \u30e2\u30b8\u30e5\u30fc\u30eb\u306e\u5229\u7528\u304c\u30aa\u30b9\u30b9\u30e1\u3002<br \/>\ninventory\u3067\u5b9a\u7fa9\u3057\u306a\u304f\u3066\u3082\u3001\u7279\u5b9a\u306e\u6761\u4ef6\u306b\u4e00\u81f4\u3059\u308b\u52d5\u7684\u306a\u30b0\u30eb\u30fc\u30d7\u304c\u4f5c\u6210\u3055\u308c\u308b\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n---\r\n\r\n# talk to all hosts just so we can learn about them\r\n- hosts: all\r\n  tasks:\r\n     - group_by: key=os_{{ ansible_distribution }}\r\n\r\n# now just on the CentOS hosts...\r\n\r\n- hosts: os_CentOS\r\n  gather_facts: False\r\n  tasks:\r\n     - # tasks that only happen on CentOS go here\r\n<\/pre>\n<p>\u3053\u308c\u306b\u3088\u308a\u3059\u3079\u3066\u306e\u30db\u30b9\u30c8\u304cOS\u306b\u57fa\u3065\u3044\u305f\u52d5\u7684\u30b0\u30eb\u30fc\u30d7\u306b\u5206\u985e\u3055\u308c\u308b\u3002<br \/>\n\u30b0\u30eb\u30fc\u30d7\u7279\u6709\u306e\u8a2d\u5b9a\u304c\u5fc5\u8981\u306a\u5834\u5408\u306f\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u8a2d\u5b9a\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n---\r\n# file: group_vars\/all\r\nasdf: 10\r\n\r\n---\r\n# file: group_vars\/os_CentOS\r\nasdf: 42\r\n<\/pre>\n<p>\u4e0a\u306e\u4f8b\u3067\u306f\u3001CentOS\u30de\u30b7\u30f3\u306fasdf\u306b42\u306e\u5024\u3092\u53d6\u5f97\u3057\u307e\u3059\u304c\u3001\u4ed6\u306e\u30de\u30b7\u30f3\u306f10\u306b\u306a\u308b\u3002<br \/>\n\u3053\u308c\u306f\u5909\u6570\u306e\u8a2d\u5b9a\u3060\u3051\u3067\u306a\u304f\u3001\u7279\u5b9a\u306e\u30b7\u30b9\u30c6\u30e0\u306b\u7279\u5b9a\u306e\u5f79\u5272\u3092\u9069\u7528\u3059\u308b\u305f\u3081\u306b\u3082\u4f7f\u7528\u3067\u304d\u308b\u3002<br \/>\n\u5909\u6570\u3060\u3051\u304c\u5fc5\u8981\u306a\u5834\u5408\u306f\u3001OS\u540d\u306b\u57fa\u3065\u3044\u3066\u5909\u6570\u304c\u53d6\u308a\u8fbc\u3080\u3053\u3068\u3082\u53ef\u80fd\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n- hosts: all\r\n  tasks:\r\n    - include_vars: &quot;os_{{ ansible_distribution }}.yml&quot;\r\n    - debug: var=asdf\r\n<\/pre>\n<h3>Bundling Ansible Modules With Playbooks<\/h3>\n<p>library\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u304c\u3042\u308b\u5834\u5408\u3001\u81ea\u52d5\u7684\u306bansible\u306e\u30e2\u30b8\u30e5\u30fc\u30eb\u30d1\u30b9\u3068\u3057\u3066\u8a8d\u8b58\u3055\u308c\u308b\u3002<br \/>\nplaybook\u3067\u5b9f\u884c\u3055\u308c\u308b\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u4fdd\u6301\u3059\u308b\u305f\u3081\u306e\u3088\u3044\u65b9\u6cd5\u3002<\/p>\n<h3>Whitespace and Comments<\/h3>\n<p>\u7a7a\u767d\u3092\u5229\u7528\u3057\u3066\u308f\u304b\u308a\u3084\u3059\u304f\u3059\u308b\u3053\u3068\u3001#\u3067\u306e\u30b3\u30e1\u30f3\u30c8\u3092\u63a8\u5968\u3002<\/p>\n<h3>Always Name Tasks<\/h3>\n<p>\u30bf\u30b9\u30af\u306e\u540d\u524d\u306f\u8a18\u8f09\u3057\u306a\u304f\u3066\u3082\u3088\u3044\u304c\u3001\u30bf\u30b9\u30af\u306e\u76ee\u7684\u3092\u8a18\u8f09\u3059\u308b\u3053\u3068\u3092\u63a8\u5968\u3002<br \/>\nplaybook\u5b9f\u884c\u6642\u306b\u8868\u793a\u3055\u308c\u308b\u3002<\/p>\n<h3>Keep It Simple<\/h3>\n<p>\u3068\u304f\u304b\u304f\u30b7\u30f3\u30d7\u30eb\u306b\u3002ansible\u306e\u3059\u3079\u3066\u306e\u6a5f\u80fd\u30921\u5ea6\u306b\u4f7f\u3044\u5206\u3051\u3066\u306f\u3044\u3051\u306a\u3044\u3002<br \/>\n\u5fc5\u8981\u306a\u3044\u3082\u306e(vars,vars_files,vars_prompt,&#8211;extra-vars )\u306f\u5229\u7528\u3057\u306a\u3044\u3053\u3068\u3002<\/p>\n<h3>Version Control<\/h3>\n<p>git\u306a\u3069\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u7ba1\u7406\u30b7\u30b9\u30c6\u30e0\u3092\u5229\u7528\u3057\u3001\u5909\u66f4\u3057\u305f\u7406\u7531\u304c\u308f\u304b\u308b\u3088\u3046\u306b\u3057\u3066\u304a\u304f\u3053\u3068\u3002<\/p>\n<h3>Variables and Vaults<\/h3>\n<p>\u4e00\u822c\u7684\u306a\u7ba1\u7406\u65b9\u6cd5\u3068\u3057\u3066\u3001\u5909\u6570\u3092\u898b\u3064\u3051\u308b\u305f\u3081\u306bgrep\u306a\u3069\u306e\u30c4\u30fc\u30eb\u304c\u5229\u7528\u3055\u308c\u307e\u3059\u3002<br \/>\n\u6697\u53f7\u5316\u306a\u3069\u3067\u8986\u3044\u96a0\u3055\u308c\u3066\u3044\u308b\u3068\u304d\u306f\u3001\u9593\u63a5\u7684\u306b\u4f5c\u696d\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<br \/>\nplaybook\u5b9f\u884c\u6642\u306b\u6697\u53f7\u5316\u3055\u308c\u3066\u3044\u306a\u3044\u30d5\u30a1\u30a4\u30eb\u304b\u3089\u5909\u6570\u3092\u53d6\u5f97\u3057<br \/>\n\u6a5f\u5bc6\u5909\u6570\u306f\u6697\u53f7\u5316\u3055\u308c\u305f\u30d5\u30a1\u30a4\u30eb\u304b\u3089\u53d6\u5f97\u3057\u307e\u3059\u3002<\/p>\n<p>\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9\u3068\u3057\u3066\u3001group_vars\/ \u306e\u30b5\u30d6\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u5229\u7528\u3059\u308b\u3002<br \/>\nvars \u3068 vault \u3068\u3044\u30462\u3064\u306e\u30d5\u30a1\u30a4\u30eb\u540d\u3084\u30d7\u30ec\u30d5\u30a3\u30c3\u30af\u30b9\u3092\u5229\u7528\u3059\u308b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Best Practices\u3092\u610f\u8a33\u3057\u3066\u307f\u305f\u3002 \u305f\u3076\u3093\u8aa4\u8a33\u3082\u3042\u308b\u3002Google\u7ffb\u8a33\u306e\u7cbe\u5ea6\u304c\u5411\u4e0a\u3057\u305f\u3053\u3068\u3092\u3059\u3054\u304f\u611f\u3058\u305f\u3002 Content Organization \u6b21\u306e\u7ae0\u3067\u306f\u3001playbook\u3092\u69cb\u6210\u3059\u308b\u3055\u307e\u3056\u307e\u306a\u65b9\u6cd5\u306e1\u3064\u3092 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[42],"tags":[],"_links":{"self":[{"href":"https:\/\/tech.akat.info\/index.php?rest_route=\/wp\/v2\/posts\/2713"}],"collection":[{"href":"https:\/\/tech.akat.info\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tech.akat.info\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tech.akat.info\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tech.akat.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2713"}],"version-history":[{"count":3,"href":"https:\/\/tech.akat.info\/index.php?rest_route=\/wp\/v2\/posts\/2713\/revisions"}],"predecessor-version":[{"id":2716,"href":"https:\/\/tech.akat.info\/index.php?rest_route=\/wp\/v2\/posts\/2713\/revisions\/2716"}],"wp:attachment":[{"href":"https:\/\/tech.akat.info\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2713"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tech.akat.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2713"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tech.akat.info\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2713"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}