{"id":350878,"date":"2023-07-27T21:01:08","date_gmt":"2023-07-27T21:01:08","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=350878"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=350878","title":{"rendered":"<span>\u0421\u043e\u0437\u0434\u0430\u0451\u043c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 EC2 \u0438 S3 Bucket \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u043b\u0435\u0439\u0431\u0443\u043a\u0430 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<p>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043e\u0432 EC2 \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u043d\u044f\u0442\u044c \u043c\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438. \u041a \u0441\u0447\u0430\u0441\u0442\u044c\u044e, Ansible \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u0439 \u0438 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043e\u0432 EC2. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u043e\u0448\u0430\u0433\u043e\u0432\u044b\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 EC2 \u0438 S3 Bucket \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Ansible Playbooks.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/d99\/315\/71a\/d9931571ab6699a8748aef2da427f564.png\" width=\"770\" height=\"440\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d99\/315\/71a\/d9931571ab6699a8748aef2da427f564.png\"\/><\/figure>\n<h2>\u0421 \u0447\u0435\u0433\u043e \u043d\u0430\u0447\u0430\u0442\u044c:<\/h2>\n<p><strong>\u0428\u0430\u0433 1.<\/strong> \u0412\u043e\u0439\u0434\u0438\u0442\u0435 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c AWS <a href=\"https:\/\/aws.amazon.com\/console\/\">https:\/\/aws.amazon.com\/console\/<\/a><\/p>\n<p><strong>\u0428\u0430\u0433 2.<\/strong> \u0417\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0435 \u043c\u0430\u0448\u0438\u043d\u0443 \u0441 Ubuntu.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/af5\/d1c\/284\/af5d1c28424ac666bfacd83c90e129fb.png\" width=\"975\" height=\"125\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/af5\/d1c\/284\/af5d1c28424ac666bfacd83c90e129fb.png\"\/><\/figure>\n<p><strong>\u0428\u0430\u0433 3.<\/strong> \u0421\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f IAM \u0438 \u043f\u0440\u0438\u0441\u0432\u043e\u0439\u0442\u0435 \u0435\u043c\u0443 \u043f\u0440\u0430\u0432\u0430 \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u0430.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/ba4\/cf6\/cbf\/ba4cf6cbf858d11fc4589d03603bf189.png\" width=\"975\" height=\"245\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/ba4\/cf6\/cbf\/ba4cf6cbf858d11fc4589d03603bf189.png\"\/><\/figure>\n<p><strong>\u0428\u0430\u0433 4.<\/strong> \u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u0441\u044c \u043a \u043c\u0430\u0448\u0438\u043d\u0435 Ubuntu \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0438 AWS.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/f5f\/565\/8c6\/f5f5658c636a8b4783faeca3d8aec206.png\" width=\"720\" height=\"151\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f5f\/565\/8c6\/f5f5658c636a8b4783faeca3d8aec206.png\"\/><\/figure>\n<p><strong>\u0428\u0430\u0433 5.<\/strong> \u041e\u0431\u043d\u043e\u0432\u0438\u0442\u0435 \u043f\u0430\u043a\u0435\u0442\u044b \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0434\u043b\u044f \u043c\u0430\u0448\u0438\u043d\u044b Ubuntu. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u0443 c \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u043c\u0438 \u0434\u043b\u044f \u0432\u0430\u0441 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438.<\/p>\n<pre><code>sudo apt update<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/0a2\/e8a\/eff\/0a2e8aeff74fd4e1d4e08bade649bd59.png\" width=\"720\" height=\"80\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/0a2\/e8a\/eff\/0a2e8aeff74fd4e1d4e08bade649bd59.png\"\/><\/figure>\n<p><strong>\u0428\u0430\u0433 6.<\/strong> \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0435 Ansible \u043d\u0430 \u043c\u0430\u0448\u0438\u043d\u0443 \u0441 Ubuntu, \u0441\u043b\u0435\u0434\u0443\u044f \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u0439 \u043d\u0438\u0436\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u0435: <\/p>\n<pre><code>sudo apt install ansible<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/5cf\/765\/08c\/5cf76508c012974b00e9a68540cef142.png\" width=\"720\" height=\"84\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/5cf\/765\/08c\/5cf76508c012974b00e9a68540cef142.png\"\/><\/figure>\n<p><strong>\u0428\u0430\u0433 7.<\/strong> \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0435 \u043c\u043e\u0434\u0443\u043b\u0438 Ansible Galaxy, \u0441\u043b\u0435\u0434\u0443\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u0435:\u00a0<\/p>\n<pre><code>ansible-galaxy collection amazon.aws<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/3ca\/2c1\/7d7\/3ca2c17d7811a5c884caa8b43c41ddb2.png\" width=\"720\" height=\"87\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/3ca\/2c1\/7d7\/3ca2c17d7811a5c884caa8b43c41ddb2.png\"\/><\/figure>\n<p><strong>\u0428\u0430\u0433 8.<\/strong> \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0435 \u043f\u0430\u043a\u0435\u0442\u044b python \u0438 boto, \u0441\u043b\u0435\u0434\u0443\u044f \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u0439 \u043d\u0438\u0436\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u0435.<\/p>\n<pre><code>sudo apt install python3-pip<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/bd2\/21e\/efc\/bd221eefc53e4c3e19cefe43df4b1a32.png\" width=\"720\" height=\"108\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/bd2\/21e\/efc\/bd221eefc53e4c3e19cefe43df4b1a32.png\"\/><\/figure>\n<pre><code>pip install \u2014 user boto3<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/9b9\/f46\/4a2\/9b9f464a25c945955148898175bf34dd.png\" width=\"720\" height=\"98\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/9b9\/f46\/4a2\/9b9f464a25c945955148898175bf34dd.png\"\/><\/figure>\n<p><strong>\u0428\u0430\u0433 9.<\/strong> \u041d\u0430\u0441\u0442\u0440\u043e\u0439\u0442\u0435 \u0443\u0447\u0435\u0442\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 AWS, \u0441\u043b\u0435\u0434\u0443\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u0435:\u00a0<\/p>\n<pre><code>aws configure<\/code><\/pre>\n<p><strong>\u0428\u0430\u0433 10.<\/strong> \u0421\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u0444\u0430\u0439\u043b <code>Ec2instance-S3bucket.yml<\/code>.<\/p>\n<h2>\u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b<\/h2>\n<pre><code>- name: Create EC2 instance  hosts: localhost  gather_facts: yes  tasks:  - name: Create EC2 instance  community.aws.ec2_instance:  name: my-instance  instance_type: t2.micro  image_id: ami-0f5ee92e2d63afc18  key_name: test  security_groups: default  - name: Create S3 bucket  amazon.aws.s3_bucket:  name: my-bucket87653890-name  state: present<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/fd3\/d5e\/b28\/fd3d5eb28e357f5f7cb9543fe530fa4e.png\" width=\"720\" height=\"195\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/fd3\/d5e\/b28\/fd3d5eb28e357f5f7cb9543fe530fa4e.png\"\/><\/figure>\n<h2>\u0421\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u043f\u043b\u0435\u0439\u0431\u0443\u043a\u0430<\/h2>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0440\u043e\u0439\u0434\u0435\u043c\u0441\u044f \u043f\u043e \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u043c\u0443 \u044d\u0442\u043e\u0433\u043e \u043f\u043b\u0435\u0439\u0431\u0443\u043a\u0430:<\/p>\n<p><code>hosts: localhost<\/code> \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u043f\u043b\u0435\u0439\u0431\u0443\u043a \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c\u0441\u044f \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e \u043d\u0430 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0449\u0435\u0439 \u043c\u0430\u0448\u0438\u043d\u0435<\/p>\n<p><code>gather_facts:<\/code> \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0430 \u0442\u043e, \u0431\u0443\u0434\u0435\u0442 \u0438\u043b\u0438 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 Ansible \u0441\u043e\u0431\u0438\u0440\u0430\u0442\u044c \u0444\u0430\u043a\u0442\u044b \u043e \u0445\u043e\u0441\u0442\u0435.<\/p>\n<p><code>EC2_Instance<\/code> \u2014 \u044d\u0442\u043e \u043e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 EC2. \u041c\u044b \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0438\u043c\u044f \u043a\u043b\u044e\u0447\u0430, \u0442\u0438\u043f \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430, AMI-\u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440, \u0440\u0435\u0433\u0438\u043e\u043d, \u0433\u0440\u0443\u043f\u043f\u0443 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438 \u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e. \u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u0447\u0442\u043e Ansible \u0431\u0443\u0434\u0435\u0442 \u0436\u0434\u0430\u0442\u044c \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430, \u043f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u044c.<\/p>\n<p><code>Replace:<\/code> \u0417\u0430\u043c\u0435\u043d\u0438\u0442\u044c t2.micro \u043d\u0430 \u0436\u0435\u043b\u0430\u0435\u043c\u044b\u0439 \u0442\u0438\u043f \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430, ami-123456890 \u043d\u0430 \u0436\u0435\u043b\u0430\u0435\u043c\u044b\u0439 Amazon Machine Image (AMI), ap-south-1 \u043d\u0430 \u0436\u0435\u043b\u0430\u0435\u043c\u044b\u0439 \u0440\u0435\u0433\u0438\u043e\u043d, key-name \u043d\u0430 \u0438\u043c\u044f \u0432\u0430\u0448\u0435\u0439 \u043f\u0430\u0440\u044b \u043a\u043b\u044e\u0447\u0435\u0439 SSH, my-security-group \u0441 \u0438\u043c\u0435\u043d\u0435\u043c \u0432\u0430\u0448\u0435\u0439 \u0433\u0440\u0443\u043f\u043f\u044b \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438, \u0430 my-instance \u043d\u0430 \u0436\u0435\u043b\u0430\u0435\u043c\u043e\u0435 \u0438\u043c\u044f \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430.<\/p>\n<p><strong>\u0428\u0430\u0433 11.<\/strong> \u0417\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0435 ansible playbook, \u0441\u043b\u0435\u0434\u0443\u044f \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u0439 \u043d\u0438\u0436\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u0435.<\/p>\n<pre><code>ansible-playbook Ec2instance-S3bucket.yml<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/b19\/870\/e91\/b19870e91d80fda0977cf70c1c3734cb.png\" width=\"720\" height=\"176\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b19\/870\/e91\/b19870e91d80fda0977cf70c1c3734cb.png\"\/><\/figure>\n<h2>\u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c<\/h2>\n<p><strong>\u0428\u0430\u0433 1.<\/strong> \u041f\u0440\u043e\u0432\u0435\u0440\u044c\u0442\u0435, \u0441\u043e\u0437\u0434\u0430\u043d \u043b\u0438 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 Ec2?<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/0ea\/178\/bc0\/0ea178bc0604ed0867c63cecf7ce88aa.png\" width=\"720\" height=\"133\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/0ea\/178\/bc0\/0ea178bc0604ed0867c63cecf7ce88aa.png\"\/><\/figure>\n<p><strong>\u0428\u0430\u0433 2.<\/strong> \u041f\u0440\u043e\u0432\u0435\u0440\u044c\u0442\u0435, \u0441\u043e\u0437\u0434\u0430\u043d \u043b\u0438 S3 Bucket \u0438\u043b\u0438 \u043d\u0435\u0442?<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/204\/6e6\/79b\/2046e679bd0808dffa8deaea0d0ad104.png\" width=\"720\" height=\"222\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/204\/6e6\/79b\/2046e679bd0808dffa8deaea0d0ad104.png\"\/><\/figure>\n<p>\u0412\u043e\u0442 \u0438 \u0432\u0441\u0435! \u0412\u044b \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 EC2 \u0438 S3 Bucket \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Ansible Playbook.<\/p>\n<hr\/>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u043d\u0430\u0443\u0447\u0438\u0442\u044c\u0441\u044f \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0438\u0441\u0430\u0442\u044c \u043f\u043b\u0435\u0439\u0431\u0443\u043a\u0438 \u0432 Ansible, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0440\u043e\u043b\u0438 \u0438 \u043c\u043e\u0434\u0443\u043b\u0438, \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0435 \u043d\u0430 \u043a\u0443\u0440\u0441\u00a0<a href=\"https:\/\/slurm.io\/ansible?utm_source=habr&amp;utm_medium=article&amp;utm_campaign=ansible&amp;utm_content=article_27-07-2023&amp;utm_term=alitenicole\">\u00abAnsible: Infrastructure as Code\u00bb<\/a><strong>. \u041d\u043e\u0432\u044b\u0439 \u043f\u043e\u0442\u043e\u043a \u0441\u0442\u0430\u0440\u0442\u0443\u0435\u0442 21 \u0430\u0432\u0433\u0443\u0441\u0442\u0430.\u00a0<\/strong>\u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u0438 \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043a\u0443\u0440\u0441 \u043c\u043e\u0436\u043d\u043e\u00a0<a href=\"https:\/\/slurm.io\/ansible?utm_source=habr&amp;utm_medium=article&amp;utm_campaign=ansible&amp;utm_content=article_27-07-2023&amp;utm_term=alitenicole\">\u043d\u0430 \u043d\u0430\u0448\u0435\u043c \u0441\u0430\u0439\u0442\u0435<\/a>. \u0416\u0434\u0451\u043c \u043d\u0430 \u043a\u0443\u0440\u0441\u0435!<\/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\/companies\/southbridge\/articles\/750864\/\"> https:\/\/habr.com\/ru\/companies\/southbridge\/articles\/750864\/<\/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<p>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043e\u0432 EC2 \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u043d\u044f\u0442\u044c \u043c\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438. \u041a \u0441\u0447\u0430\u0441\u0442\u044c\u044e, Ansible \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u0439 \u0438 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043e\u0432 EC2. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u043e\u0448\u0430\u0433\u043e\u0432\u044b\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 EC2 \u0438 S3 Bucket \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Ansible Playbooks.<\/p>\n<figure class=\"full-width\"><\/figure>\n<h2>\u0421 \u0447\u0435\u0433\u043e \u043d\u0430\u0447\u0430\u0442\u044c:<\/h2>\n<p><strong>\u0428\u0430\u0433 1.<\/strong> \u0412\u043e\u0439\u0434\u0438\u0442\u0435 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c AWS <a href=\"https:\/\/aws.amazon.com\/console\/\">https:\/\/aws.amazon.com\/console\/<\/a><\/p>\n<p><strong>\u0428\u0430\u0433 2.<\/strong> \u0417\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0435 \u043c\u0430\u0448\u0438\u043d\u0443 \u0441 Ubuntu.<\/p>\n<figure class=\"full-width\"><\/figure>\n<p><strong>\u0428\u0430\u0433 3.<\/strong> \u0421\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f IAM \u0438 \u043f\u0440\u0438\u0441\u0432\u043e\u0439\u0442\u0435 \u0435\u043c\u0443 \u043f\u0440\u0430\u0432\u0430 \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u0430.<\/p>\n<figure class=\"full-width\"><\/figure>\n<p><strong>\u0428\u0430\u0433 4.<\/strong> \u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u0441\u044c \u043a \u043c\u0430\u0448\u0438\u043d\u0435 Ubuntu \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0438 AWS.<\/p>\n<figure class=\"full-width\"><\/figure>\n<p><strong>\u0428\u0430\u0433 5.<\/strong> \u041e\u0431\u043d\u043e\u0432\u0438\u0442\u0435 \u043f\u0430\u043a\u0435\u0442\u044b \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0434\u043b\u044f \u043c\u0430\u0448\u0438\u043d\u044b Ubuntu. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u0443 c \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u043c\u0438 \u0434\u043b\u044f \u0432\u0430\u0441 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438.<\/p>\n<pre><code>sudo apt update<\/code><\/pre>\n<figure class=\"full-width\"><\/figure>\n<p><strong>\u0428\u0430\u0433 6.<\/strong> \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0435 Ansible \u043d\u0430 \u043c\u0430\u0448\u0438\u043d\u0443 \u0441 Ubuntu, \u0441\u043b\u0435\u0434\u0443\u044f \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u0439 \u043d\u0438\u0436\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u0435: <\/p>\n<pre><code>sudo apt install ansible<\/code><\/pre>\n<figure class=\"full-width\"><\/figure>\n<p><strong>\u0428\u0430\u0433 7.<\/strong> \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0435 \u043c\u043e\u0434\u0443\u043b\u0438 Ansible Galaxy, \u0441\u043b\u0435\u0434\u0443\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u0435:\u00a0<\/p>\n<pre><code>ansible-galaxy collection amazon.aws<\/code><\/pre>\n<figure class=\"full-width\"><\/figure>\n<p><strong>\u0428\u0430\u0433 8.<\/strong> \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0435 \u043f\u0430\u043a\u0435\u0442\u044b python \u0438 boto, \u0441\u043b\u0435\u0434\u0443\u044f \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u0439 \u043d\u0438\u0436\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u0435.<\/p>\n<pre><code>sudo apt install python3-pip<\/code><\/pre>\n<figure class=\"full-width\"><\/figure>\n<pre><code>pip install \u2014 user boto3<\/code><\/pre>\n<figure class=\"full-width\"><\/figure>\n<p><strong>\u0428\u0430\u0433 9.<\/strong> \u041d\u0430\u0441\u0442\u0440\u043e\u0439\u0442\u0435 \u0443\u0447\u0435\u0442\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 AWS, \u0441\u043b\u0435\u0434\u0443\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u0435:\u00a0<\/p>\n<pre><code>aws configure<\/code><\/pre>\n<p><strong>\u0428\u0430\u0433 10.<\/strong> \u0421\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u0444\u0430\u0439\u043b <code>Ec2instance-S3bucket.yml<\/code>.<\/p>\n<h2>\u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b<\/h2>\n<pre><code>- name: Create EC2 instance  hosts: localhost  gather_facts: yes  tasks:  - name: Create EC2 instance  community.aws.ec2_instance:  name: my-instance  instance_type: t2.micro  image_id: ami-0f5ee92e2d63afc18  key_name: test  security_groups: default  - name: Create S3 bucket  amazon.aws.s3_bucket:  name: my-bucket87653890-name  state: present<\/code><\/pre>\n<figure class=\"full-width\"><\/figure>\n<h2>\u0421\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u043f\u043b\u0435\u0439\u0431\u0443\u043a\u0430<\/h2>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0440\u043e\u0439\u0434\u0435\u043c\u0441\u044f \u043f\u043e \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u043c\u0443 \u044d\u0442\u043e\u0433\u043e \u043f\u043b\u0435\u0439\u0431\u0443\u043a\u0430:<\/p>\n<p><code>hosts: localhost<\/code> \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u043f\u043b\u0435\u0439\u0431\u0443\u043a \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c\u0441\u044f \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e \u043d\u0430 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0449\u0435\u0439 \u043c\u0430\u0448\u0438\u043d\u0435<\/p>\n<p><code>gather_facts:<\/code> \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0430 \u0442\u043e, \u0431\u0443\u0434\u0435\u0442 \u0438\u043b\u0438 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 Ansible \u0441\u043e\u0431\u0438\u0440\u0430\u0442\u044c \u0444\u0430\u043a\u0442\u044b \u043e \u0445\u043e\u0441\u0442\u0435.<\/p>\n<p><code>EC2_Instance<\/code> \u2014 \u044d\u0442\u043e \u043e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 EC2. \u041c\u044b \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0438\u043c\u044f \u043a\u043b\u044e\u0447\u0430, \u0442\u0438\u043f \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430, AMI-\u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440, \u0440\u0435\u0433\u0438\u043e\u043d, \u0433\u0440\u0443\u043f\u043f\u0443 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438 \u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e. \u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u0447\u0442\u043e Ansible \u0431\u0443\u0434\u0435\u0442 \u0436\u0434\u0430\u0442\u044c \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430, \u043f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u044c.<\/p>\n<p><code>Replace:<\/code> \u0417\u0430\u043c\u0435\u043d\u0438\u0442\u044c t2.micro \u043d\u0430 \u0436\u0435\u043b\u0430\u0435\u043c\u044b\u0439 \u0442\u0438\u043f \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430, ami-123456890 \u043d\u0430 \u0436\u0435\u043b\u0430\u0435\u043c\u044b\u0439 Amazon Machine Image (AMI), ap-south-1 \u043d\u0430 \u0436\u0435\u043b\u0430\u0435\u043c\u044b\u0439 \u0440\u0435\u0433\u0438\u043e\u043d, key-name \u043d\u0430 \u0438\u043c\u044f \u0432\u0430\u0448\u0435\u0439 \u043f\u0430\u0440\u044b \u043a\u043b\u044e\u0447\u0435\u0439 SSH, my-security-group \u0441 \u0438\u043c\u0435\u043d\u0435\u043c \u0432\u0430\u0448\u0435\u0439 \u0433\u0440\u0443\u043f\u043f\u044b \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438, \u0430 my-instance \u043d\u0430 \u0436\u0435\u043b\u0430\u0435\u043c\u043e\u0435 \u0438\u043c\u044f \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430.<\/p>\n<p><strong>\u0428\u0430\u0433 11.<\/strong> \u0417\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0435 ansible playbook, \u0441\u043b\u0435\u0434\u0443\u044f \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u0439 \u043d\u0438\u0436\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u0435.<\/p>\n<pre><code>ansible-playbook Ec2instance-S3bucket.yml<\/code><\/pre>\n<figure class=\"full-width\"><\/figure>\n<h2>\u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c<\/h2>\n<p><strong>\u0428\u0430\u0433 1.<\/strong> \u041f\u0440\u043e\u0432\u0435\u0440\u044c\u0442\u0435, \u0441\u043e\u0437\u0434\u0430\u043d \u043b\u0438 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 Ec2?<\/p>\n<figure class=\"full-width\"><\/figure>\n<p><strong>\u0428\u0430\u0433 2.<\/strong> \u041f\u0440\u043e\u0432\u0435\u0440\u044c\u0442\u0435, \u0441\u043e\u0437\u0434\u0430\u043d \u043b\u0438 S3 Bucket \u0438\u043b\u0438 \u043d\u0435\u0442?<\/p>\n<figure class=\"full-width\"><\/figure>\n<p>\u0412\u043e\u0442 \u0438 \u0432\u0441\u0435! \u0412\u044b \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 EC2 \u0438 S3 Bucket \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Ansible Playbook.<\/p>\n<hr\/>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u043d\u0430\u0443\u0447\u0438\u0442\u044c\u0441\u044f \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0438\u0441\u0430\u0442\u044c \u043f\u043b\u0435\u0439\u0431\u0443\u043a\u0438 \u0432 Ansible, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0440\u043e\u043b\u0438 \u0438 \u043c\u043e\u0434\u0443\u043b\u0438, \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0435 \u043d\u0430 \u043a\u0443\u0440\u0441\u00a0<a href=\"https:\/\/slurm.io\/ansible?utm_source=habr&amp;utm_medium=article&amp;utm_campaign=ansible&amp;utm_content=article_27-07-2023&amp;utm_term=alitenicole\">\u00abAnsible: Infrastructure as Code\u00bb<\/a><strong>. \u041d\u043e\u0432\u044b\u0439 \u043f\u043e\u0442\u043e\u043a \u0441\u0442\u0430\u0440\u0442\u0443\u0435\u0442 21 \u0430\u0432\u0433\u0443\u0441\u0442\u0430.\u00a0<\/strong>\u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u0438 \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043a\u0443\u0440\u0441 \u043c\u043e\u0436\u043d\u043e\u00a0<a href=\"https:\/\/slurm.io\/ansible?utm_source=habr&amp;utm_medium=article&amp;utm_campaign=ansible&amp;utm_content=article_27-07-2023&amp;utm_term=alitenicole\">\u043d\u0430 \u043d\u0430\u0448\u0435\u043c \u0441\u0430\u0439\u0442\u0435<\/a>. \u0416\u0434\u0451\u043c \u043d\u0430 \u043a\u0443\u0440\u0441\u0435!<\/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\/companies\/southbridge\/articles\/750864\/\"> https:\/\/habr.com\/ru\/companies\/southbridge\/articles\/750864\/<\/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-350878","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/350878","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=350878"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/350878\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=350878"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=350878"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=350878"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}