{"id":312576,"date":"2020-11-05T09:00:25","date_gmt":"2020-11-05T09:00:25","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=312576"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=312576","title":{"rendered":"\u0420\u0430\u0441\u043f\u0443\u0442\u044b\u0432\u0430\u044f Ansible Loops"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\">\n<p>\u0412 \u043f\u043e\u0441\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 Ansible \u043c\u043e\u0434\u0443\u043b\u0438 loop: with_items, with_nested, with_subelements, with_dict.<\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<p>\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 <a href=\"https:\/\/github.com\/ctorgalson\/ansible-loops\" rel=\"nofollow\">https:\/\/github.com\/ctorgalson\/ansible-loops<\/a><\/p>\n<p>  <\/p>\n<p>\u041e\u0434\u043d\u0430 \u0438\u0437 \u043c\u043e\u0438\u0445 \u0440\u043e\u043b\u0435\u0439 \u0432 Chromatic \u2014 \u0447\u043b\u0435\u043d \u043a\u043e\u043c\u0430\u043d\u0434\u044b DevOps. \u041f\u043e\u043c\u0438\u043c\u043e \u043f\u0440\u043e\u0447\u0435\u0433\u043e, \u044d\u0442\u043e \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0432 \u0441\u0435\u0431\u044f \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u043d\u0430\u0448\u0438\u043c\u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u0430\u043c\u0438 \u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u0430\u043c\u0438 \u043d\u0430\u0448\u0438\u0445 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432. \u042d\u0442\u043e, \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u044f \u0442\u0440\u0430\u0447\u0443 \u043c\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043d\u0430 \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 <a href=\"https:\/\/www.ansible.com\/\" rel=\"nofollow\">Ansible<\/a>, \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u043c \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u043c \u0434\u043b\u044f \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0438 \u0440\u0430\u0437\u0432\u0435\u0440\u0442\u044b\u0432\u0430\u043d\u0438\u044f \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u0432 \u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u043e\u0449\u0435 \u0433\u043e\u0432\u043e\u0440\u044f, \u043c\u0430\u0448\u0438\u043d\u0430, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0437\u0430\u043f\u0443\u0449\u0435\u043d Ansible, \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u043d\u0430 \u0434\u0440\u0443\u0433\u043e\u043c \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u0435 \u0447\u0435\u0440\u0435\u0437 SSH. \u042d\u0442\u0438 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f <a href=\"http:\/\/latentflip.com\/imperative-vs-declarative\" rel=\"nofollow\">\u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0442\u0438\u0432\u043d\u043e (\u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e)<\/a> \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0443\u0447\u0430\u0441\u0442\u043a\u043e\u0432 YAML, \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0445 \u0437\u0430\u0434\u0430\u0447\u0430\u043c\u0438. \u042d\u0442\u0438 TASKS \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0442 <a href=\"https:\/\/github.com\/ansible\/ansible-modules-core\" rel=\"nofollow\">\u043c\u043e\u0434\u0443\u043b\u0438 Ansible<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u043d\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u043e\u043f\u0446\u0438\u0439 \u0441 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u043c\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u043c\u0438, \u0442\u0430\u043a\u0438\u043c\u0438 \u043a\u0430\u043a \u0444\u0430\u0439\u043b\u044b, \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0442. \u0434.<\/p>\n<p>  <\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043c\u043e\u0434\u0443\u043b\u044c File (<a href=\"http:\/\/docs.ansible.com\/ansible\/2.4\/file_module.html\" rel=\"nofollow\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f<\/a>, <a href=\"https:\/\/github.com\/ansible\/ansible-modules-core\/blob\/devel\/files\/file.py\" rel=\"nofollow\">\u043a\u043e\u0434<\/a>) \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0430, \u0435\u0441\u043b\u0438 \u043e\u043d \u0435\u0449\u0435 \u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442, \u0438 \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442 \u0435\u0433\u043e \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b, \u0435\u0441\u043b\u0438 \u043e\u043d\u0438 \u0435\u0449\u0435 \u043d\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u044b \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">- file:     path: \/home\/jenkins\/.ssh     state: directory     owner: jenkins     group: jenkins     mode: 700<\/code><\/pre>\n<p>  <\/p>\n<p>\u041d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0437\u0430\u0434\u0430\u0447, \u043e\u0442\u043d\u043e\u0441\u044f\u0449\u0438\u0445\u0441\u044f \u043a \u043e\u0434\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0435, \u0441\u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u0432 \u0440\u043e\u043b\u0438, \u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u043e\u043b\u0435\u0439 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0441\u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u0432 playbooks. \u0417\u0430\u0442\u0435\u043c \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c playbook \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0442\u043e\u0447\u043d\u043e \u0442\u0430\u043a\u0438\u0445 \u0436\u0435 \u0448\u0430\u0433\u043e\u0432 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u043d\u0430 \u043b\u044e\u0431\u043e\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435 \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u0432 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e. <\/p>\n<p>  <\/p>\n<h4 id=\"ansible-deklarativnyy\">Ansible \u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0442\u0438\u0432\u043d\u044b\u0439?<\/h4>\n<p>  <\/p>\n<p>TASKS Ansible \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0442\u0438\u0432\u043d\u043e, \u0442\u043e \u0435\u0441\u0442\u044c \u043c\u044b \u043d\u0435 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c, \u043a\u0430\u043a\u0430\u044f \u0431\u0430\u0437\u043e\u0432\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0434\u043e\u043b\u0436\u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f TASKS. \u042d\u0442\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u043e, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u0432\u044b\u0441\u043e\u043a\u0438\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u0438, \u043e\u0447\u0435\u043d\u044c \u0447\u0438\u0442\u0430\u0435\u043c\u044b\u0439 \u0438 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0434\u043b\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u043a\u043e\u0434\u0430, \u0430 \u0432 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0430\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0434\u043d\u0443 \u0438 \u0442\u0443 \u0436\u0435 \u0437\u0430\u0434\u0430\u0447\u0443 \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0430\u0445. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u0442\u044c \u043c\u043e\u0434\u0443\u043b\u044c <a href=\"http:\/\/docs.ansible.com\/ansible\/2.4\/copy_module.html\" rel=\"nofollow\">Ansible Copy<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0444\u0430\u0439\u043b\u043e\u0432 \u043d\u0430 \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440. \u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0437\u0430\u0434\u0430\u0447\u0435 Ansible \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u0442 \u0444\u0430\u0439\u043b \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u0432 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u043a\u0430\u0442\u0430\u043b\u043e\u0433 \u043d\u0430 \u0443\u0434\u0430\u043b\u0435\u043d\u043d\u043e\u043c \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u0435 \u0438 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u0432\u043b\u0430\u0434\u0435\u043b\u044c\u0446\u0430, \u0433\u0440\u0443\u043f\u043f\u0443 \u0438 \u043f\u0440\u0430\u0432\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0444\u0430\u0439\u043b\u0443:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">- name: Copy SSH config file into Alice\u2019s .ssh directory.   copy:     src: files\/config     dest: \/home\/alice\/.ssh\/config     owner: alice     group: alice     mode: 0600<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u0434\u043e\u0441\u0442\u0438\u0436\u0435\u043d\u0438\u044f \u0442\u043e\u0433\u043e \u0436\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u043c\u044b \u043c\u043e\u0433\u043b\u0438 \u0431\u044b, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u0435\u0440\u0438\u044e \u043a\u043e\u043c\u0430\u043d\u0434 \u0438\u043b\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0432 bash, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <code>scp<\/code>, <code>chown<\/code> \u0438 chmod. \u0421 Ansible \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u043e\u0441\u0440\u0435\u0434\u043e\u0442\u043e\u0447\u0438\u0442\u044c\u0441\u044f \u043d\u0430 \u0436\u0435\u043b\u0430\u0435\u043c\u043e\u0439 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438, \u043d\u0435 \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0437\u0430\u0431\u043e\u0442\u044f\u0441\u044c \u043e \u0434\u0435\u0442\u0430\u043b\u044f\u0445.<\/p>\n<p>  <\/p>\n<p>\u0421 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u044d\u0442\u043e \u0442\u0430\u043a\u0436\u0435 \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u0438\u043d\u043e\u0433\u0434\u0430 \u043a\u0430\u0436\u0443\u0442\u0441\u044f \u0441\u0442\u0440\u0430\u043d\u043d\u044b\u043c\u0438 \u0438\u043b\u0438 \u043d\u0435\u043e\u0431\u044b\u0447\u043d\u044b\u043c\u0438 \u2014 \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u043e\u0431\u044b\u0447\u043d\u043e \u0438\u043c\u0435\u044e\u0442 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0438\u043c\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u044b\u043c \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430\u043c \u0432 \u0442\u0435\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445, \u043a\u043e\u0433\u0434\u0430 \u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u043d\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442.<\/p>\n<p>  <\/p>\n<p>\u041e\u0434\u043d\u043e \u043c\u0435\u0441\u0442\u043e, \u0433\u0434\u0435 \u044f \u0437\u0430\u043c\u0435\u0442\u0438\u043b \u044d\u0442\u043e \u0432 Ansible, \u2014 \u044d\u0442\u043e \u043c\u043d\u043e\u0433\u043e\u043a\u0440\u0430\u0442\u043d\u043e\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043e\u0434\u043d\u043e\u0439 \u0438 \u0442\u043e\u0439 \u0436\u0435 TASKS \u0441 \u043d\u0430\u0431\u043e\u0440\u043e\u043c \u0440\u0430\u0437\u043d\u044b\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432. \u0412 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438, \u044f \u043d\u0430\u0448\u0435\u043b <a href=\"http:\/\/docs.ansible.com\/ansible\/2.4\/playbooks_loops.html\" rel=\"nofollow\">\u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u0446\u0438\u043a\u043b\u043e\u0432 Ansible<\/a> \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0441\u0442\u0440\u0430\u043d\u043d\u044b\u043c\u0438, \u043d\u0435 \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0438\u0445 \u0448\u0435\u0441\u0442\u043d\u0430\u0434\u0446\u0430\u0442\u044c \u2014 \u043f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 PHP, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u043c\u0435\u0435\u0442 <a href=\"http:\/\/php.net\/manual\/en\/language.control-structures.php\" rel=\"nofollow\">\u0447\u0435\u0442\u044b\u0440\u0435 \u0432\u0438\u0434\u0430 \u0446\u0438\u043a\u043b\u043e\u0432<\/a>.<\/p>\n<p>  <\/p>\n<p>\u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0435\u0441\u0442\u044c \u043f\u0440\u0438\u0447\u0438\u043d\u0430, \u0435\u0441\u043b\u0438 \u0432\u0430\u0441 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0435 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e Ansible. \u041d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 Loops \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0443\u043a\u0430\u0437\u0430\u043d\u043e, \u0447\u0442\u043e \u00abloops \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0441\u043e\u0431\u043e\u0439 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u044e \u0432\u0435\u0449\u0435\u0439 \u0441 _ + lookup(), \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043b\u044e\u0431\u043e\u0439 \u043f\u043b\u0430\u0433\u0438\u043d \u043f\u043e\u0438\u0441\u043a\u0430 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430 \u0434\u043b\u044f \u0446\u0438\u043a\u043b\u0430\u00bb. <a href=\"http:\/\/docs.ansible.com\/ansible\/2.4\/playbooks_lookups.html\" rel=\"nofollow\">\u041f\u043e\u0438\u0441\u043a (Lookups) \u2014 \u044d\u0442\u043e \u0442\u0438\u043f \u043f\u043b\u0430\u0433\u0438\u043d\u0430 Ansible<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u00ab\u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0434\u0430\u043d\u043d\u044b\u043c \u0432 Ansible \u0438\u0437 \u0432\u043d\u0435\u0448\u043d\u0438\u0445 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u0432\u00bb, \u0438 \u0435\u0441\u043b\u0438 \u0432\u044b \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u0435 <a href=\"http:\/\/docs.ansible.com\/ansible\/2.4\/playbooks_loops.html\" rel=\"nofollow\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e Loops<\/a> \u0438 <a href=\"https:\/\/github.com\/ansible\/ansible\/tree\/devel\/lib\/ansible\/plugins\/lookup\" rel=\"nofollow\">\u043a\u0430\u0442\u0430\u043b\u043e\u0433 \u043f\u043b\u0430\u0433\u0438\u043d\u043e\u0432 Ansible \u043d\u0430 Github<\/a>, \u0432\u044b \u0443\u0432\u0438\u0434\u0438\u0442\u0435 \u043c\u043d\u043e\u0433\u0438\u0435 \u0438\u0437 \u043d\u0438\u0445 \u0441 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u043c\u0438 \u0438\u043c\u0435\u043d\u0430\u043c\u0438.<\/p>\n<p>  <\/p>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 Ansible \u043f\u043e\u0438\u0441\u043a\u043e\u0432\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u043a\u0430\u043a \u00ab\u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u043d\u0430\u044f \u0442\u0435\u043c\u0430\u00bb, \u0438 \u043d\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0443\u0433\u043b\u0443\u0431\u043b\u044f\u0442\u044c\u0441\u044f \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u0443\u0447\u0438\u0442\u044c\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0430\u043c\u0438 \u0446\u0438\u043a\u043b\u044b. \u0412 \u043e\u0441\u0442\u0430\u0432\u0448\u0435\u0439\u0441\u044f \u0447\u0430\u0441\u0442\u0438 \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u0441\u0442\u0430 \u043e\u043f\u0438\u0441\u0430\u043d\u044b \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0447\u0430\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0445 \u0446\u0438\u043a\u043b\u043e\u0432 Ansible, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u0435\u0449\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f \u0443\u0437\u043d\u0430\u043b \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0438\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c.<\/p>\n<p>  <\/p>\n<h4 id=\"cikly-ansible\">\u0426\u0418\u041a\u041b\u042b ANSIBLE<\/h4>\n<p>  <\/p>\n<p>TASKS, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u0435 \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445, \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0431\u043e\u043b\u0435\u0435 \u0438\u043b\u0438 \u043c\u0435\u043d\u0435\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u043c\u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u043c\u0438 \u0441 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0438 \u0438\u0445 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u043e\u0432, \u043d\u043e \u043e\u043d\u0438 \u0442\u0435\u0441\u043d\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u044b \u0441 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0437\u0430\u0434\u0430\u0447\u0430\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u043f\u043e\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u0441\u0435\u0440\u0432\u0435\u0440\u0430\u0445 (\u043d\u043e \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435: \u0434\u0430\u043d\u043d\u044b\u0435, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c, \u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u0430\u0434\u0430\u0447, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0438\u0436\u0435\u043d\u0438\u044f \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0439 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438, \u044f\u0432\u043d\u043e \u043d\u0435\u0440\u0435\u0430\u043b\u044c\u043d\u043e!)<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440\u044b \u043e\u0441\u043d\u043e\u0432\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0434\u0440\u0443\u0433 \u043d\u0430 \u0434\u0440\u0443\u0433\u0435 \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u0437\u0430\u0434\u0430\u0447 \u043d\u0430 \u0433\u0438\u043f\u043e\u0442\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u0441\u0435\u0440\u0432\u0435\u0440\u0435:<\/p>\n<p>  <\/p>\n<ol>\n<li>\n<p>\u0423\u0431\u0435\u0434\u0438\u0442\u0435\u0441\u044c, \u0447\u0442\u043e \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u0447\u0435\u0442\u044b\u0440\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f: <code>alice<\/code>, <code>bob<\/code>, <code>carol<\/code> \u0438 <code>dan<\/code>.<\/p>\n<p>  <\/li>\n<li>\n<p>\u0423\u0431\u0435\u0434\u0438\u0442\u0435\u0441\u044c, \u0447\u0442\u043e \u0434\u043e\u043c\u0430\u0448\u043d\u0438\u0439 \u043a\u0430\u0442\u0430\u043b\u043e\u0433 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0434\u0432\u0430 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0430: <code>.ssh\/<\/code> \u0438 <code>loops<\/code>.<\/p>\n<p>  <\/li>\n<li>\n<p>\u0423\u0431\u0435\u0434\u0438\u0442\u0435\u0441\u044c, \u0447\u0442\u043e \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u0447\u0435\u0442\u044b\u0440\u0435\u0445 \u0434\u043e\u043c\u0430\u0448\u043d\u0438\u0445 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u043e\u0432 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0443 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043e\u043c\u0430\u0448\u043d\u0438\u0439 \u043a\u0430\u0442\u0430\u043b\u043e\u0433 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f alice \u043f\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0438 \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a:<\/p>\n<p>  <\/li>\n<\/ol>\n<p>  <\/p>\n<pre><code class=\"plaintext\">\/home\/alice\/ \u251c\u2500\u2500 .ssh\/ \u251c\u2500\u2500 bob\/ \u251c\u2500\u2500 carol\/ \u251c\u2500\u2500 dan\/ \u2514\u2500\u2500 loops\/<\/code><\/pre>\n<p>  <\/p>\n<h4 id=\"cikl-1-sozdanie-polzovateley-with_itemshttpdocsansiblecomansible24playbooks_loopshtmlstandard-loops\">\u0426\u0418\u041a\u041b 1. \u0421\u041e\u0417\u0414\u0410\u041d\u0418\u0415 \u041f\u041e\u041b\u042c\u0417\u041e\u0412\u0410\u0422\u0415\u041b\u0415\u0419 <a href=\"http:\/\/docs.ansible.com\/ansible\/2.4\/playbooks_loops.html#standard-loops\" rel=\"nofollow\">WITH_ITEMS<\/a><\/h4>\n<p>  <\/p>\n<p>\u0422\u0438\u043f\u0438\u0447\u043d\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u0432 Ansible \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a, \u043a\u043e\u0433\u0434\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0443\u0434\u0430\u043b\u044f\u0435\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f <code>chuck<\/code> \u0438\u0437 \u0441\u0438\u0441\u0442\u0435\u043c\u044b, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0437\u0430\u0434\u0430\u0447\u0430:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">- name: Remove user \u2018Chuck\u2019 from the system.   user:     name: chuck     state: absent     remove: yes<\/code><\/pre>\n<p>  <\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u043f\u043e\u0432\u0442\u043e\u0440\u0438\u0442\u044c \u044d\u0442\u0443 \u0437\u0430\u0434\u0430\u0447\u0443 \u0434\u043b\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u2014 \u0441\u043a\u0430\u0436\u0435\u043c, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 <code>Chuck<\/code> \u0438 <code>Craig<\/code> \u2014 \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0432 \u0437\u0430\u0434\u0430\u0447\u0443 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <code>with_items<\/code>. with_items \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043b\u0438\u0431\u043e \u0441\u043f\u0438\u0441\u043e\u043a (\u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0439 \u0437\u0434\u0435\u0441\u044c), \u043b\u0438\u0431\u043e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e (\u043a\u0430\u043a \u0432 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445):<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">- name: Remove users \u2018Chuck\u2019 and \u2018Craig\u2019 from the system.   user:     name: &quot;{{ item }}&quot;     state: absent     remove: yes   with_items:     - chuck     - craig<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044f\u0441\u044c \u043a \u043d\u0430\u0448\u0435\u043c\u0443 \u043f\u0435\u0440\u0432\u043e\u043c\u0443 \u043f\u0440\u0438\u043c\u0435\u0440\u0443 \u0446\u0438\u043a\u043b\u0430, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c with_items \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u0435\u0440\u0432\u044b\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043f\u0438\u0441\u043a\u0435, <code>alice<\/code> \u0438 <code>bob<\/code>:<\/p>\n<p>  <\/p>\n<h5 id=\"peremennye\">\u041f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435<\/h5>\n<p>  <\/p>\n<pre><code class=\"plaintext\">users_with_items:   - name: &quot;alice&quot;     personal_directories:       - &quot;bob&quot;       - &quot;carol&quot;       - &quot;dan&quot;   - name: &quot;bob&quot;     personal_directories:       - &quot;alice&quot;       - &quot;carol&quot;       - &quot;dan&quot;<\/code><\/pre>\n<p>  <\/p>\n<h5 id=\"tasks\">TASKS<\/h5>\n<p>  <\/p>\n<pre><code class=\"plaintext\">- name: &quot;Loop 1: create users using 'with_items'.&quot;   user:     name: &quot;{{ item.name }}&quot;   with_items: &quot;{{ users_with_items }}&quot;<\/code><\/pre>\n<p>  <\/p>\n<p>\u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <a href=\"http:\/\/docs.ansible.com\/ansible\/2.4\/user_module.html\" rel=\"nofollow\">\u043c\u043e\u0434\u0443\u043b\u044c Ansible User<\/a> \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0431\u043e\u0440\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0441 \u0438\u043c\u0435\u043d\u0435\u043c users_with_items. \u042d\u0442\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0438\u043c\u0435\u043d\u0430 \u0438 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0434\u0432\u0443\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u0445, \u043d\u043e \u0437\u0430\u0434\u0430\u0447\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442, \u0447\u0442\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0435, \u043e\u043d\u0430 \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0438, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0435\u0441\u044f \u0432 \u0441\u043f\u0438\u0441\u043a\u0435 personal_directories \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f (\u043e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e personal_directories \u2014 \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0439 \u043a\u043b\u044e\u0447 \u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430).<\/p>\n<p>  <\/p>\n<p>\u042d\u0442\u043e \u043f\u0440\u0438\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u0446\u0438\u043a\u043b\u043e\u0432 Ansible (\u0438 Ansible \u0432 \u0446\u0435\u043b\u043e\u043c): \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 TASKS \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 \u043c\u043e\u0434\u0443\u043b\u0438 \u0441 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043d\u043e\u0439 \u043e\u0431\u043b\u0430\u0441\u0442\u044c\u044e, \u043e\u0431\u044b\u0447\u043d\u043e \u0432 \u0437\u0430\u0434\u0430\u0447\u0435 \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u0432\u0438\u0434\u0430 \u0432\u0435\u0449\u0435\u0439. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043c\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u043c \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e <code>personal_directories<\/code> \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u0438\u0437 \u044d\u0442\u043e\u0439 TASKS (\u0442. \u0435. \u041f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043c\u043e\u0434\u0443\u043b\u044c User, \u0430 \u043d\u0435 \u043c\u043e\u0434\u0443\u043b\u044c File).<\/p>\n<p>  <\/p>\n<p>\u0426\u0438\u043a\u043b <code>with_items<\/code> \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a \u0436\u0435, \u043a\u0430\u043a \u044d\u0442\u043e\u0442 \u0446\u0438\u043a\u043b PHP:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">&lt;?php  foreach ($users_with_items as $user) {   \/\/ Do something with $user... }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041c\u044b \u043f\u0438\u0441\u0430\u043b\u0438 \u0437\u0430\u0434\u0430\u0447\u0443 \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u043e, \u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u0442\u043e\u0433\u043e, \u0447\u0442\u043e:<\/p>\n<p>  <\/p>\n<p>\u2022 \u041c\u044b \u0437\u0430\u043c\u0435\u043d\u0438\u043b\u0438 \u0438\u043c\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 <code>item.name<\/code> \u043d\u0430 \u0438\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<\/p>\n<p>  <\/p>\n<p>\u2022 \u041c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u0441\u0442\u0440\u043e\u043a\u0443 <code>with_items<\/code>, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0449\u0443\u044e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0431\u043e\u0440\u0430.<\/p>\n<p>  <\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0441\u0442\u043e\u0438\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0432\u043d\u0443\u0442\u0440\u0438 \u0446\u0438\u043a\u043b\u0430 Ansible \u0442\u0435\u043a\u0443\u0449\u0430\u044f \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044f \u0432\u0441\u0435\u0433\u0434\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f <code>item<\/code>, \u0438 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043b\u044e\u0431\u043e\u043c\u0443 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u043c\u0443 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0443 \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>item.property<\/code>.<\/p>\n<p>  <\/p>\n<h5 id=\"rezultaty\">\u0420\u0415\u0417\u0423\u041b\u042c\u0422\u0410\u0422\u042b<\/h5>\n<p>  <\/p>\n<pre><code class=\"plaintext\">\/home\/ \u251c\u2500\u2500 alice\/ \u2514\u2500\u2500 bob\/<\/code><\/pre>\n<p>  <\/p>\n<h4 id=\"cikl-2-sozdavayte-katalogi-obschih-polzovateley-ispolzuya-with_nestedhttpdocsansiblecomansible24playbooks_loopshtmlnested-loops\">\u0426\u0418\u041a\u041b 2: \u0421\u041e\u0417\u0414\u0410\u0412\u0410\u0419\u0422\u0415 \u041a\u0410\u0422\u0410\u041b\u041e\u0413\u0418 \u041e\u0411\u0429\u0418\u0425 \u041f\u041e\u041b\u042c\u0417\u041e\u0412\u0410\u0422\u0415\u041b\u0415\u0419, \u0418\u0421\u041f\u041e\u041b\u042c\u0417\u0423\u042f <a href=\"http:\/\/docs.ansible.com\/ansible\/2.4\/playbooks_loops.html#nested-loops\" rel=\"nofollow\">WITH_NESTED<\/a><\/h4>\n<p>  <\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435: \u0414\u043b\u044f \u0446\u0438\u043a\u043b\u0430 2 \u043d\u0443\u0436\u043d\u044b \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0435 \u044e\u0437\u0435\u0440\u044b, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0446\u0438\u043a\u043b\u0430 1. \u0418\u043d\u0430\u0447\u0435 \u0431\u0443\u0434\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0430 <code>chown failed: failed to look up user<\/code><\/p>\n<p>  <\/p>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0434\u0432\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435, <code>users_with_items<\/code> \u0438\u0437 \u0446\u0438\u043a\u043b\u0430 1, \u0438 \u043d\u043e\u0432\u0443\u044e, <code>common_directories<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u0432\u0441\u0435\u0445 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0432 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0435 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f. \u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e (\u0441\u043d\u043e\u0432\u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044f\u0441\u044c \u043a PHP), \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0447\u0442\u043e-\u0442\u043e, \u0447\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">&lt;?php  foreach ($users_with_items as $user) {   foreach ($common_directories as $directory) {     \/\/ Create $directory for $user...   } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 Ansible \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0446\u0438\u043a\u043b <code>with_nested<\/code>. \u0426\u0438\u043a\u043b\u044b <code>with_nested<\/code> \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0442 \u0434\u0432\u0430 \u0441\u043f\u0438\u0441\u043a\u0430, \u0432\u0442\u043e\u0440\u043e\u0439 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0435\u0442\u0441\u044f \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438 \u043f\u0435\u0440\u0432\u043e\u0433\u043e:<\/p>\n<p>  <\/p>\n<h5 id=\"peremennye-1\">\u041f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435<\/h5>\n<p>  <\/p>\n<pre><code class=\"plaintext\">users_with_items:   - name: &quot;alice&quot;     personal_directories:       - &quot;bob&quot;       - &quot;carol&quot;       - &quot;dan&quot;   - name: &quot;bob&quot;     personal_directories:       - &quot;alice&quot;       - &quot;carol&quot;       - &quot;dan&quot;  common_directories:   - &quot;.ssh&quot;   - &quot;loops<\/code><\/pre>\n<p>  <\/p>\n<h5 id=\"tasks-1\">TASKS<\/h5>\n<p>  <\/p>\n<pre><code class=\"plaintext\"># Note that this does not set correct permissions on \/home\/{{ item.x.name }}\/.ssh! - name: &quot;Loop 2: create common users' directories using 'with_nested'.&quot;   file:     dest: &quot;\/home\/{{ item.0.name }}\/{{ item.1 }}&quot;     owner: &quot;{{ item.0.name }}&quot;     group: &quot;{{ item.0.name }}&quot;     state: directory   with_nested:     - &quot;{{ users_with_items }}&quot;     - &quot;{{ common_directories }}&quot;<\/code><\/pre>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u0432 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u0439 \u0432\u044b\u0448\u0435 \u0437\u0430\u0434\u0430\u0447\u0435, \u043a \u0434\u0432\u0443\u043c \u0441\u043f\u0438\u0441\u043a\u0430\u043c \u0432 with_nested \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <code>item.0<\/code> (\u0434\u043b\u044f <code>users_with_items<\/code>) \u0438 <code>item.1<\/code> (\u0434\u043b\u044f <code>common_directories<\/code>) \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e. \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0430\u043c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u043a\u0430\u0442\u0430\u043b\u043e\u0433 <code>\/home\/alice\/.ssh<\/code> \u043d\u0430 \u0441\u0430\u043c\u043e\u0439 \u043f\u0435\u0440\u0432\u043e\u0439 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438.<\/p>\n<p>  <\/p>\n<h5 id=\"rezultaty-1\">\u0420\u0415\u0417\u0423\u041b\u042c\u0422\u0410\u0422\u042b<\/h5>\n<p>  <\/p>\n<pre><code class=\"plaintext\">\/home\/ \u251c\u2500\u2500 alice\/ \u2502   \u251c\u2500\u2500 .ssh\/ \u2502   \u2514\u2500\u2500 loops\/ \u2514\u2500\u2500 bob\/     \u251c\u2500\u2500 .ssh\/     \u2514\u2500\u2500 loops\/<\/code><\/pre>\n<p>  <\/p>\n<h4 id=\"cikl-3-sozdavayte-lichnye-katalogi-polzovateley-ispolzuya-with_subelementshttpdocsansiblecomansible24playbooks_loopshtmllooping-over-subelements\">\u0426\u0418\u041a\u041b 3: \u0421\u041e\u0417\u0414\u0410\u0412\u0410\u0419\u0422\u0415 \u041b\u0418\u0427\u041d\u042b\u0415 \u041a\u0410\u0422\u0410\u041b\u041e\u0413\u0418 \u041f\u041e\u041b\u042c\u0417\u041e\u0412\u0410\u0422\u0415\u041b\u0415\u0419, \u0418\u0421\u041f\u041e\u041b\u042c\u0417\u0423\u042f <a href=\"http:\/\/docs.ansible.com\/ansible\/2.4\/playbooks_loops.html#looping-over-subelements\" rel=\"nofollow\">WITH_SUBELEMENTS<\/a><\/h4>\n<p>  <\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435: \u0414\u043b\u044f \u0446\u0438\u043a\u043b\u0430 3 \u043d\u0443\u0436\u043d\u044b \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0435 \u044e\u0437\u0435\u0440\u044b, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0446\u0438\u043a\u043b\u0430 1. \u0418\u043d\u0430\u0447\u0435 \u0431\u0443\u0434\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0430 <code>chown failed: failed to look up user<\/code><\/p>\n<p>  <\/p>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0434\u0440\u0443\u0433\u043e\u0439 \u0432\u0438\u0434 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0433\u043e \u0446\u0438\u043a\u043b\u0430 <code>with_subelements<\/code> \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u043e\u0432, \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0445 \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 <code>users_with_items<\/code> \u0438\u0437 \u0446\u0438\u043a\u043b\u0430 1. \u0412 PHP \u0446\u0438\u043a\u043b \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">&lt;?php  foreach ($users_with_items as $user) {   foreach ($user['personal_directories'] as $directory) {     \/\/ Create $directory for $user...   } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u043c\u044b \u043f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0435\u043c \u043c\u0430\u0441\u0441\u0438\u0432 <code>$users_with_items<\/code> \u0438 <code>$user['personal_directories']<\/code> \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<\/p>\n<p>  <\/p>\n<h5 id=\"peremennye-2\">\u041f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435<\/h5>\n<p>  <\/p>\n<pre><code class=\"plaintext\">users_with_items:   - name: &quot;alice&quot;     personal_directories:       - &quot;bob&quot;       - &quot;carol&quot;       - &quot;dan&quot;   - name: &quot;bob&quot;     personal_directories:       - &quot;alice&quot;       - &quot;carol&quot;       - &quot;dan&quot;<\/code><\/pre>\n<p>  <\/p>\n<h5 id=\"tasks-2\">TASKS<\/h5>\n<p>  <\/p>\n<pre><code class=\"plaintext\">- name: &quot;Loop 3: create personal users' directories using 'with_subelements'.&quot;   file:     dest: &quot;\/home\/{{ item.0.name }}\/{{ item.1 }}&quot;     owner: &quot;{{ item.0.name }}&quot;     group: &quot;{{ item.0.name }}&quot;     state: directory   with_subelements:     - &quot;{{ users_with_items }}&quot;     - personal_directories<\/code><\/pre>\n<p>  <\/p>\n<p>\u0426\u0438\u043a\u043b <code>with_subelements<\/code> \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u043e\u0447\u0442\u0438 \u0442\u0430\u043a \u0436\u0435, \u043a\u0430\u043a <code>with_nested<\/code>, \u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0432\u043c\u0435\u0441\u0442\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u043e\u043d \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0438 \u043a\u043b\u044e\u0447 \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u0441\u043f\u0438\u0441\u043a\u0430, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0435\u0433\u043e\u0441\u044f \u0432 \u044d\u0442\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u2014 \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 personal_directories. \u041a\u0430\u043a \u0438 \u0432 \u0446\u0438\u043a\u043b\u0435 2, \u043f\u0435\u0440\u0432\u0430\u044f \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044f \u044d\u0442\u043e\u0433\u043e \u0446\u0438\u043a\u043b\u0430 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 (\u0438\u043b\u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u0435) <code>\/home\/alice\/bob<\/code>.<\/p>\n<p>  <\/p>\n<h5 id=\"rezultaty-2\">\u0420\u0415\u0417\u0423\u041b\u042c\u0422\u0410\u0422\u042b<\/h5>\n<p>  <\/p>\n<pre><code class=\"plaintext\">\/home\/ \u251c\u2500\u2500 alice\/ \u2502   \u251c\u2500\u2500 .ssh\/ \u2502   \u251c\u2500\u2500 bob\/ \u2502   \u251c\u2500\u2500 carol\/ \u2502   \u251c\u2500\u2500 dan\/ \u2502   \u2514\u2500\u2500 loops\/ \u2514\u2500\u2500 bob\/     \u251c\u2500\u2500 .ssh\/     \u251c\u2500\u2500 alice\/     \u251c\u2500\u2500 carol\/     \u251c\u2500\u2500 dan\/     \u2514\u2500\u2500 loops\/<\/code><\/pre>\n<p>  <\/p>\n<h4 id=\"cikl-4-sozdavayte-polzovateley-s-ispolzovaniem-with_dicthttpdocsansiblecomansible24playbooks_loopshtmllooping-over-hashes\">\u0426\u0418\u041a\u041b 4: \u0421\u041e\u0417\u0414\u0410\u0412\u0410\u0419\u0422\u0415 \u041f\u041e\u041b\u042c\u0417\u041e\u0412\u0410\u0422\u0415\u041b\u0415\u0419 \u0421 \u0418\u0421\u041f\u041e\u041b\u042c\u0417\u041e\u0412\u0410\u041d\u0418\u0415\u041c <a href=\"http:\/\/docs.ansible.com\/ansible\/2.4\/playbooks_loops.html#looping-over-hashes\" rel=\"nofollow\">WITH_DICT<\/a><\/h4>\n<p>  <\/p>\n<p>\u0426\u0438\u043a\u043b 3 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u043b \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0443 \u0434\u043e\u043c\u0430\u0448\u043d\u0438\u0445 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u043e\u0432, \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0430\u0449\u0438\u0445 <code>alice<\/code> \u0438 <code>bob<\/code>, \u043d\u043e \u0435\u0441\u0442\u044c \u0435\u0449\u0435 \u0434\u0432\u0430 \u0432\u044b\u0434\u0430\u044e\u0449\u0438\u0445\u0441\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c, <code>carol<\/code> \u0438 <code>dan<\/code>. \u0412 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u044d\u0442\u0438\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0441\u043e\u0437\u0434\u0430\u044e\u0442\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043d\u043e\u0432\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 <code>users_with_dict<\/code> \u0438 \u0446\u0438\u043a\u043b\u0430 Ansible <code>with_dict<\/code>.<\/p>\n<p>  <\/p>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0437\u0434\u0435\u0441\u044c \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0437\u043d\u0430\u0447\u0438\u043c\u044b\u0435 \u043a\u043b\u044e\u0447\u0438 (<code>dict<\/code> \u0438\u043b\u0438 <code>dictionary<\/code> \u2014 \u044d\u0442\u043e \u0438\u043c\u044f Python \u0434\u043b\u044f \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u043c\u0430\u0441\u0441\u0438\u0432\u0430); <code>with_dict<\/code> \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043b\u0443\u0447\u0448\u0438\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u043c, \u0435\u0441\u043b\u0438 \u0432\u044b \u0432\u044b\u043d\u0443\u0436\u0434\u0435\u043d\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0441 \u0442\u0430\u043a\u0438\u043c \u0442\u0438\u043f\u043e\u043c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b. \u0426\u0438\u043a\u043b, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0437\u0434\u0435\u0441\u044c \u0432 Ansible, \u0432 PHP \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a\u043e\u0439:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">&lt;?php  foreach ($users_with_dict as $user =&gt; $properties) {   \/\/ Create a user named $user... }<\/code><\/pre>\n<p>  <\/p>\n<h5 id=\"peremennye-3\">\u041f\u0415\u0420\u0415\u041c\u0415\u041d\u041d\u042b\u0415<\/h5>\n<p>  <\/p>\n<pre><code class=\"plaintext\">users_with_dict:   carol:     common_directories: &quot;{{ common_directories }}&quot;   dan:     common_directories: &quot;{{ common_directories }}&quot;<\/code><\/pre>\n<p>  <\/p>\n<h5 id=\"tasks-3\">TASKS<\/h5>\n<p>  <\/p>\n<pre><code class=\"plaintext\">- name: &quot;Loop 4: create users using 'with_dict'.&quot;   user:     name: &quot;{{ item.key }}&quot;   with_dict: &quot;{{ users_with_dict }}&quot;<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0438\u043f \u0446\u0438\u043a\u043b\u0430 <code>with_dict<\/code> \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043a\u0440\u0430\u0442\u043e\u043a \u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043a\u043b\u044e\u0447\u0430\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c. \u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u0443 \u043d\u0435\u0433\u043e \u0435\u0441\u0442\u044c \u043e\u0434\u0438\u043d \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u043a, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u043e, \u0447\u0442\u043e \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0431\u0440\u0430\u0442\u044c \u043f\u043e\u0434\u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b <code>dict<\/code> \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>with_dict<\/code> (\u0442\u0430\u043a, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>with_dict<\/code> \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043e\u0431\u0449\u0438\u0445 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u043e\u0432 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f).<\/p>\n<p>  <\/p>\n<h5 id=\"rezultaty-3\">\u0420\u0415\u0417\u0423\u041b\u042c\u0422\u0410\u0422\u042b<\/h5>\n<p>  <\/p>\n<pre><code class=\"plaintext\">\/home\/ \u251c\u2500\u2500 alice\/ \u2502   \u251c\u2500\u2500 .ssh\/ \u2502   \u251c\u2500\u2500 bob\/ \u2502   \u251c\u2500\u2500 carol\/ \u2502   \u251c\u2500\u2500 dan\/ \u2502   \u2514\u2500\u2500 loops\/ \u251c\u2500\u2500 bob\/ \u2502   \u251c\u2500\u2500 .ssh\/ \u2502   \u251c\u2500\u2500 alice\/ \u2502   \u251c\u2500\u2500 carol\/ \u2502   \u251c\u2500\u2500 dan\/ \u2502   \u2514\u2500\u2500 loops\/ \u251c\u2500\u2500 carol\/ \u2514\u2500\u2500 dan\/<\/code><\/pre>\n<p>  <\/p>\n<h4 id=\"cikl-5-sozdavayte-lichnye-katalogi-esli-oni-ne-suschestvuyut\">\u0426\u0418\u041a\u041b 5: \u0421\u041e\u0417\u0414\u0410\u0412\u0410\u0419\u0422\u0415 \u041b\u0418\u0427\u041d\u042b\u0415 \u041a\u0410\u0422\u0410\u041b\u041e\u0413\u0418, \u0415\u0421\u041b\u0418 \u041e\u041d\u0418 \u041d\u0415 \u0421\u0423\u0429\u0415\u0421\u0422\u0412\u0423\u042e\u0422<\/h4>\n<p>  <\/p>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u043c \u043b\u0435\u0433\u043a\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>users_with_dict<\/code>, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b Ansible, \u0447\u0442\u043e\u0431\u044b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u043f\u043e-\u0434\u0440\u0443\u0433\u043e\u043c\u0443. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 <code>alice<\/code>, <code>bob<\/code>, <code>carol<\/code> \u0438 <code>dan<\/code>, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0446\u0438\u043a\u043b <code>with_nested<\/code> \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u044b\u043c \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0430 <code>\/home\/<\/code>. \u0412 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u043e\u0432\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u043d\u0435 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u0441 \u0446\u0438\u043a\u043b\u0430\u043c\u0438, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c, \u043a\u0430\u043a \u0446\u0438\u043a\u043b\u044b \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0438\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u0432 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043b\u043e\u0436\u043d\u044b\u0435 TASKS:<\/p>\n<p>  <\/p>\n<p>\u2022 \u0420\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 Ansible<\/p>\n<p>  <\/p>\n<p>\u2022 Ansible \u0443\u0441\u043b\u043e\u0432\u043d\u044b\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f<\/p>\n<p>  <\/p>\n<p>\u2022 Jinja2 (\u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435)<\/p>\n<p>  <\/p>\n<p>\u2022 Jinja2 (\u0444\u0438\u043b\u044c\u0442\u0440\u044b)<\/p>\n<p>  <\/p>\n<h5 id=\"peremennye-4\">\u041f\u0415\u0420\u0415\u041c\u0415\u041d\u041d\u042b\u0415<\/h5>\n<p>  <\/p>\n<pre><code class=\"plaintext\">common_directories:   - &quot;.ssh&quot;   - &quot;loops&quot;<\/code><\/pre>\n<p>  <\/p>\n<h5 id=\"tasks-4\">TASKS<\/h5>\n<p>  <\/p>\n<pre><code class=\"plaintext\">- name: &quot;Get list of extant users.&quot;   shell: &quot;find * -type d -prune | sort&quot;   args:     chdir: &quot;\/home&quot;   register: &quot;home_directories&quot;   changed_when: false  - name: &quot;Loop 5: create personal user directories if they don't exist.&quot;   file:     dest: &quot;\/home\/{{ item.0 }}\/{{ item.1 }}&quot;     owner: &quot;{{ item.0 }}&quot;     group: &quot;{{ item.0 }}&quot;     state: directory   with_nested:     - &quot;{{ home_directories.stdout_lines }}&quot;     - &quot;{{ home_directories.stdout_lines | union(common_directories) }}&quot;   when: &quot;'{{ item.0 }}' != '{{ item.1 }}'&quot;<\/code><\/pre>\n<p>  <\/p>\n<p>\u0417\u0434\u0435\u0441\u044c \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0434\u0432\u0435 TASKS: \u043e\u0434\u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043c\u043e\u0434\u0443\u043b\u044c <code>shell<\/code> \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u044b <code>find<\/code> \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0435, \u0430 \u0434\u0440\u0443\u0433\u0430\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 file \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u043e\u0432.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u0432 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0435 <code>\/home<\/code> \u043a\u043e\u043c\u0430\u043d\u0434\u0430 <code>find \\ -type d -prune | sort<\/code> (\u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043c\u043e\u0434\u0443\u043b\u0435\u043c <code>shell<\/code>) \u0432\u0435\u0440\u043d\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u043c\u0435\u043d\u0430 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u043e\u0432, \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u044b\u0445 \u0432\u043d\u0443\u0442\u0440\u0438 <code>\/home<\/code>, \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u0438\u043c\u0435\u043d\u0430 \u0432\u0441\u0435\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0438 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u0442\u044c.<\/p>\n<p>  <\/p>\n<p>\u0412\u044b\u0432\u043e\u0434 \u044d\u0442\u043e\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442\u0441\u044f \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 <code>home_directories<\/code> \u0441\u0442\u0440\u043e\u043a\u043e\u0439 <code>register: &quot;home_directories&quot;<\/code> \u0432 \u0437\u0430\u0434\u0430\u0447\u0435. \u0412\u0430\u0436\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u044d\u0442\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0437\u0430\u0434\u0430\u0447\u0435, \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">&quot;stdout_lines&quot;: [   &quot;alice&quot;,   &quot;bob&quot;,   &quot;carol&quot;,   &quot;dan&quot;, ],<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u0442\u043e\u0440\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u0432 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 (\u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0446\u0438\u043a\u043b) \u043f\u043e\u0447\u0442\u0438 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0435\u0442 \u0441 \u0446\u0438\u043a\u043b\u043e\u043c <code>with_nested<\/code> \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435, \u043d\u043e \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c \u0434\u0432\u0430 \u043e\u0442\u043b\u0438\u0447\u0438\u044f:<\/p>\n<p>  <\/p>\n<ol>\n<li>\u0412\u0442\u043e\u0440\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u0432 \u0440\u0430\u0437\u0434\u0435\u043b\u0435 <code>with_nested<\/code> \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u0435\u043e\u0431\u044b\u0447\u043d\u043e:<\/li>\n<\/ol>\n<p>  <\/p>\n<pre><code class=\"plaintext\">- &quot;{{ home_directories.stdout_lines | union(common_directories) }}&quot;<\/code><\/pre>\n<p>  <\/p>\n<ol>\n<li>\n<p>\u0415\u0441\u0442\u044c \u0435\u0449\u0435 \u043e\u0434\u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0430, \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0430\u044f\u0441\u044f \u0441 <code>when<\/code> \u0432 \u043a\u043e\u043d\u0446\u0435 TASKS:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">when: &quot;'{{ item.0 }}' != '{{ item.1 }}'&quot;<\/code><\/pre>\n<p>  <\/li>\n<\/ol>\n<p>  <\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0440\u043e\u0439\u0434\u0435\u043c\u0441\u044f \u043f\u043e \u043d\u0438\u043c \u043f\u043e \u043e\u0447\u0435\u0440\u0435\u0434\u0438. \u041d\u0435\u0447\u0435\u0442\u043d\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u043f\u043e\u0434 <code>with_nested<\/code> \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442 \u0444\u0438\u043b\u044c\u0442\u0440 Jinja2 \u043a \u043d\u043e\u0432\u043e\u043c\u0443 \u0441\u043f\u0438\u0441\u043a\u0443 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u043e\u0432 \u0438\u0437 \u043f\u0435\u0440\u0432\u043e\u0439 TASKS \u0432\u044b\u0448\u0435 (\u044d\u0442\u043e \u0447\u0430\u0441\u0442\u044c <code>home_directories.stdout_lines<\/code>). \u0411\u0430\u0437\u043e\u0432\u044b\u0439 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 \u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432 Jinja:<\/p>\n<p>  <\/p>\n<p>\u2022 \u043e\u0431\u044a\u0435\u043a\u0442 \u0434\u043b\u044f \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438 (<code>home_directories.stdout_lines<\/code>)<\/p>\n<p>  <\/p>\n<p>\u2022 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u0444\u0438\u043b\u044c\u0442\u0440 (<code>|<\/code>)<\/p>\n<p>  <\/p>\n<p>\u2022 \u0438\u043c\u044f \u0444\u0438\u043b\u044c\u0442\u0440\u0430 \u043f\u043b\u044e\u0441 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b, \u0435\u0441\u043b\u0438 \u0435\u0441\u0442\u044c (<code>union (common_directories)<\/code>)<\/p>\n<p>  <\/p>\n<p>\u0414\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0444\u0438\u043b\u044c\u0442\u0440 \u0434\u043b\u044f \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f <code>home_directories.stdout_lines<\/code> \u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 <code>common_directories<\/code> \u0438\u0437 \u043d\u0430\u0447\u0430\u043b\u0430 \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0432 \u0435\u0434\u0438\u043d\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">item:   - .ssh   - alice   - bob   - carol   - dan   - loops<\/code><\/pre>\n<p>  <\/p>\n<p>\u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043d\u0430\u0448 \u0446\u0438\u043a\u043b <code>with_nested<\/code> \u0431\u0443\u0434\u0435\u0442 \u043f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0442\u044c \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 <code>home_directories.stdout_lines<\/code> (\u043f\u0435\u0440\u0432\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 <code>with_nested<\/code>) \u0438 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u0447\u0442\u043e \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u043e\u0432 \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0432 \u0434\u043e\u043c\u0430\u0448\u043d\u0435\u043c \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0435 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<\/p>\n<p>  <\/p>\n<p>\u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u044d\u0442\u043e \u0434\u0430\u043b\u043e \u0431\u044b \u043d\u0430\u043c \u043d\u0435\u0432\u0435\u0440\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u2014 \u0435\u0441\u043b\u0438 \u0431\u044b \u043c\u044b \u043f\u043e\u043b\u0430\u0433\u0430\u043b\u0438\u0441\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 \u0446\u0438\u043a\u043b, \u043c\u044b \u0431\u044b \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u043b\u0438, \u0447\u0442\u043e \u0434\u043e\u043c\u0430\u0448\u043d\u0438\u0439 \u043a\u0430\u0442\u0430\u043b\u043e\u0433 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u043a\u0430\u0442\u0430\u043b\u043e\u0433 \u0441 \u0442\u0435\u043c \u0436\u0435 \u0438\u043c\u0435\u043d\u0435\u043c, \u0447\u0442\u043e \u0438 \u0434\u043e\u043c\u0430\u0448\u043d\u0438\u0439 \u043a\u0430\u0442\u0430\u043b\u043e\u0433! (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <code>\/home\/alice\/alice<\/code>, <code>\/home\/bob\/bob<\/code> \u0438 \u0442. \u0434.) \u0412\u043e\u0442 \u0433\u0434\u0435 \u043f\u043e\u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0443\u0441\u043b\u043e\u0432\u043d\u044b\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f Ansible \u2014 <code>when<\/code> \u2014 \u043f\u0440\u0438\u0445\u043e\u0434\u044f\u0442:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">when: &quot;'{{ item.0 }}' != '{{ item.1 }}'&quot;<\/code><\/pre>\n<p>  <\/p>\n<p>\u042d\u0442\u0430 \u0441\u0442\u0440\u043e\u043a\u0430 \u043d\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0437\u0430\u0434\u0430\u0447\u0435 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043a\u0430\u0442\u0430\u043b\u043e\u0433, \u043a\u043e\u0433\u0434\u0430 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0432 <code>home_directories.stdout_lines<\/code> \u0438 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0432 \u043d\u0430\u0448\u0435\u043c \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0438 <code>home_directories.stdout_lines<\/code> \u0438\u0434\u0435\u043d\u0442\u0438\u0447\u043d\u044b (\u043a\u0430\u043a \u0443\u043a\u0430\u0437\u0430\u043d\u043e \u0432 <a href=\"http:\/\/docs.ansible.com\/ansible\/2.4\/playbooks_loops.html\" rel=\"nofollow\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 Ansible Loops<\/a>, \u00ab\u2026 \u043f\u0440\u0438 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0438 <code>when<\/code> \u0441 <code>with_items<\/code> (\u0438\u043b\u0438 \u043b\u044e\u0431\u043e\u0439 \u0434\u0440\u0443\u0433\u043e\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u0446\u0438\u043a\u043b\u0430), \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 when \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u00bb). \u0412 PHP \u0442\u043e, \u0447\u0442\u043e \u043c\u044b \u0434\u0435\u043b\u0430\u0435\u043c \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0435, \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">&lt;?php  $users = ['alice', 'bob', 'carol', 'dan']; $common_directories = ['.ssh', 'loops']; $directories = $user + $common_directories;  foreach ($users as $user) {   foreach ($directories as $directory) {     if ($directory != $user) {       \/\/ Create the directory\u2026     }   } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u042d\u0442\u043e \u0434\u0430\u0435\u0442 \u043d\u0430\u043c \u043d\u0430\u0431\u043e\u0440 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432, \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0445 \u043d\u0438\u0436\u0435, \u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0443 \u043d\u0430\u0448\u0435\u0433\u043e \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430.<\/p>\n<p>  <\/p>\n<h5 id=\"rezultaty-4\">\u0420\u0415\u0417\u0423\u041b\u042c\u0422\u0410\u0422\u042b<\/h5>\n<p>  <\/p>\n<pre><code class=\"plaintext\">\/home\/ \u251c\u2500\u2500 alice\/ \u2502   \u251c\u2500\u2500 .ssh\/ \u2502   \u251c\u2500\u2500 bob\/ \u2502   \u251c\u2500\u2500 carol\/ \u2502   \u251c\u2500\u2500 dan\/ \u2502   \u2514\u2500\u2500 loops\/ \u251c\u2500\u2500 bob\/ \u2502   \u251c\u2500\u2500 .ssh\/ \u2502   \u251c\u2500\u2500 alice\/ \u2502   \u251c\u2500\u2500 carol\/ \u2502   \u251c\u2500\u2500 dan\/ \u2502   \u2514\u2500\u2500 loops\/ \u251c\u2500\u2500 carol\/ \u2502   \u251c\u2500\u2500 .ssh\/ \u2502   \u251c\u2500\u2500 alice\/ \u2502   \u251c\u2500\u2500 bob\/ \u2502   \u251c\u2500\u2500 dan\/ \u2502   \u2514\u2500\u2500 loops\/ \u2514\u2500\u2500 dan\/     \u251c\u2500\u2500 .ssh\/     \u251c\u2500\u2500 alice\/     \u251c\u2500\u2500 bob\/     \u251c\u2500\u2500 carol\/     \u2514\u2500\u2500 loops\/<\/code><\/pre>\n<p>  <\/p>\n<h4 id=\"vyvody\">\u0412\u042b\u0412\u041e\u0414\u042b<\/h4>\n<p>  <\/p>\n<p>\u0426\u0438\u043a\u043b\u044b Ansible \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0441\u0442\u0440\u0430\u043d\u043d\u044b\u0435. \u041e\u043d\u0438 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0442\u0438\u0432\u043d\u044b (\u043a\u0430\u043a \u0438 \u0432\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0435 \u0432 Ansible), \u043d\u043e \u0438 \u0438\u043c\u0435\u044e\u0442 \u043c\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432, \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0437 \u0438\u043c\u0435\u043d \u043a\u043e\u0442\u043e\u0440\u044b\u0445 (<code>with_nested<\/code>? <code>with_subitems<\/code>?) \u0422\u0440\u0443\u0434\u043d\u043e \u0440\u0430\u0441\u043f\u0443\u0442\u0430\u0442\u044c.<\/p>\n<p>  <\/p>\n<p>\u0421 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u043e\u043d\u0438 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043c\u043e\u0449\u043d\u044b, \u0447\u0442\u043e\u0431\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c TASKS, \u0445\u043e\u0442\u044f \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u0441\u0434\u0432\u0438\u0433\u0430 \u0432 \u043c\u044b\u0448\u043b\u0435\u043d\u0438\u0438 (\u0432\u043e \u043c\u043d\u043e\u0433\u043e\u043c \u043f\u043e\u0434\u043e\u0431\u043d\u043e \u044f\u0437\u044b\u043a\u043e\u0432\u044b\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c, \u0442\u0430\u043a\u0438\u043c \u043a\u0430\u043a <code>array_filter<\/code>, <code>array_reduce<\/code>, <code>array_map<\/code> \u0438 \u0434\u0440\u0443\u0433\u0438\u043c \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c, \u043a\u043e\u0433\u0434\u0430 \u0432\u044b \u0432\u043f\u0435\u0440\u0432\u044b\u0435 \u0441\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u0435\u0442\u0435\u0441\u044c \u0441 \u043d\u0438\u043c\u0438). \u041f\u0440\u043e\u0448\u043b\u043e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u0440\u0435\u043c\u044f, \u043f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u044f \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0430\u0447\u0430\u043b \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c, \u0447\u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u0438\u0441\u043e\u0435\u0434\u0438\u043d\u0438\u0442\u044c \u0446\u0438\u043a\u043b \u043a \u0437\u0430\u0434\u0430\u0447\u0435 \u2014 \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u0438\u043d\u043e\u0433\u0434\u0430 \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u043f\u043e\u0432\u0442\u043e\u0440\u0435\u043d\u0438\u0435 \u043e\u0434\u043d\u0438\u0445 \u0438 \u0442\u0435\u0445 \u0436\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0431\u043e\u043b\u0435\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u0430 \u2014 \u0432\u043c\u0435\u0441\u0442\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043e\u0434\u043d\u043e\u0439 \u0438\u043b\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0437\u0430\u0434\u0430\u0447 \u0432\u043d\u0443\u0442\u0440\u0438 \u0446\u0438\u043a\u043b\u0430.<\/p>\n<p>  <\/p>\n<p>\u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u044d\u0442\u043e\u0442 \u043f\u043e\u0441\u0442 \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u0432\u0430\u043c \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u0442 \u043c\u043e\u0435\u0433\u043e \u043f\u0435\u0440\u0432\u043e\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0437\u0430\u0442\u0440\u0443\u0434\u043d\u0435\u043d\u0438\u044f. \u0421 \u044d\u0442\u043e\u0439 \u0446\u0435\u043b\u044c\u044e \u044f \u0441\u043e\u0431\u0440\u0430\u043b \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u0443\u044e \u043c\u0430\u0448\u0438\u043d\u0443 <a href=\"https:\/\/github.com\/ctorgalson\/ansible-loops\" rel=\"nofollow\">Vagrant<\/a> (Vagrant \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 Ansible \u0434\u043b\u044f \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0438) \u0438 Ansible playbook, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0438 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u044d\u0442\u0438\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432). \u041f\u0440\u043e\u0441\u0442\u043e \u0441\u043b\u0435\u0434\u0443\u0439\u0442\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f\u043c \u0432 README, \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0438\u0437 \u044d\u0442\u043e\u0433\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0438\u043b\u0438 \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u0438 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435. \u0415\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u043a\u0430\u043a\u0438\u0435-\u043b\u0438\u0431\u043e \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u0438\u043b\u0438 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438, \u043d\u0430\u043f\u0438\u0448\u0438\u0442\u0435 \u043d\u0430\u043c \u0432 Twitter \u043f\u043e \u0430\u0434\u0440\u0435\u0441\u0443 @chromaticHQ!<\/p>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/526526\/\"> https:\/\/habr.com\/ru\/post\/526526\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\">\n<p>\u0412 \u043f\u043e\u0441\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 Ansible \u043c\u043e\u0434\u0443\u043b\u0438 loop: with_items, with_nested, with_subelements, with_dict.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-312576","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/312576","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=312576"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/312576\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=312576"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=312576"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=312576"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}