{"id":1414,"date":"2019-08-28T16:15:59","date_gmt":"2019-08-28T13:15:59","guid":{"rendered":"https:\/\/artem.services\/?p=1392"},"modified":"2019-09-24T21:47:24","modified_gmt":"2019-09-24T18:47:24","slug":"1414","status":"publish","type":"post","link":"https:\/\/artem.services\/?p=1414&lang=en","title":{"rendered":"\u00a0Ansible &#8212; Install"},"content":{"rendered":"<p><img loading=\"lazy\" class=\"aligncenter wp-image-1393 \" src=\"https:\/\/artem.services\/wp-content\/uploads\/2019\/08\/ansible-logo-300x169.png\" alt=\"\" width=\"526\" height=\"296\" srcset=\"https:\/\/artem.services\/wp-content\/uploads\/2019\/08\/ansible-logo-300x169.png 300w, https:\/\/artem.services\/wp-content\/uploads\/2019\/08\/ansible-logo-768x432.png 768w, https:\/\/artem.services\/wp-content\/uploads\/2019\/08\/ansible-logo-1024x576.png 1024w, https:\/\/artem.services\/wp-content\/uploads\/2019\/08\/ansible-logo-954x537.png 954w, https:\/\/artem.services\/wp-content\/uploads\/2019\/08\/ansible-logo.png 1280w\" sizes=\"(max-width: 526px) 100vw, 526px\" \/><\/p>\n<p><span class=\"tlid-translation translation\" lang=\"en\"><span class=\"\" title=\"\">A simple example of installing Ansible and adding a host.<\/span><\/p>\n<p><span class=\"\" title=\"\">Install Ansible:<\/span><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong>RedHat<\/strong> systems:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nyum install ansible\r\n<\/pre>\n<p><strong>Deb<\/strong> systems:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\napt install ansible\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>Generate an <strong>SSH<\/strong> key if it is not on the instance with <strong>Ansible<\/strong>:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nssh-keygen -t rsa\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>Add the public key to the host, which we will manage:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nssh-copy-id root@192.168.1.101\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>Add the host to the list:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nvim \/etc\/ansible\/hosts\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>And insert the following into it:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n192.168.1.101 ansible_ssh_user=root\r\n<\/pre>\n<p>&nbsp;<\/p>\n<blockquote><p>You can specify both an <strong>IP<\/strong> address and a <strong>DNS<\/strong> name.<br \/>\n<strong>root<\/strong> &#8212; the user on the remote machine that is used when connecting<\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<p>Check the connection:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nansible -m ping all\r\n\r\n192.168.1.101 | SUCCESS =&gt; {\r\n    &quot;ansible_facts&quot;: {\r\n        &quot;discovered_interpreter_python&quot;: &quot;\/usr\/bin\/python&quot;\r\n    },\r\n    &quot;changed&quot;: false,\r\n    &quot;ping&quot;: &quot;pong&quot;\r\n}\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><span class=\"tlid-translation translation\" lang=\"en\" tabindex=\"-1\"><span title=\"\"><strong>all<\/strong> &#8212; run on all hosts specified in the file &quot;<strong>\/etc\/ansible\/hosts<\/strong>&quot;<\/span><\/p>\n<p><span title=\"\">You can group hosts.<\/span> <span title=\"\">For example, create a group &quot;<strong>web<\/strong>&quot; for our host:<\/span><\/span><\/p>\n<p>&nbsp;<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n[web]\r\n192.168.1.101 ansible_ssh_user=root\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><span class=\"tlid-translation translation\" lang=\"en\"><span class=\"\" title=\"\">Now you can call by group name:<\/span><\/span><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nansible -m ping web\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>A simple example of installing Ansible and adding a host. Install Ansible: &nbsp; RedHat systems: Deb systems: &nbsp; Generate an SSH key if it is not on the instance with Ansible: &nbsp; Add the public key to the host, which we will manage: &nbsp; Add the host to the list: &nbsp; And insert the following &hellip; <a href=\"https:\/\/artem.services\/?p=1414&#038;lang=en\" class=\"more-link\">\u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u044c \u0447\u0438\u0442\u0430\u0442\u044c<span class=\"screen-reader-text\"> &quot;\u00a0Ansible &#8212; Install&quot;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1131],"tags":[1133],"_links":{"self":[{"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/1414"}],"collection":[{"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1414"}],"version-history":[{"count":2,"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/1414\/revisions"}],"predecessor-version":[{"id":1417,"href":"https:\/\/artem.services\/index.php?rest_route=\/wp\/v2\/posts\/1414\/revisions\/1417"}],"wp:attachment":[{"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1414"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1414"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/artem.services\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1414"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}