{"id":6639,"date":"2014-09-13T17:31:27","date_gmt":"2014-09-13T09:31:27","guid":{"rendered":"http:\/\/jpuyy.com\/?p=6639"},"modified":"2014-11-17T13:19:58","modified_gmt":"2014-11-17T05:19:58","slug":"ansible-variables","status":"publish","type":"post","link":"https:\/\/jpuyy.com\/?p=6639","title":{"rendered":"ansible\u4e2d\u7684\u53d8\u91cf"},"content":{"rendered":"<p>\u7528ansible\u4e5f\u6709\u4e00\u6bb5\u65f6\u95f4\u4e86\uff0c\u5728\u4f7f\u7528\u6a21\u677f\u548c\u5199playbook\u7684\u65f6\u5019\u53d8\u91cf\u5f88\u91cd\u8981\uff0c\u6574\u7406\u4e00\u4e9b\u5e38\u7528\u7684\u53d8\u91cf\u3002<\/p>\n<p>#\u5199\u5230hosts\u6587\u4ef6\u4e2d\u7684\u4e3b\u673a\u540d<\/p>\n<pre><span style=\"color: #222222;\">inventory_hostname<\/span><\/pre>\n<p>ansible\u81ea\u5e26\u7684setup\u6a21\u5757\u68c0\u6d4b\u51fa\u6765\u7684\u53d8\u91cf\u90fd\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\uff0c\u5199\u51e0\u4e2a\u5e38\u7528\u7684<\/p>\n<p>#\u7cfb\u7edf\u53d1\u884c\u5206\u652f<\/p>\n<pre class=\"p1\">ansible_distribution<\/pre>\n<p class=\"p1\"># \u4e3b\u673a\u540d<\/p>\n<pre class=\"p1\">ansible_hostname<\/pre>\n<p class=\"p1\"># \u6240\u6709\u7684cpu<\/p>\n<pre class=\"p1\">ansible_processor<\/pre>\n<p class=\"p1\"># \u786c\u4ef6\u578b\u53f7<\/p>\n<pre class=\"p1\">ansible_product_name<\/pre>\n<p class=\"p1\"># \u7cfb\u7edf\u65f6\u95f4,\u4f1a\u662f\u4e00\u7ec4\u4e0d\u540c\u65b9\u5f0f\u8868\u793a\u7684\u503c<\/p>\n<pre class=\"p1\">ansible_date_time<\/pre>\n<p class=\"p1\">\u4e3b\u673a\u7684fqdn\uff0c\u5373 hostname -f \uff0c\u5f97\u5230\u7684\u65b9\u6cd5\u662f<\/p>\n<pre class=\"p1\">ansible_fqdn<\/pre>\n<pre>python -c \"import socket; print socket.gethostname()\"\r\npython -c \"import socket; print socket.gethostbyaddr('whatever_we_got_from_last_command')\"<\/pre>\n<p>\u4e3b\u673a\u540d\u5373 hostname<\/p>\n<pre>ansible_nodename<\/pre>\n<pre>python -c \"import platform; print platform.node()\"<\/pre>\n<p>item\u53d8\u91cf\uff0c\u914d\u5408with_items\u4f7f\u7528<\/p>\n<pre>- name: install rpms\r\nyum: name={{ item }} disable_gpg_check=yes state=present\r\n\r\nwith_items:\r\n- gcc\r\n- zlib\r\n<\/pre>\n<p>\uff03eth0\u7684\u503c<\/p>\n<pre> ansible_eth0.ipv4.address<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u7528ansible\u4e5f\u6709\u4e00\u6bb5\u65f6\u95f4\u4e86\uff0c\u5728\u4f7f\u7528\u6a21\u677f\u548c\u5199playbook\u7684\u65f6\u5019\u53d8\u91cf\u5f88\u91cd\u8981\uff0c\u6574\u7406\u4e00\u4e9b\u5e38\u7528\u7684\u53d8\u91cf\u3002 #\u5199\u5230hosts\u6587\u4ef6\u4e2d\u7684\u4e3b\u673a\u540d inventory_hostname ansible\u81ea\u5e26\u7684setup\u6a21\u5757\u68c0\u6d4b\u51fa\u6765\u7684\u53d8\u91cf\u90fd\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\uff0c\u5199\u51e0\u4e2a\u5e38\u7528\u7684 #\u7cfb\u7edf\u53d1\u884c\u5206\u652f ansible_distribution # \u4e3b\u673a\u540d ansible_hostname # \u6240\u6709\u7684cpu ansible_processor # \u786c\u4ef6\u578b\u53f7 ansible_product_name # \u7cfb\u7edf\u65f6\u95f4,\u4f1a\u662f\u4e00\u7ec4\u4e0d\u540c\u65b9\u5f0f\u8868\u793a\u7684\u503c ansible_date_time \u4e3b\u673a\u7684fqdn\uff0c\u5373 hostname -f \uff0c\u5f97\u5230\u7684\u65b9\u6cd5\u662f ansible_fqdn python -c &#8220;import socket; print socket.gethostname()&#8221; python -c &#8220;import socket; print socket.gethostbyaddr(&#8216;whatever_we_got_from_last_command&#8217;)&#8221; \u4e3b\u673a\u540d\u5373 hostname ansible_nodename python -c &#8220;import platform; print platform.node()&#8221; item\u53d8\u91cf\uff0c\u914d\u5408with_items\u4f7f\u7528 &#8211; name: install rpms yum: name={{ item }} disable_gpg_check=yes state=present [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[165],"tags":[],"class_list":["post-6639","post","type-post","status-publish","format-standard","hentry","category-ops"],"_links":{"self":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/6639","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6639"}],"version-history":[{"count":11,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/6639\/revisions"}],"predecessor-version":[{"id":6860,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/6639\/revisions\/6860"}],"wp:attachment":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6639"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6639"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6639"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}