{"id":379614,"date":"2024-06-25T03:11:33","date_gmt":"2024-06-25T03:11:33","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=379614"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=379614","title":{"rendered":"<span>\u041f\u043b\u0435\u0439\u0431\u0443\u043a\u0438 \u0432 Ansible<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/64f\/d43\/e85\/64fd43e85a1bbb639cc0667da658a9dc.png\" width=\"780\" height=\"439\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/64f\/d43\/e85\/64fd43e85a1bbb639cc0667da658a9dc.png\"\/><\/figure>\n<p><em>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440!<\/em><\/p>\n<p><a href=\"https:\/\/www.ansible.com\/\">Ansible <\/a>\u2014 \u044d\u0442\u043e \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u0434\u043b\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0430\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0431\u043b\u0435\u0433\u0447\u0430\u0435\u0442 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f\u043c\u0438, \u0440\u0430\u0437\u0432\u0435\u0440\u0442\u044b\u0432\u0430\u043d\u0438\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u0438 \u043e\u0440\u043a\u0435\u0441\u0442\u0440\u0430\u0446\u0438\u044e \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447. \u0415\u0433\u043e \u0433\u043b\u0430\u0432\u043d\u0430\u044f \u0441\u0438\u043b\u0430 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u0432\u044b\u0441\u043e\u043a\u043e\u0439 \u0447\u0438\u0442\u0430\u0435\u043c\u043e\u0441\u0442\u0438 \u043f\u043b\u0435\u0439\u0431\u0443\u043a\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0441\u043e\u0431\u043e\u0439 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0438 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0430\u0446\u0438\u0438, \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 YAML.<\/p>\n<p>\u041f\u043b\u0435\u0439\u0431\u0443\u043a\u0438 \u0432 Ansible \u2014 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 Ansible. \u041f\u043b\u0435\u0439\u0431\u0443\u043a \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u043b\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 <em>\u0438\u0433\u0440<\/em> (plays), \u043a\u0430\u0436\u0434\u0430\u044f \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445, \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 <em>\u0437\u0430\u0434\u0430\u0447\u0438<\/em> (tasks). \u042d\u0442\u0438 \u0437\u0430\u0434\u0430\u0447\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u0447\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u043b\u043e\u0436\u043d\u044b\u0435, \u043d\u043e \u043b\u0435\u0433\u043a\u043e \u0447\u0438\u0442\u0430\u0435\u043c\u044b\u0435 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0438 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0430\u0446\u0438\u0438.<\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043f\u043b\u0435\u0439\u0431\u0443\u043a\u0430\u043c\u0438 \u0432 Ansible.<\/p>\n<h3>\u041d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043f\u043b\u0435\u0439\u0431\u0443\u043a\u043e\u0432  <\/h3>\n<p>\u041c\u044b \u0443\u0436\u0435 \u0437\u043d\u0430\u0435\u043c, \u0447\u0442\u043e \u0434\u043b\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u043f\u043b\u0435\u0439\u0431\u0443\u043a\u043e\u0432 \u0432 Ansible \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 Yaml. \u041e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441\u0430 YAML:<\/p>\n<ol>\n<li>\n<p><strong>\u041e\u0442\u0441\u0442\u0443\u043f\u044b:<\/strong> YAML \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043e\u0442\u0441\u0442\u0443\u043f\u044b \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0443\u0440\u043e\u0432\u043d\u044f \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438. \u041e\u0431\u044b\u0447\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u043f\u0440\u043e\u0431\u0435\u043b\u044b, \u0430 \u043d\u0435 \u0442\u0430\u0431\u0443\u043b\u044f\u0446\u0438\u0438.<\/p>\n<\/li>\n<li>\n<p><strong>\u041a\u043b\u044e\u0447-\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435:<\/strong> \u043a\u0430\u0436\u0434\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043f\u0430\u0440\u0443 \u043a\u043b\u044e\u0447-\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 \u0434\u0432\u043e\u0435\u0442\u043e\u0447\u0438\u0435\u043c.<\/p>\n<\/li>\n<li>\n<p><strong>\u0421\u043f\u0438\u0441\u043a\u0438:<\/strong> \u0441\u043f\u0438\u0441\u043a\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u044e\u0442\u0441\u044f \u0434\u0435\u0444\u0438\u0441\u043e\u043c (-).<\/p>\n<\/li>\n<\/ol>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e YAML-\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430:<\/p>\n<pre><code class=\"yaml\">name: Ivan age: 30 address:   street: 123 Main St   city: Anytown   state: CA phone_numbers:   - type: home     number: 123-456-7890   - type: work     number: 987-654-3210<\/code><\/pre>\n<p>\u041f\u043b\u0435\u0439\u0431\u0443\u043a\u0438 Ansible \u0441\u043e\u0441\u0442\u043e\u044f\u0442 \u0438\u0437 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432:<\/p>\n<ol>\n<li>\n<p><strong>Header:<\/strong> \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u043e\u0431\u0449\u0438\u0435 \u0441\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u043e \u043f\u043b\u0435\u0439\u0431\u0443\u043a\u0435, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0438 \u0446\u0435\u043b\u0435\u0432\u044b\u0435 \u0445\u043e\u0441\u0442\u044b.<\/p>\n<\/li>\n<li>\n<p><strong>Variables:<\/strong> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u044b \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e \u0432 \u043f\u043b\u0435\u0439\u0431\u0443\u043a\u0435.<\/p>\n<\/li>\n<li>\n<p><strong>Tasks:<\/strong> \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u044b \u043d\u0430 \u0445\u043e\u0441\u0442\u0430\u0445.<\/p>\n<\/li>\n<li>\n<p><strong>Handlers:<\/strong> \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u043f\u0440\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u044b, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a \u0441\u043b\u0443\u0436\u0431\u044b \u043f\u043e\u0441\u043b\u0435 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438.<\/p>\n<\/li>\n<li>\n<p><strong>Conditionals:<\/strong> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u0439.<\/p>\n<\/li>\n<\/ol>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u043f\u043b\u0435\u0439\u0431\u0443\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u0438 \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u0442 \u0432\u0435\u0431-\u0441\u0435\u0440\u0432\u0435\u0440 Apache:<\/p>\n<pre><code class=\"yaml\">--- - name: \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 Apache   hosts: webservers   become: yes   vars:     http_port: 80     max_clients: 200   tasks:     - name: \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 Apache       apt:         name: apache2         state: present      - name: \u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 Apache       template:         src: templates\/apache2.conf.j2         dest: \/etc\/apache2\/apache2.conf       notify:         - \u041f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a Apache      - name: \u041e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 Apache       service:         name: apache2         state: started         enabled: yes    handlers:     - name: \u041f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a Apache       service:         name: apache2         state: restarted<\/code><\/pre>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043f\u043b\u0435\u0439\u0431\u0443\u043a\u0435:<\/p>\n<ul>\n<li>\n<p><code>hosts<\/code> \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0446\u0435\u043b\u0435\u0432\u044b\u0435 \u0445\u043e\u0441\u0442\u044b.<\/p>\n<\/li>\n<li>\n<p><code>become: yes<\/code> \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u0447\u0442\u043e \u0437\u0430\u0434\u0430\u0447\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f \u0441 \u043f\u0440\u0438\u0432\u0438\u043b\u0435\u0433\u0438\u044f\u043c\u0438 \u0441\u0443\u043f\u0435\u0440\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<\/p>\n<\/li>\n<li>\n<p><code>vars<\/code> \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u0432 \u043f\u043b\u0435\u0439\u0431\u0443\u043a\u0435.<\/p>\n<\/li>\n<li>\n<p><code>tasks<\/code> \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0441\u043f\u0438\u0441\u043e\u043a \u0437\u0430\u0434\u0430\u0447, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 Apache, \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u0438 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0441\u043b\u0443\u0436\u0431\u044b.<\/p>\n<\/li>\n<li>\n<p><code>handlers<\/code> \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u043f\u0440\u0438 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a Apache \u043f\u043e\u0441\u043b\u0435 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438.<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u0423\u0441\u043b\u043e\u0432\u043d\u044b\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f<\/strong> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u0439. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 Nginx \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 Debian-\u0431\u0430\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0445:<\/p>\n<pre><code class=\"yaml\">- name: \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 Nginx   apt:     name: nginx     state: present   when: ansible_os_family == \"Debian\"<\/code><\/pre>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u043f\u043b\u0435\u0439\u0431\u0443\u043a\u0430 \u0434\u043b\u044f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 MySQL:<\/p>\n<pre><code class=\"yaml\">--- - name: \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 MySQL   hosts: databases   become: yes   tasks:     - name: \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 MySQL       apt:         name: mysql-server         state: present      - name: \u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 MySQL       template:         src: templates\/my.cnf.j2         dest: \/etc\/mysql\/my.cnf       notify:         - \u041f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a MySQL      - name: \u041e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 MySQL       service:         name: mysql         state: started         enabled: yes    handlers:     - name: \u041f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a MySQL       service:         name: mysql         state: restarted<\/code><\/pre>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u043f\u043b\u0435\u0439\u0431\u0443\u043a\u0430 \u0434\u043b\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 SSH:<\/p>\n<pre><code class=\"yaml\">--- - name: \u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 SSH   hosts: all   become: yes   tasks:     - name: \u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 SSH       lineinfile:         path: \/etc\/ssh\/sshd_config         regexp: '^#PermitRootLogin'         line: 'PermitRootLogin no'       notify:         - \u041f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a SSH    handlers:     - name: \u041f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a SSH       service:         name: sshd         state: restarted<\/code><\/pre>\n<h4>\u041f\u0440\u043e\u0447\u0438\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438<\/h4>\n<p><strong>\u0420\u043e\u043b\u0438<\/strong> \u0438 <strong>\u043c\u043e\u0434\u0443\u043b\u0438<\/strong> \u0432 \u043f\u043e\u043c\u043e\u0433\u0430\u044e\u0442 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438 \u0443\u043f\u0440\u043e\u0449\u0430\u0442\u044c \u043f\u043b\u0435\u0439\u0431\u0443\u043a\u0438.<\/p>\n<p>\u0420\u043e\u043b\u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0440\u0430\u0437\u0431\u0438\u0442\u044c \u043f\u043b\u0435\u0439\u0431\u0443\u043a \u043d\u0430 \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0447\u0430\u0441\u0442\u0438 \u0438 \u043f\u0435\u0440\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u0445 \u0432 \u0440\u0430\u0437\u043d\u044b\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445. \u0420\u043e\u043b\u044c \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u043d\u0430\u0431\u043e\u0440\u0430 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0445 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0439 \u0438 \u0444\u0430\u0439\u043b\u043e\u0432, \u0432\u043a\u043b\u044e\u0447\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0438, \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438, \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435, \u0448\u0430\u0431\u043b\u043e\u043d\u044b \u0438 \u0444\u0430\u0439\u043b\u044b.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0440\u043e\u043b\u0438:<\/p>\n<pre><code>my_role\/ \u251c\u2500\u2500 defaults \u2502   \u2514\u2500\u2500 main.yml \u251c\u2500\u2500 files \u2502   \u2514\u2500\u2500 my_file.txt \u251c\u2500\u2500 handlers \u2502   \u2514\u2500\u2500 main.yml \u251c\u2500\u2500 tasks \u2502   \u2514\u2500\u2500 main.yml \u251c\u2500\u2500 templates \u2502   \u2514\u2500\u2500 my_template.j2 \u251c\u2500\u2500 tests \u2502   \u251c\u2500\u2500 inventory \u2502   \u2514\u2500\u2500 test.yml \u2514\u2500\u2500 vars     \u2514\u2500\u2500 main.yml<\/code><\/pre>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0440\u043e\u043b\u0438 \u0434\u043b\u044f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 Apache:<\/p>\n<pre><code class=\"yaml\"># tasks\/main.yml --- - name: \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 Apache   apt:     name: apache2     state: present  - name: \u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 Apache   template:     src: my_template.j2     dest: \/etc\/apache2\/apache2.conf   notify:     - \u041f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a Apache  - name: \u041e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 Apache   service:     name: apache2     state: started     enabled: yes<\/code><\/pre>\n<p>\u041c\u043e\u0434\u0443\u043b\u0438 \u2014 \u044d\u0442\u043e \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0449\u0438\u0435 \u043e\u0434\u043d\u0443 \u0437\u0430\u0434\u0430\u0447\u0443, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u043f\u0430\u043a\u0435\u0442\u043e\u0432, \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0444\u0430\u0439\u043b\u0430\u043c\u0438 \u0438\u043b\u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432. Ansible \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0445 \u043c\u043e\u0434\u0443\u043b\u0435\u0439, \u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u043c\u043e\u0434\u0443\u043b\u0438.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043c\u043e\u0434\u0443\u043b\u044f apt \u0434\u043b\u044f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u043f\u0430\u043a\u0435\u0442\u0430:<\/p>\n<pre><code class=\"yaml\">- name: \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 Apache   apt:     name: apache2     state: present<\/code><\/pre>\n<p>\u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u0441 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u043c\u043e\u0434\u0443\u043b\u044f\u043c\u0438 <a href=\"https:\/\/docs.ansible.com\/ansible\/2.9\/modules\/list_of_all_modules.html\">\u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c\u0441\u044f \u0437\u0434\u0435\u0441\u044c.<\/a><\/p>\n<p><strong>\u0428\u0430\u0431\u043b\u043e\u043d\u044b Jinja2<\/strong> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0444\u0430\u0439\u043b\u044b \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445. \u0424\u0430\u0439\u043b\u044b \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432 \u0438\u043c\u0435\u044e\u0442 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 <em>.j2<\/em>.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0448\u0430\u0431\u043b\u043e\u043d\u0430 Apache \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 (templates\/apache2.conf.j2):<\/p>\n<pre><code>Listen {{ http_port }} MaxClients {{ max_clients }}<\/code><\/pre>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0448\u0430\u0431\u043b\u043e\u043d\u0430 \u0432 \u0437\u0430\u0434\u0430\u0447\u0435:<\/p>\n<pre><code class=\"yaml\">- name: \u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 Apache   template:     src: templates\/apache2.conf.j2     dest: \/etc\/apache2\/apache2.conf   notify:     - \u041f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a Apache<\/code><\/pre>\n<p><strong>\u0423\u0441\u043b\u043e\u0432\u043d\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b<\/strong> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u0439.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"yaml\">- name: \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 Nginx \u043d\u0430 Debian   apt:     name: nginx     state: present   when: ansible_os_family == \"Debian\"<\/code><\/pre>\n<p>\u0414\u043b\u044f \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0440\u0430\u0437\u0432\u0435\u0440\u0442\u044b\u0432\u0430\u043d\u0438\u0439<strong> \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f \u0440\u0430\u0437\u0431\u0438\u0432\u0430\u0442\u044c \u043f\u043b\u0435\u0439\u0431\u0443\u043a\u0438 \u043d\u0430 \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0447\u0430\u0441\u0442\u0438,<\/strong> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0440\u043e\u043b\u0438 \u0438 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f.<\/p>\n<p>\u0420\u0430\u0437\u0432\u0435\u0440\u0442\u044b\u0432\u0430\u043d\u0438\u0435 \u0432\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0441 \u0411\u0414 \u0438 \u0431\u0430\u043b\u0430\u043d\u0441\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u043e\u043c \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0438:<\/p>\n<pre><code class=\"yaml\">--- - name: \u0420\u0430\u0437\u0432\u0435\u0440\u0442\u044b\u0432\u0430\u043d\u0438\u0435 \u0432\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f   hosts: all   become: yes    roles:     - load_balancer     - web_server     - database  # load_balancer\/tasks\/main.yml --- - name: \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 HAProxy   apt:     name: haproxy     state: present  - name: \u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 HAProxy   template:     src: haproxy.cfg.j2     dest: \/etc\/haproxy\/haproxy.cfg   notify:     - \u041f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a HAProxy  - name: \u041e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 HAProxy   service:     name: haproxy     state: started     enabled: yes  # web_server\/tasks\/main.yml --- - name: \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 Apache   apt:     name: apache2     state: present  - name: \u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 Apache   template:     src: apache2.conf.j2     dest: \/etc\/apache2\/apache2.conf   notify:     - \u041f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a Apache  - name: \u041e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 Apache   service:     name: apache2     state: started     enabled: yes  # database\/tasks\/main.yml --- - name: \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 MySQL   apt:     name: mysql-server     state: present  - name: \u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 MySQL   template:     src: my.cnf.j2     dest: \/etc\/mysql\/my.cnf   notify:     - \u041f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a MySQL  - name: \u041e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 MySQL   service:     name: mysql     state: started     enabled: yes<\/code><\/pre>\n<h3>\u0422\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 \u043e\u0442\u043b\u0430\u0434\u043a\u0430 \u043f\u043b\u0435\u0439\u0431\u0443\u043a\u043e\u0432  <\/h3>\n<p><strong>\u0420\u0435\u0436\u0438\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438<\/strong> \u0438\u043b\u0438 <strong>check mode<\/strong>  \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043f\u043b\u0435\u0439\u0431\u0443\u043a\u0438 \u0431\u0435\u0437 \u0432\u043d\u0435\u0441\u0435\u043d\u0438\u044f \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u0432 \u0446\u0435\u043b\u0435\u0432\u044b\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u044b.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043f\u043b\u0435\u0439\u0431\u0443\u043a\u0430 \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438:<\/p>\n<pre><code class=\"bash\">ansible-playbook my_playbook.yml --check<\/code><\/pre>\n<p>\u0412 \u0440\u0435\u0436\u0438\u043c\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 Ansible \u0441\u0438\u043c\u0443\u043b\u0438\u0440\u0443\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u0447, \u0432\u044b\u0432\u043e\u0434\u044f \u043d\u0430 \u044d\u043a\u0440\u0430\u043d \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u043c\u044b\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f.<\/p>\n<p>Ansible Vault \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d \u0434\u043b\u044f \u0437\u0430\u0449\u0438\u0442\u044b \u0447\u0443\u0432\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445. \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Vault \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0448\u0438\u0444\u0440\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0438 \u0434\u0435\u0448\u0438\u0444\u0440\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0444\u0430\u0439\u043b\u044b \u0441 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0435\u0439 \u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c\u0438.<\/p>\n<p>\u0414\u043b\u044f \u0448\u0438\u0444\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0444\u0430\u0439\u043b\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f <code>ansible-vault encrypt<\/code>:<\/p>\n<pre><code class=\"bash\">ansible-vault encrypt secrets.yml<\/code><\/pre>\n<p>\u0414\u043b\u044f \u0434\u0435\u0448\u0438\u0444\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0444\u0430\u0439\u043b\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f <code>ansible-vault decrypt<\/code>:<\/p>\n<pre><code class=\"bash\">ansible-vault decrypt secrets.yml<\/code><\/pre>\n<p>\u0427\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u0448\u0438\u0444\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0444\u0430\u0439\u043b\u044b \u0432 \u043f\u043b\u0435\u0439\u0431\u0443\u043a\u0430\u0445, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <code>--ask-vault-pass<\/code>:<\/p>\n<pre><code class=\"bash\">ansible-playbook my_playbook.yml --ask-vault-pass<\/code><\/pre>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0437\u0430\u0448\u0438\u0444\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 \u0441 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c\u0438:<\/p>\n<pre><code class=\"yaml\">--- - name: \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 MySQL   hosts: databases   become: yes   vars_files:     - secrets.yml   tasks:     - name: \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 MySQL       apt:         name: mysql-server         state: present<\/code><\/pre>\n<p><strong>Ansible-lint<\/strong> \u2014 \u044d\u0442\u043e \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u0434\u043b\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u043f\u043b\u0435\u0439\u0431\u0443\u043a\u043e\u0432 \u043d\u0430 \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u043e\u0448\u0438\u0431\u043e\u043a \u0438 \u043d\u0435\u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0439 \u0441\u0442\u0438\u043b\u044e. \u041e\u043d \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u043e\u0434\u0430.<\/p>\n<p>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 ansible-lint:<\/p>\n<pre><code class=\"bash\">pip install ansible-lint<\/code><\/pre>\n<p>\u0417\u0430\u043f\u0443\u0441\u043a ansible-lint \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043f\u043b\u0435\u0439\u0431\u0443\u043a\u0430:<\/p>\n<pre><code class=\"bash\">ansible-lint my_playbook.yml<\/code><\/pre>\n<p>Ansible-lint \u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u043f\u043b\u0435\u0439\u0431\u0443\u043a \u0438 \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u044f \u0438 \u043e\u0448\u0438\u0431\u043a\u0438, \u043f\u043e\u043c\u043e\u0433\u0430\u044f \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0434\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043f\u043b\u0435\u0439\u0431\u0443\u043a\u0430.<\/p>\n<p>\u0414\u043b\u044f \u043e\u0442\u043b\u0430\u0434\u043a\u0438 \u043f\u043b\u0435\u0439\u0431\u0443\u043a\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c:<\/p>\n<ul>\n<li>\n<p><strong>\u041c\u043e\u0434\u0443\u043b\u044c debug:<\/strong> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0434\u0438\u0430\u0433\u043d\u043e\u0441\u0442\u0438\u043a\u0438.<\/p>\n<pre><code class=\"yaml\">- name: \u041e\u0442\u043b\u0430\u0434\u043a\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445   debug:     var: my_variable<\/code><\/pre>\n<\/li>\n<li>\n<p><strong>\u0424\u043b\u0430\u0433 verbosity (-v):<\/strong> \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u0442 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0441\u0442\u0438 \u0432\u044b\u0432\u043e\u0434\u0430 Ansible.<\/p>\n<pre><code class=\"bash\">ansible-playbook my_playbook.yml -v<\/code><\/pre>\n<\/li>\n<li>\n<p><strong>\u041c\u043e\u0434\u0443\u043b\u044c assert:<\/strong> \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0438 \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043f\u0440\u0438 \u0438\u0445 \u043d\u0430\u0440\u0443\u0448\u0435\u043d\u0438\u0438.<\/p>\n<pre><code class=\"yaml\">- name: \u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439   assert:     that:       - my_variable == \"expected_value\"<\/code><\/pre>\n<\/li>\n<\/ul>\n<hr\/>\n<p>\u0410 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u0441 Ansible \u0438 \u043f\u0440\u043e\u0447\u0438\u043c\u0438 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430\u043c\u0438, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c\u0441\u044f \u043d\u0430 \u043a\u0443\u0440\u0441\u0435 Infrastructure as a code. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0443\u0436\u0435 \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u043f\u0440\u043e\u0439\u0434\u0435\u0442 \u0431\u0435\u0441\u043f\u043b\u0430\u0442\u043d\u044b\u0439 \u0432\u0435\u0431\u0438\u043d\u0430\u0440 \u043f\u0440\u043e \u0437\u043d\u0430\u043a\u043e\u043c\u0441\u0442\u0432\u043e \u0441 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u043c \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u043c Terraform. <a href=\"https:\/\/otus.pw\/4hQG\/\">\u0420\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430 \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435<\/a>.<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \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\/articles\/821263\/\"> https:\/\/habr.com\/ru\/articles\/821263\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><\/figure>\n<p><em>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440!<\/em><\/p>\n<p><a href=\"https:\/\/www.ansible.com\/\">Ansible <\/a>\u2014 \u044d\u0442\u043e \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u0434\u043b\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0430\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0431\u043b\u0435\u0433\u0447\u0430\u0435\u0442 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f\u043c\u0438, \u0440\u0430\u0437\u0432\u0435\u0440\u0442\u044b\u0432\u0430\u043d\u0438\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u0438 \u043e\u0440\u043a\u0435\u0441\u0442\u0440\u0430\u0446\u0438\u044e \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447. \u0415\u0433\u043e \u0433\u043b\u0430\u0432\u043d\u0430\u044f \u0441\u0438\u043b\u0430 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u0432\u044b\u0441\u043e\u043a\u043e\u0439 \u0447\u0438\u0442\u0430\u0435\u043c\u043e\u0441\u0442\u0438 \u043f\u043b\u0435\u0439\u0431\u0443\u043a\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0441\u043e\u0431\u043e\u0439 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0438 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0430\u0446\u0438\u0438, \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 YAML.<\/p>\n<p>\u041f\u043b\u0435\u0439\u0431\u0443\u043a\u0438 \u0432 Ansible \u2014 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 Ansible. \u041f\u043b\u0435\u0439\u0431\u0443\u043a \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u043b\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 <em>\u0438\u0433\u0440<\/em> (plays), \u043a\u0430\u0436\u0434\u0430\u044f \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445, \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 <em>\u0437\u0430\u0434\u0430\u0447\u0438<\/em> (tasks). \u042d\u0442\u0438 \u0437\u0430\u0434\u0430\u0447\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u0447\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u043b\u043e\u0436\u043d\u044b\u0435, \u043d\u043e \u043b\u0435\u0433\u043a\u043e \u0447\u0438\u0442\u0430\u0435\u043c\u044b\u0435 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0438 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0430\u0446\u0438\u0438.<\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043f\u043b\u0435\u0439\u0431\u0443\u043a\u0430\u043c\u0438 \u0432 Ansible.<\/p>\n<h3>\u041d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043f\u043b\u0435\u0439\u0431\u0443\u043a\u043e\u0432  <\/h3>\n<p>\u041c\u044b \u0443\u0436\u0435 \u0437\u043d\u0430\u0435\u043c, \u0447\u0442\u043e \u0434\u043b\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u043f\u043b\u0435\u0439\u0431\u0443\u043a\u043e\u0432 \u0432 Ansible \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 Yaml. \u041e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441\u0430 YAML:<\/p>\n<ol>\n<li>\n<p><strong>\u041e\u0442\u0441\u0442\u0443\u043f\u044b:<\/strong> YAML \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043e\u0442\u0441\u0442\u0443\u043f\u044b \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0443\u0440\u043e\u0432\u043d\u044f \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438. \u041e\u0431\u044b\u0447\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u043f\u0440\u043e\u0431\u0435\u043b\u044b, \u0430 \u043d\u0435 \u0442\u0430\u0431\u0443\u043b\u044f\u0446\u0438\u0438.<\/p>\n<\/li>\n<li>\n<p><strong>\u041a\u043b\u044e\u0447-\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435:<\/strong> \u043a\u0430\u0436\u0434\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043f\u0430\u0440\u0443 \u043a\u043b\u044e\u0447-\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 \u0434\u0432\u043e\u0435\u0442\u043e\u0447\u0438\u0435\u043c.<\/p>\n<\/li>\n<li>\n<p><strong>\u0421\u043f\u0438\u0441\u043a\u0438:<\/strong> \u0441\u043f\u0438\u0441\u043a\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u044e\u0442\u0441\u044f \u0434\u0435\u0444\u0438\u0441\u043e\u043c (-).<\/p>\n<\/li>\n<\/ol>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e YAML-\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430:<\/p>\n<pre><code class=\"yaml\">name: Ivan age: 30 address:   street: 123 Main St   city: Anytown   state: CA phone_numbers:   - type: home     number: 123-456-7890   - type: work     number: 987-654-3210<\/code><\/pre>\n<p>\u041f\u043b\u0435\u0439\u0431\u0443\u043a\u0438 Ansible \u0441\u043e\u0441\u0442\u043e\u044f\u0442 \u0438\u0437 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432:<\/p>\n<ol>\n<li>\n<p><strong>Header:<\/strong> \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u043e\u0431\u0449\u0438\u0435 \u0441\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u043e \u043f\u043b\u0435\u0439\u0431\u0443\u043a\u0435, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0438 \u0446\u0435\u043b\u0435\u0432\u044b\u0435 \u0445\u043e\u0441\u0442\u044b.<\/p>\n<\/li>\n<li>\n<p><strong>Variables:<\/strong> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u044b \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e \u0432 \u043f\u043b\u0435\u0439\u0431\u0443\u043a\u0435.<\/p>\n<\/li>\n<li>\n<p><strong>Tasks:<\/strong> \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u044b \u043d\u0430 \u0445\u043e\u0441\u0442\u0430\u0445.<\/p>\n<\/li>\n<li>\n<p><strong>Handlers:<\/strong> \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u043f\u0440\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u044b, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a \u0441\u043b\u0443\u0436\u0431\u044b \u043f\u043e\u0441\u043b\u0435 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438.<\/p>\n<\/li>\n<li>\n<p><strong>Conditionals:<\/strong> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u0439.<\/p>\n<\/li>\n<\/ol>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u043f\u043b\u0435\u0439\u0431\u0443\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u0438 \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u0442 \u0432\u0435\u0431-\u0441\u0435\u0440\u0432\u0435\u0440 Apache:<\/p>\n<pre><code class=\"yaml\">--- - name: \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 Apache   hosts: webservers   become: yes   vars:     http_port: 80     max_clients: 200   tasks:     - name: \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 Apache       apt:         name: apache2         state: present      - name: \u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 Apache       template:         src: templates\/apache2.conf.j2         dest: \/etc\/apache2\/apache2.conf       notify:         - \u041f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a Apache      - name: \u041e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 Apache       service:         name: apache2         state: started         enabled: yes    handlers:     - name: \u041f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a Apache       service:         name: apache2         state: restarted<\/code><\/pre>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043f\u043b\u0435\u0439\u0431\u0443\u043a\u0435:<\/p>\n<ul>\n<li>\n<p><code>hosts<\/code> \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0446\u0435\u043b\u0435\u0432\u044b\u0435 \u0445\u043e\u0441\u0442\u044b.<\/p>\n<\/li>\n<li>\n<p><code>become: yes<\/code> \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u0447\u0442\u043e \u0437\u0430\u0434\u0430\u0447\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f \u0441 \u043f\u0440\u0438\u0432\u0438\u043b\u0435\u0433\u0438\u044f\u043c\u0438 \u0441\u0443\u043f\u0435\u0440\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<\/p>\n<\/li>\n<li>\n<p><code>vars<\/code> \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u0432 \u043f\u043b\u0435\u0439\u0431\u0443\u043a\u0435.<\/p>\n<\/li>\n<li>\n<p><code>tasks<\/code> \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0441\u043f\u0438\u0441\u043e\u043a \u0437\u0430\u0434\u0430\u0447, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 Apache, \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u0438 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0441\u043b\u0443\u0436\u0431\u044b.<\/p>\n<\/li>\n<li>\n<p><code>handlers<\/code> \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u043f\u0440\u0438 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a Apache \u043f\u043e\u0441\u043b\u0435 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438.<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u0423\u0441\u043b\u043e\u0432\u043d\u044b\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f<\/strong> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u0439. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 Nginx \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 Debian-\u0431\u0430\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0445:<\/p>\n<pre><code class=\"yaml\">- name: \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 Nginx   apt:     name: nginx     state: present   when: ansible_os_family == \"Debian\"<\/code><\/pre>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u043f\u043b\u0435\u0439\u0431\u0443\u043a\u0430 \u0434\u043b\u044f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 MySQL:<\/p>\n<pre><code class=\"yaml\">--- - name: \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 MySQL   hosts: databases   become: yes   tasks:     - name: \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 MySQL       apt:         name: mysql-server         state: present      - name: \u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 MySQL       template:         src: templates\/my.cnf.j2         dest: \/etc\/mysql\/my.cnf       notify:         - \u041f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a MySQL      - name: \u041e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 MySQL       service:         name: mysql         state: started         enabled: yes    handlers:     - name: \u041f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a MySQL       service:         name: mysql         state: restarted<\/code><\/pre>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u043f\u043b\u0435\u0439\u0431\u0443\u043a\u0430 \u0434\u043b\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 SSH:<\/p>\n<pre><code class=\"yaml\">--- - name: \u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 SSH   hosts: all   become: yes   tasks:     - name: \u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 SSH       lineinfile:         path: \/etc\/ssh\/sshd_config         regexp: '^#PermitRootLogin'         line: 'PermitRootLogin no'       notify:         - \u041f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a SSH    handlers:     - name: \u041f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a SSH       service:         name: sshd         state: restarted<\/code><\/pre>\n<h4>\u041f\u0440\u043e\u0447\u0438\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438<\/h4>\n<p><strong>\u0420\u043e\u043b\u0438<\/strong> \u0438 <strong>\u043c\u043e\u0434\u0443\u043b\u0438<\/strong> \u0432 \u043f\u043e\u043c\u043e\u0433\u0430\u044e\u0442 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438 \u0443\u043f\u0440\u043e\u0449\u0430\u0442\u044c \u043f\u043b\u0435\u0439\u0431\u0443\u043a\u0438.<\/p>\n<p>\u0420\u043e\u043b\u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0440\u0430\u0437\u0431\u0438\u0442\u044c \u043f\u043b\u0435\u0439\u0431\u0443\u043a \u043d\u0430 \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0447\u0430\u0441\u0442\u0438 \u0438 \u043f\u0435\u0440\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u0445 \u0432 \u0440\u0430\u0437\u043d\u044b\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445. \u0420\u043e\u043b\u044c \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u043d\u0430\u0431\u043e\u0440\u0430 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0445 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0439 \u0438 \u0444\u0430\u0439\u043b\u043e\u0432, \u0432\u043a\u043b\u044e\u0447\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0438, \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438, \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435, \u0448\u0430\u0431\u043b\u043e\u043d\u044b \u0438 \u0444\u0430\u0439\u043b\u044b.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0440\u043e\u043b\u0438:<\/p>\n<pre><code>my_role\/ \u251c\u2500\u2500 defaults \u2502   \u2514\u2500\u2500 main.yml \u251c\u2500\u2500 files \u2502   \u2514\u2500\u2500 my_file.txt \u251c\u2500\u2500 handlers \u2502   \u2514\u2500\u2500 main.yml \u251c\u2500\u2500 tasks \u2502   \u2514\u2500\u2500 main.yml \u251c\u2500\u2500 templates \u2502   \u2514\u2500\u2500 my_template.j2 \u251c\u2500\u2500 tests \u2502   \u251c\u2500\u2500 inventory \u2502   \u2514\u2500\u2500 test.yml \u2514\u2500\u2500 vars     \u2514\u2500\u2500 main.yml<\/code><\/pre>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0440\u043e\u043b\u0438 \u0434\u043b\u044f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 Apache:<\/p>\n<pre><code class=\"yaml\"># tasks\/main.yml --- - name: \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 Apache   apt:     name: apache2     state: present  - name: \u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 Apache   template:     src: my_template.j2     dest: \/etc\/apache2\/apache2.conf   notify:     - \u041f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a Apache  - name: \u041e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 Apache   service:     name: apache2     state: started     enabled: yes<\/code><\/pre>\n<p>\u041c\u043e\u0434\u0443\u043b\u0438 \u2014 \u044d\u0442\u043e \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0449\u0438\u0435 \u043e\u0434\u043d\u0443 \u0437\u0430\u0434\u0430\u0447\u0443, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u043f\u0430\u043a\u0435\u0442\u043e\u0432, \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0444\u0430\u0439\u043b\u0430\u043c\u0438 \u0438\u043b\u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432. Ansible \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0445 \u043c\u043e\u0434\u0443\u043b\u0435\u0439, \u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u043c\u043e\u0434\u0443\u043b\u0438.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043c\u043e\u0434\u0443\u043b\u044f apt \u0434\u043b\u044f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u043f\u0430\u043a\u0435\u0442\u0430:<\/p>\n<pre><code class=\"yaml\">- name: \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 Apache   apt:     name: apache2     state: present<\/code><\/pre>\n<p>\u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u0441 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u043c\u043e\u0434\u0443\u043b\u044f\u043c\u0438 <a href=\"https:\/\/docs.ansible.com\/ansible\/2.9\/modules\/list_of_all_modules.html\">\u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c\u0441\u044f \u0437\u0434\u0435\u0441\u044c.<\/a><\/p>\n<p><strong>\u0428\u0430\u0431\u043b\u043e\u043d\u044b Jinja2<\/strong> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0444\u0430\u0439\u043b\u044b \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445. \u0424\u0430\u0439\u043b\u044b \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432 \u0438\u043c\u0435\u044e\u0442 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 <em>.j2<\/em>.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0448\u0430\u0431\u043b\u043e\u043d\u0430 Apache \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 (templates\/apache2.conf.j2):<\/p>\n<pre><code>Listen {{ http_port }} MaxClients {{ max_clients }}<\/code><\/pre>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0448\u0430\u0431\u043b\u043e\u043d\u0430 \u0432 \u0437\u0430\u0434\u0430\u0447\u0435:<\/p>\n<pre><code class=\"yaml\">- name: \u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 Apache   template:     src: templates\/apache2.conf.j2     dest: \/etc\/apache2\/apache2.conf   notify:     - \u041f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a Apache<\/code><\/pre>\n<p><strong>\u0423\u0441\u043b\u043e\u0432\u043d\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b<\/strong> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u0439.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"yaml\">- name: \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 Nginx \u043d\u0430 Debian   apt:     name: nginx     state: present   when: ansible_os_family == \"Debian\"<\/code><\/pre>\n<p>\u0414\u043b\u044f \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0440\u0430\u0437\u0432\u0435\u0440\u0442\u044b\u0432\u0430\u043d\u0438\u0439<strong> \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f \u0440\u0430\u0437\u0431\u0438\u0432\u0430\u0442\u044c \u043f\u043b\u0435\u0439\u0431\u0443\u043a\u0438 \u043d\u0430 \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0447\u0430\u0441\u0442\u0438,<\/strong> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0440\u043e\u043b\u0438 \u0438 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f.<\/p>\n<p>\u0420\u0430\u0437\u0432\u0435\u0440\u0442\u044b\u0432\u0430\u043d\u0438\u0435 \u0432\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0441 \u0411\u0414 \u0438 \u0431\u0430\u043b\u0430\u043d\u0441\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u043e\u043c \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0438:<\/p>\n<pre><code class=\"yaml\">--- - name: \u0420\u0430\u0437\u0432\u0435\u0440\u0442\u044b\u0432\u0430\u043d\u0438\u0435 \u0432\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f   hosts: all   become: yes    roles:     - load_balancer     - web_server     - database  # load_balancer\/tasks\/main.yml --- - name: \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 HAProxy   apt:     name: haproxy     state: present  - name: \u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 HAProxy   template:     src: haproxy.cfg.j2     dest: \/etc\/haproxy\/haproxy.cfg   notify:     - \u041f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a HAProxy  - name: \u041e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 HAProxy   service:     name: haproxy     state: started     enabled: yes  # web_server\/tasks\/main.yml --- - name: \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 Apache   apt:     name: apache2     state: present  - name: \u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 Apache   template:     src: apache2.conf.j2     dest: \/etc\/apache2\/apache2.conf   notify:     - \u041f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a Apache  - name: \u041e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 Apache   service:     name: apache2     state: started     enabled: yes  # database\/tasks\/main.yml --- - name: \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 MySQL   apt:     name: mysql-server     state: present  - name: \u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 MySQL   template:     src: my.cnf.j2     dest: \/etc\/mysql\/my.cnf   notify:     - \u041f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a MySQL  - name: \u041e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 MySQL   service:     name: mysql     state: started     enabled: yes<\/code><\/pre>\n<h3>\u0422\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 \u043e\u0442\u043b\u0430\u0434\u043a\u0430 \u043f\u043b\u0435\u0439\u0431\u0443\u043a\u043e\u0432  <\/h3>\n<p><strong>\u0420\u0435\u0436\u0438\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438<\/strong> \u0438\u043b\u0438 <strong>check mode<\/strong>  \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043f\u043b\u0435\u0439\u0431\u0443\u043a\u0438 \u0431\u0435\u0437 \u0432\u043d\u0435\u0441\u0435\u043d\u0438\u044f \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u0432 \u0446\u0435\u043b\u0435\u0432\u044b\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u044b.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043f\u043b\u0435\u0439\u0431\u0443\u043a\u0430 \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438:<\/p>\n<pre><code class=\"bash\">ansible-playbook my_playbook.yml --check<\/code><\/pre>\n<p>\u0412 \u0440\u0435\u0436\u0438\u043c\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 Ansible \u0441\u0438\u043c\u0443\u043b\u0438\u0440\u0443\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u0447, \u0432\u044b\u0432\u043e\u0434\u044f \u043d\u0430 \u044d\u043a\u0440\u0430\u043d \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u043c\u044b\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f.<\/p>\n<p>Ansible Vault \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d \u0434\u043b\u044f \u0437\u0430\u0449\u0438\u0442\u044b \u0447\u0443\u0432\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445. \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Vault \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0448\u0438\u0444\u0440\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0438 \u0434\u0435\u0448\u0438\u0444\u0440\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0444\u0430\u0439\u043b\u044b \u0441 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0435\u0439 \u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c\u0438.<\/p>\n<p>\u0414\u043b\u044f \u0448\u0438\u0444\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0444\u0430\u0439\u043b\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f <code>ansible-vault encrypt<\/code>:<\/p>\n<pre><code class=\"bash\">ansible-vault encrypt secrets.yml<\/code><\/pre>\n<p>\u0414\u043b\u044f \u0434\u0435\u0448\u0438\u0444\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0444\u0430\u0439\u043b\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f <code>ansible-vault decrypt<\/code>:<\/p>\n<pre><code class=\"bash\">ansible-vault decrypt secrets.yml<\/code><\/pre>\n<p>\u0427\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u0448\u0438\u0444\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0444\u0430\u0439\u043b\u044b \u0432 \u043f\u043b\u0435\u0439\u0431\u0443\u043a\u0430\u0445, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <code>--ask-vault-pass<\/code>:<\/p>\n<pre><code class=\"bash\">ansible-playbook my_playbook.yml --ask-vault-pass<\/code><\/pre>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0437\u0430\u0448\u0438\u0444\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 \u0441 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c\u0438:<\/p>\n<pre><code class=\"yaml\">--- - name: \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 MySQL   hosts: databases   become: yes   vars_files:     - secrets.yml   tasks:     - name: \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 MySQL       apt:         name: mysql-server         state: present<\/code><\/pre>\n<p><strong>Ansible-lint<\/strong> \u2014 \u044d\u0442\u043e \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u0434\u043b\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u043f\u043b\u0435\u0439\u0431\u0443\u043a\u043e\u0432 \u043d\u0430 \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u043e\u0448\u0438\u0431\u043e\u043a \u0438 \u043d\u0435\u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0439 \u0441\u0442\u0438\u043b\u044e. \u041e\u043d \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u043e\u0434\u0430.<\/p>\n<p>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 ansible-lint:<\/p>\n<pre><code class=\"bash\">pip install ansible-lint<\/code><\/pre>\n<p>\u0417\u0430\u043f\u0443\u0441\u043a ansible-lint \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043f\u043b\u0435\u0439\u0431\u0443\u043a\u0430:<\/p>\n<pre><code class=\"bash\">ansible-lint my_playbook.yml<\/code><\/pre>\n<p>Ansible-lint \u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u043f\u043b\u0435\u0439\u0431\u0443\u043a \u0438 \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u044f \u0438 \u043e\u0448\u0438\u0431\u043a\u0438, \u043f\u043e\u043c\u043e\u0433\u0430\u044f \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0434\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043f\u043b\u0435\u0439\u0431\u0443\u043a\u0430.<\/p>\n<p>\u0414\u043b\u044f \u043e\u0442\u043b\u0430\u0434\u043a\u0438 \u043f\u043b\u0435\u0439\u0431\u0443\u043a\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c:<\/p>\n<ul>\n<li>\n<p><strong>\u041c\u043e\u0434\u0443\u043b\u044c debug:<\/strong> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0434\u0438\u0430\u0433\u043d\u043e\u0441\u0442\u0438\u043a\u0438.<\/p>\n<pre><code class=\"yaml\">- name: \u041e\u0442\u043b\u0430\u0434\u043a\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445   debug:     var: my_variable<\/code><\/pre>\n<\/li>\n<li>\n<p><strong>\u0424\u043b\u0430\u0433 verbosity (-v):<\/strong> \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u0442 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0441\u0442\u0438 \u0432\u044b\u0432\u043e\u0434\u0430 Ansible.<\/p>\n<pre><code class=\"bash\">ansible-playbook my_playbook.yml -v<\/code><\/pre>\n<\/li>\n<li>\n<p><strong>\u041c\u043e\u0434\u0443\u043b\u044c assert:<\/strong> \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0438 \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043f\u0440\u0438 \u0438\u0445 \u043d\u0430\u0440\u0443\u0448\u0435\u043d\u0438\u0438.<\/p>\n<pre><code class=\"yaml\">- name: \u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439   assert:     that:       - my_variable == \"expected_value\"<\/code><\/pre>\n<\/li>\n<\/ul>\n<hr\/>\n<p>\u0410 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u0441 Ansible \u0438 \u043f\u0440\u043e\u0447\u0438\u043c\u0438 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430\u043c\u0438, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c\u0441\u044f \u043d\u0430 \u043a\u0443\u0440\u0441\u0435 Infrastructure as a code. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0443\u0436\u0435 \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u043f\u0440\u043e\u0439\u0434\u0435\u0442 \u0431\u0435\u0441\u043f\u043b\u0430\u0442\u043d\u044b\u0439 \u0432\u0435\u0431\u0438\u043d\u0430\u0440 \u043f\u0440\u043e \u0437\u043d\u0430\u043a\u043e\u043c\u0441\u0442\u0432\u043e \u0441 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u043c \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u043c Terraform. <a href=\"https:\/\/otus.pw\/4hQG\/\">\u0420\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430 \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435<\/a>.<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \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\/articles\/821263\/\"> https:\/\/habr.com\/ru\/articles\/821263\/<\/a><br \/><\/br><\/br><\/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-379614","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/379614","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=379614"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/379614\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=379614"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=379614"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=379614"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}