{"id":2718,"date":"2017-02-19T23:54:14","date_gmt":"2017-02-19T14:54:14","guid":{"rendered":"http:\/\/tech.akat.info\/?p=2718"},"modified":"2017-02-20T00:00:13","modified_gmt":"2017-02-19T15:00:13","slug":"dynamic-inventory","status":"publish","type":"post","link":"https:\/\/tech.akat.info\/?p=2718","title":{"rendered":"Dynamic Inventory"},"content":{"rendered":"<p><a href=\"http:\/\/docs.ansible.com\/ansible\/intro_dynamic_inventory.html\">Dynamic Inventory<\/a>\u3092\u4e00\u90e8\u610f\u8a33\u3057\u3066\u307f\u305f\u3002<br \/>\n\u305f\u3076\u3093\u8aa4\u8a33\u3082\u3042\u308b\u3002\u305d\u3057\u3066\u610f\u5473\u304c\u308f\u304b\u308a\u306b\u304f\u3044\u3068\u3053\u308d\u3082\u3042\u308b\u3002<\/p>\n<h1>Topics<\/h1>\n<p>\u30af\u30e9\u30a6\u30c9\u3084LDAP\u3084Cobber\u306a\u3069\u9055\u3063\u305f\u30d7\u30e9\u30c3\u30c8\u30d5\u30a9\u30fc\u30e0\u4e0a\u306e\u30b7\u30b9\u30c6\u30e0\u306b\u3064\u3044\u3066\u3001<br \/>\ninventory\u30d5\u30a1\u30a4\u30eb\u3092\u7ba1\u7406\u3059\u308b\u3053\u3068\u304c\u53ef\u80fd\u3067\u3042\u308b\u3002<\/p>\n<p>Ansible Tower\u3067\u306fDB\u306bWEB\u3084REST\u304b\u3089\u30a2\u30af\u30bb\u30b9\u3067\u304d\u308binventry\u60c5\u5831\u3092\u4fdd\u6301\u3059\u308b\u3002<br \/>\n\u307e\u305f\u3059\u3079\u3066\u306e\u30db\u30b9\u30c8\u60c5\u5831\u3082DB\u306b\u6301\u3064\u3053\u3068\u3067\u3001playbook\u5c65\u6b74\u3092\u8ffd\u3046\u3053\u3068\u304c\u53ef\u80fd\u3002<\/p>\n<h1>Example: The Cobbler External Inventory Script<\/h1>\n<p>\u591a\u304f\u306e\u30cf\u30fc\u30c9\u30a6\u30a7\u30a2\u3092\u7ba1\u7406\u3057\u3066\u3044\u308bAnsible\u30e6\u30fc\u30b6\u304cCobber\u3092\u5229\u7528\u3057\u3066\u3044\u308b\u3068\u63a8\u6e2c\u3055\u308c\u308b\u3002<br \/>\n(\u5143Ansible, Inc\u3067\u50cd\u3044\u3066\u3044\u305fMichael DeHaan\u304c\u4f5c\u6210\u3057\u3066\u3044\u308b)<\/p>\n<p>&#8230;\u4e2d\u7565&#8230;<\/p>\n<h1>Example: AWS EC2 External Inventory Script<\/h1>\n<p>AWS\u3092\u5229\u7528\u3057\u3066\u3044\u308b\u5834\u5408\u3001\u30db\u30b9\u30c8\u306e\u5897\u6e1b\u304c\u767a\u751f\u3059\u308b\u305f\u3081inventory\u30d5\u30a1\u30a4\u30eb\u306e\u7ba1\u7406\u306f\u96e3\u3057\u3044\u305f\u3081\u3001<br \/>\nEC2 external inventory script\u3092\u5229\u7528\u3057\u305f\u307b\u3046\u304c\u3088\u3044\u3002<\/p>\n<p>\u3053\u306e\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u5229\u7528\u3059\u308b\u305f\u3081\u306b\u306f2\u3064\u306e\u65b9\u6cd5\u304c\u3042\u308b\u3002<br \/>\n1\u3064\u3081\u306f-i\u30aa\u30d7\u30b7\u30e7\u30f3\u3092\u5229\u7528\u3057\u3066ansible\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3059\u308b\u3053\u3068\u3067\u3042\u308b\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nansible -i ec2.py -u ubuntu us-east-1d -m ping\r\n<\/pre>\n<p>2\u3064\u3081\u306f\u30b9\u30af\u30ea\u30d7\u30c8\u3092\/etc\/ansible\/hosts\u306b\u30b3\u30d4\u30fc\u3057\u3001chmod +x\u3092\u5b9f\u884c\u3059\u308b\u3002<br \/>\n\u307e\u305f ec2.ini\u3092\/etc\/ansible\/ec2.ini\u306b\u30b3\u30d4\u30fc\u3059\u308b\u3002<br \/>\n\u305d\u3057\u3066\u3044\u3064\u3082\u901a\u308a\u306bansible\u3092\u5b9f\u884c\u3059\u308b\u3053\u3068\u3002<\/p>\n<p>AWS\u3078\u306eAPI\u547c\u3073\u51fa\u3057\u3092\u6b63\u5e38\u306b\u884c\u3046\u306b\u306f\u3001Boto(Python\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30a4\u30b9\u3092AWS\u306b\u8a2d\u5b9a\u3059\u308b)\u3092\u8a2d\u5b9a\u3059\u308b\u3053\u3068\u3002<br \/>\n\u5229\u7528\u53ef\u80fd\u306a\u3055\u307e\u3056\u307e\u306a\u65b9\u6cd5\u304c\u3042\u308a\u307e\u3059\u304c\u3001\u6700\u3082\u7c21\u5358\u306a\u306e\u306f\u30012\u3064\u306e\u74b0\u5883\u5909\u6570\u3092\u30a8\u30af\u30b9\u30dd\u30fc\u30c8\u3059\u308b\u3053\u3068\u3060\u3051\u3067\u3059\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nexport AWS_ACCESS_KEY_ID='AK123'\r\nexport AWS_SECRET_ACCESS_KEY='abc123'\r\n<\/pre>\n<p>\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u5b9f\u884c\u3057\u3066\u3001\u6b63\u3057\u304f\u52d5\u4f5c\u3059\u308b\u304b\u78ba\u8a8d\u53ef\u80fd<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\ncd contrib\/inventory\r\n.\/ec2.py --list\r\n<\/pre>\n<p>\u3057\u3070\u3089\u304f\u3059\u308b\u3068\u3001\u3059\u3079\u3066\u306e\u30ea\u30fc\u30b8\u30e7\u30f3\u306eEC2 inventory\u304c\u8868\u793a\u3055\u308c\u308b\u3002<br \/>\nBoto\u30d7\u30ed\u30d5\u30a1\u30a4\u30eb\u3092\u5229\u7528\u3057\u3066\u3001\u8907\u6570AWS\u30a2\u30ab\u30a6\u30f3\u30c8\u3092\u7ba1\u7406\u3059\u308b\u5834\u5408&#8211;profile PROFILE\u3068\u3044\u3046\u30aa\u30d7\u30b7\u30e7\u30f3\u3092ec2.py\u306b\u6e21\u3059\u3002<br \/>\n\u30d7\u30ed\u30d5\u30a1\u30a4\u30eb\u4f8b\u306f\u4ee5\u4e0b\u3068\u306a\u308b\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n&#x5B;profile dev]\r\naws_access_key_id = &lt;dev access key&gt;\r\naws_secret_access_key = &lt;dev secret key&gt;\r\n\r\n&#x5B;profile prod]\r\naws_access_key_id = &lt;prod access key&gt;\r\naws_secret_access_key = &lt;prod secret key&gt;\r\n<\/pre>\n<p>ec2.py &#8211;profile prod \u3092\u5b9f\u884c\u3059\u308b\u3053\u3068\u3067\u3001prod\u30a2\u30ab\u30a6\u30f3\u30c8\u306einventory\u3092\u53d6\u5f97\u3067\u304d\u308b\u3002<br \/>\n(\u305f\u3060\u3057ansible-playbook\u3067\u306f\u30b5\u30dd\u30fc\u30c8\u3055\u308c\u3066\u3044\u306a\u3044)<br \/>\nAWS_PROFILE=prod ansible-playbook -i ec2.py myplaybook.yml\u3068\u3044\u3063\u305f\u5f62\u3067ansible-playbook\u3092\u5229\u7528\u3067\u304d\u308b\u3002<br \/>\nec2.ini\u3092\u7de8\u96c6\u3059\u308b\u3053\u3068\u3067\u4f7f\u7528\u3057\u3066\u3044\u306a\u3044\u30ea\u30fc\u30b8\u30e7\u30f3\u3092\u9664\u304f\u3053\u3068\u306a\u3069\u304c\u53ef\u80fd\u3002<\/p>\n<p>\u30ad\u30e3\u30c3\u30b7\u30e5\u30b3\u30f3\u30c8\u30ed\u30fc\u30eb\u3084\u5b9b\u5148\u5909\u6570\u3092ec2.ini\u3067\u8a2d\u5b9a\u3059\u308b\u3053\u3068\u3082\u53ef\u80fd\u3002<br \/>\n\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u306fAWS\u306e\u3059\u3079\u3066\u306e\u30b5\u30fc\u30d3\u30b9\u7528\u306b\u8a2d\u5b9a\u3055\u308c\u3066\u3044\u308b\u304c\u3001\u30b3\u30e1\u30f3\u30c8\u30a2\u30a6\u30c8\u3059\u308b\u3053\u3068\u3067\u5236\u5fa1\u53ef\u80fd\u3002<br \/>\n\u4f8b\u3048\u3070RDS\u3084elasticache\u3092\u5229\u7528\u3057\u306a\u3044\u306e\u3067\u3042\u308c\u3070\u3001False\u3092\u8a2d\u5b9a\u3059\u308b\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n&#x5B;ec2]\r\n...\r\n\r\n# To exclude RDS instances from the inventory, uncomment and set to False.\r\nrds = False\r\n\r\n# To exclude ElastiCache instances from the inventory, uncomment and set to False.\r\nelasticache = False\r\n<\/pre>\n<p>inventory\u30d5\u30a1\u30a4\u30eb\u306f\u540d\u524d\u3068\u5b9b\u5148\u30a2\u30c9\u30ec\u30b9\u3092\u7d50\u3073\u3064\u3051\u308b\u3060\u3051\u3067\u3059\u3002<br \/>\n\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u8a2d\u5b9a\u3068\u3057\u3066EC2\u5916\u304b\u3089ansible\u3092\u5b9f\u65bd\u3059\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u304c\u3001\u3053\u308c\u306f\u6700\u3082\u52b9\u7387\u7684\u306a\u65b9\u6cd5\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002<\/p>\n<p>EC2\u5185\u3067ansible\u3092\u5b9f\u884c\u3057\u3066\u3044\u308b\u5834\u5408\u3001\u5185\u90e8DNS\u3068IP\u306e\u5229\u7528\u306f\u5916\u90e8DNS\u540d\u3092\u4f7f\u3046\u3088\u308a\u3082\u7406\u306b\u304b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<br \/>\n\u3053\u306e\u5834\u5408ec2.ini\u306edestination_variable\u3092\u5185\u90e8DNS\u3068\u3057\u3066\u7de8\u96c6\u3067\u304d\u307e\u3059\u3002<br \/>\nVPC\u3092\u5229\u7528\u3057\u3066\u3044\u308b\u6642\u306b\u7279\u306b\u6709\u7528\u3067\u3059\u3002<\/p>\n<p>EC2 external inventory\u306f\u8907\u6570\u306e\u30b0\u30eb\u30fc\u30d7\u3078\u306e\u30de\u30c3\u30d4\u30f3\u30b0\u304c\u53ef\u80fd\u3067\u3059\u3002<br \/>\n(Global,Instance ID,Region,Availability Zone,Security Group,Tags\u306a\u3069)<\/p>\n<p>&#8211;host=HOST \u30aa\u30d7\u30b7\u30e7\u30f3\u3092\u5229\u7528\u3057\u3066\u7279\u5b9aEC2\u3067\u5229\u7528\u3067\u304d\u308b\u5909\u6570\u3092\u53d6\u5f97\u3067\u304d\u308b\u3002<br \/>\n(ec2_architecture,ec2_description,&#8230;,ec2_vpc_id)<\/p>\n<p>\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3067\u5229\u7528\u3067\u304d\u308b\u5909\u6570\u53d6\u5f97\u65b9\u6cd5<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\ncd contrib\/inventory\r\n.\/ec2.py --host ec2-12-12-12-12.compute-1.amazonaws.com\r\n<\/pre>\n<p>AWS inventory script \u306f\u30ad\u30e3\u30c3\u30b7\u30e5\u3057\u3066API\u3092\u547c\u3073\u51fa\u3055\u306a\u3044\u3088\u3046\u306b\u3059\u308b\u305f\u3081<br \/>\nec2.ini\u306b\u30ad\u30e3\u30c3\u30b7\u30e5\u3057\u306a\u3044\u3088\u3046\u306b\u8a2d\u5b9a\u3059\u308b\u304b\u3001\u4ee5\u4e0b\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u65bd\u3059\u308b\u3053\u3068\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n.\/ec2.py --refresh-cache\r\n<\/pre>\n<h1>Example: OpenStack External Inventory Script<\/h1>\n<p>OpenStack\u30d9\u30fc\u30b9\u306e\u30af\u30e9\u30a6\u30c9\u3092\u5229\u7528\u3057\u3066\u3044\u308b\u5834\u5408\u306f\u52d5\u7684\u30a4\u30f3\u30d9\u30f3\u30c8\u30ea\u3092\u5229\u7528\u3057\u3066(openstack.py)\u3001<br \/>\nOpenStack\u304b\u3089\u76f4\u63a5\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3067\u304d\u308b\u3002<br \/>\nOpenStack inventory script \u306f\u4ee5\u4e0b\u304b\u3089\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u53ef\u80fd\u3002<br \/>\nhttps:\/\/raw.githubusercontent.com\/ansible\/ansible\/devel\/contrib\/inventory\/openstack.py<\/p>\n<p>ansible\u30b3\u30de\u30f3\u30c9\u3067-i openstack.py \u3068\u660e\u793a\u7684\u306b\u6307\u5b9a\u3059\u308b\u304b\u3001\/etc\/ansible\/hosts \u3078\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u7f6e\u304f\u3053\u3068\u3067\u5229\u7528\u53ef\u80fd\u3002<\/p>\n<p>&#8230;\u4e2d\u7565&#8230;<\/p>\n<h1>Other inventory scripts<\/h1>\n<p>Cobbler\u3084EC2\u3060\u3051\u3067\u306a\u304f\u3001\u4ee5\u4e0b\u306b\u3064\u3044\u3066\u3082inventory script\u3092\u5229\u7528\u53ef\u80fd\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nBSD Jails\r\nDigitalOcean\r\nGoogle Compute Engine\r\nLinode\r\nOpenShift\r\nOpenStack Nova\r\nOvirt\r\nSpaceWalk\r\nVagrant (not to be confused with the provisioner in vagrant, which is preferred)\r\nZabbix\r\n<\/pre>\n<p>\u4f7f\u3044\u65b9\u306e\u8a73\u7d30\u306f\u4eca\u5f8c\u8ffd\u52a0\u3055\u308c\u308b\u304b\u3082\u3057\u308c\u306a\u3044\u3002\u73fe\u72b6 contrib\/inventory \u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u304c\u308f\u304b\u308a\u3084\u3059\u3044\u3002<br \/>\n\u57fa\u672c\u7684\u306bAWS\u306e\u30b9\u30af\u30ea\u30d7\u30c8\u3068\u540c\u3058\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Dynamic Inventory\u3092\u4e00\u90e8\u610f\u8a33\u3057\u3066\u307f\u305f\u3002 \u305f\u3076\u3093\u8aa4\u8a33\u3082\u3042\u308b\u3002\u305d\u3057\u3066\u610f\u5473\u304c\u308f\u304b\u308a\u306b\u304f\u3044\u3068\u3053\u308d\u3082\u3042\u308b\u3002 Topics \u30af\u30e9\u30a6\u30c9\u3084LDAP\u3084Cobber\u306a\u3069\u9055\u3063\u305f\u30d7\u30e9\u30c3\u30c8\u30d5\u30a9\u30fc\u30e0\u4e0a\u306e\u30b7\u30b9\u30c6\u30e0\u306b\u3064\u3044\u3066\u3001 inven [&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\/2718"}],"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=2718"}],"version-history":[{"count":2,"href":"https:\/\/tech.akat.info\/index.php?rest_route=\/wp\/v2\/posts\/2718\/revisions"}],"predecessor-version":[{"id":2720,"href":"https:\/\/tech.akat.info\/index.php?rest_route=\/wp\/v2\/posts\/2718\/revisions\/2720"}],"wp:attachment":[{"href":"https:\/\/tech.akat.info\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2718"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tech.akat.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2718"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tech.akat.info\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2718"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}