{"id":1727,"date":"2020-03-22T16:14:57","date_gmt":"2020-03-22T13:14:57","guid":{"rendered":"https:\/\/artem.services\/?p=1727"},"modified":"2020-03-22T16:14:57","modified_gmt":"2020-03-22T13:14:57","slug":"ansible-%d0%b8%d1%81%d0%bf%d0%be%d0%bb%d1%8c%d0%b7%d0%be%d0%b2%d0%b0%d1%82%d1%8c-%d0%b7%d0%bd%d0%b0%d1%87%d0%b5%d0%bd%d0%b8%d1%8f-%d0%b2-%d1%86%d0%b8%d0%ba%d0%bb%d0%b5-%d1%81-hosts-%d1%84%d0%b0","status":"publish","type":"post","link":"https:\/\/artem.services\/?p=1727","title":{"rendered":"Ansible &#8212; \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u0446\u0438\u043a\u043b\u0435 \u0441 hosts \u0444\u0430\u0439\u043b\u0430 \u043d\u0430 \u0434\u0440\u0443\u0433\u043e\u043c \u0445\u043e\u0441\u0442\u0435"},"content":{"rendered":"<p><img loading=\"lazy\" class=\"aligncenter size-full wp-image-1393\" src=\"https:\/\/artem.services\/wp-content\/uploads\/2019\/08\/ansible-logo.png\" alt=\"\" width=\"1280\" height=\"720\" srcset=\"https:\/\/artem.services\/wp-content\/uploads\/2019\/08\/ansible-logo.png 1280w, https:\/\/artem.services\/wp-content\/uploads\/2019\/08\/ansible-logo-300x169.png 300w, https:\/\/artem.services\/wp-content\/uploads\/2019\/08\/ansible-logo-768x432.png 768w, https:\/\/artem.services\/wp-content\/uploads\/2019\/08\/ansible-logo-1024x576.png 1024w, https:\/\/artem.services\/wp-content\/uploads\/2019\/08\/ansible-logo-954x537.png 954w\" sizes=\"(max-width: 1280px) 100vw, 1280px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>\u0415\u0441\u0442\u044c &quot;<strong>hosts<\/strong>&quot; \u0444\u0430\u0439\u043b, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0435\u0441\u0442\u044c \u0433\u0440\u0443\u043f\u043f\u0430 &quot;<strong>db<\/strong>&quot;. \u042d\u0442\u043e \u0438\u043d\u0441\u0442\u0430\u043d\u0441\u044b \u0441 \u0431\u0430\u0437\u0430\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442 \u0440\u0430\u0437\u043d\u0443\u044e \u0440\u043e\u043b\u044c. \u0426\u0435\u043b\u044c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0442\u0438\u043f \u0440\u043e\u043b\u0438 \u0432 &quot;<strong>hosts<\/strong>&quot; \u0444\u0430\u0439\u043b, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0442\u043e\u043c \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043c\u044b \u043c\u043e\u0433\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u0446\u0438\u043a\u043b\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u0441\u044f \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u043d\u0430 \u0434\u0440\u0443\u0433\u043e\u043c \u0445\u043e\u0441\u0442\u0435, \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443 &quot;<strong>management<\/strong>&quot;<\/p>\n<p>&nbsp;<\/p>\n<p>\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 &quot;<strong>hosts<\/strong>&quot; \u0444\u0430\u0439\u043b:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n[db]\r\ndb1 ansible_host=192.168.1.101\r\ndb2 ansible_host=192.168.1.102\r\ndb3 ansible_host=192.168.1.103\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u043c \u043a\u043b\u044e\u0447 &quot;<strong>role<\/strong>&quot; \u0441 \u043d\u0443\u0436\u043d\u044b\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0445\u043e\u0441\u0442\u0430 \u0432 \u0433\u0440\u0443\u043f\u043f\u0435 &quot;<strong>db<\/strong>&quot;:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n[db]\r\ndb1 role=development ansible_host=192.168.1.101\r\ndb2 role=staging ansible_host=192.168.1.102\r\ndb3 role=production ansible_host=192.168.1.103\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 <strong>Playbook<\/strong>&#39;\u0430:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n---\r\n\r\n- name: management\r\n  gather_facts: No\r\n  hosts: management\r\n \r\n  tasks:\r\n    - name: debug\r\n      debug:\r\n        msg: &quot;Instance {{ item.1 }} with IP {{ hostvars[ item.1 ].ansible_host }} is {{ hostvars[ item.1 ].role}}&quot;\r\n      with_indexed_items: &quot;{{ groups['db'] }}&quot;\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nok: [management] =&gt; (item=[0, u'db1']) =&gt; {\r\n    &quot;msg&quot;: &quot;Instance db1 with IP 192.168.1.101 is development&quot;\r\n}\r\nok: [management] =&gt; (item=[1, u'db2']) =&gt; {\r\n    &quot;msg&quot;: &quot;Instance db2 with IP 192.168.1.102 is staging&quot;\r\n}\r\nok: [management] =&gt; (item=[2, u'db3']) =&gt; {\r\n    &quot;msg&quot;: &quot;Instance db3 with IP 192.168.1.103 is production&quot;\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; \u0415\u0441\u0442\u044c &quot;hosts&quot; \u0444\u0430\u0439\u043b, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0435\u0441\u0442\u044c \u0433\u0440\u0443\u043f\u043f\u0430 &quot;db&quot;. \u042d\u0442\u043e \u0438\u043d\u0441\u0442\u0430\u043d\u0441\u044b \u0441 \u0431\u0430\u0437\u0430\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442 \u0440\u0430\u0437\u043d\u0443\u044e \u0440\u043e\u043b\u044c. \u0426\u0435\u043b\u044c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0442\u0438\u043f \u0440\u043e\u043b\u0438 \u0432 &quot;hosts&quot; \u0444\u0430\u0439\u043b, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0442\u043e\u043c \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043c\u044b \u043c\u043e\u0433\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u0446\u0438\u043a\u043b\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u0441\u044f \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u043d\u0430 \u0434\u0440\u0443\u0433\u043e\u043c \u0445\u043e\u0441\u0442\u0435, \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443 &quot;management&quot; &nbsp; \u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 &quot;hosts&quot; \u0444\u0430\u0439\u043b: &nbsp; \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u043a\u043b\u044e\u0447 &quot;role&quot; \u0441 \u043d\u0443\u0436\u043d\u044b\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c &hellip; <a href=\"https:\/\/artem.services\/?p=1727\" class=\"more-link\">\u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u044c \u0447\u0438\u0442\u0430\u0442\u044c<span class=\"screen-reader-text\"> &quot;Ansible &#8212; \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u0446\u0438\u043a\u043b\u0435 \u0441 hosts \u0444\u0430\u0439\u043b\u0430 \u043d\u0430 \u0434\u0440\u0443\u0433\u043e\u043c \u0445\u043e\u0441\u0442\u0435&quot;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1109],"tags":[1111,1367,1375,1373],"_links":{"self":[{"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/1727"}],"collection":[{"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1727"}],"version-history":[{"count":1,"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/1727\/revisions"}],"predecessor-version":[{"id":1729,"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/1727\/revisions\/1729"}],"wp:attachment":[{"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1727"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1727"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1727"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}