{"id":7361,"date":"2016-03-17T13:05:01","date_gmt":"2016-03-17T12:05:01","guid":{"rendered":"https:\/\/www.dbi-services.com\/blog\/getting-started-with-ansible-preparations\/"},"modified":"2016-03-17T13:05:01","modified_gmt":"2016-03-17T12:05:01","slug":"getting-started-with-ansible-preparations","status":"publish","type":"post","link":"https:\/\/www.dbi-services.com\/blog\/getting-started-with-ansible-preparations\/","title":{"rendered":"Getting started with Ansible &#8211; Preparations"},"content":{"rendered":"<p>When your infrastructure landscape becomes larger and larger you definitely need a tool which helps you in managing your servers, no matter if p\u1e27ysical or virtual, running in the cloud or not. One tool (many others are around) which assists you in provisioning, configuration management and mass deployment is <a href=\"https:\/\/www.ansible.com\" target=\"_blank\" rel=\"noopener\">Ansible<\/a>. If you look at the man page you can find this sentence: &#8220;Ansible is an extra-simple tool\/framework\/API for doing &#8216;remote things&#8217; over SSH.&#8221;. What is better than learning by doing? Lets start:<\/p>\n<p>I have three <a href=\"https:\/\/www.centos.org\" target=\"_blank\" rel=\"noopener\">CentOS 7.2<\/a> core installations:<\/p>\n<table>\n<tr>\n<th>hostname<\/th>\n<th>description<\/th>\n<th>ip<\/th>\n<\/tr>\n<tr>\n<td>ansible-control<\/td>\n<td>The ansible control host. All Ansible commands will be executed from here<\/td>\n<td>192.168.22.170<\/td>\n<\/tr>\n<tr>\n<td>ansible-pg1<\/td>\n<td>The first host that will be managed by Ansible<\/td>\n<td>192.168.22.171<\/td>\n<\/tr>\n<tr>\n<td>ansible-pg2<\/td>\n<td>The second host that will be managed by Ansible<\/td>\n<td>192.168.22.172<\/td>\n<\/tr>\n<\/table>\n<p>All of these hosts are on the same CentOS release (although that does not really matter):<\/p>\n<pre class=\"brush: bash; gutter: true; firsts-line: 1\">\n[root@ansible-control~]$ cat \/etc\/centos-release\nCentOS Linux release 7.2.1511 (Core)\n<\/pre>\n<p>Obviously the first step is to get Ansible installed on the control host. There is nothing we need to install on the hosts we want to manage. Ansible does not require to setup any agents which is one of the main advantages over other tools. The only requirement is ssh. There are various ways to get Ansible installed but for the scope of this post we&#8217;ll go with yum as Ansible is available in the <a href=\"https:\/\/fedoraproject.org\/wiki\/EPEL\" target=\"_blank\" rel=\"noopener\">EPEL repository<\/a>. Lets add the repository:<\/p>\n<pre class=\"brush: bash; gutter: true; firsts-line: 1\">\n[root@ansible-control~]$ yum install -y https:\/\/dl.fedoraproject.org\/pub\/epel\/epel-release-latest-7.noarch.rpm\n[root@ansible-control~]$ rpm -qa | grep epel\nepel-release-7-5.noarch\n<\/pre>\n<p>From there on installing Ansible is just a matter of using yum:<\/p>\n<pre class=\"brush: bash; gutter: true; firsts-line: 1\">\n[root@ansible-control~]$ yum install -y ansible\n<\/pre>\n<p>At the time of writing this will install version 1.9.4 of Ansible:<\/p>\n<pre class=\"brush: bash; gutter: true; firsts-line: 1\">\n[ansible@ansible-control ~]$ ansible --version\nansible 1.9.4\n  configured module search path = None\n<\/pre>\n<p>Yum will take care of all the dependencies (e.g. python) and setup everything for us. Before starting to work with Ansible (because we do not want to work with root) all three hosts get a group and a user created. So, for all hosts:<\/p>\n<pre class=\"brush: bash; gutter: true; firsts-line: 1\">\n[root@ansible-control~]$ groupadd ansible\n[root@ansible-control~]$ useradd -g ansible ansible\n[root@ansible-control~]$ passwd ansible \n[root@ansible-control~]$ su - ansible\n[ansible@ansible-control~]$ ssh-keygen -t rsa\n<\/pre>\n<p>The generation of the ssh keys is important as we&#8217;ll use password-less ssh authentication for talking from the control host to the managed hosts. To succeed with this we&#8217;ll need to copy the ssh ids from the control host to the managed hosts:<\/p>\n<pre class=\"brush: bash; gutter: true; firsts-line: 1\">\n[ansible@ansible-control ~]$ ssh-copy-id -i .ssh\/id_rsa.pub ansible@192.168.22.171\n[ansible@ansible-control ~]$ ssh-copy-id -i .ssh\/id_rsa.pub ansible@192.168.22.172\n<\/pre>\n<p>How does the control host know which hosts it shall manage if nothing gets installed on the clients? Quite easy: there is a configuration file in \/etc\/ansible. As we do want to work with our dedicated user we&#8217;ll change the permissions:<\/p>\n<pre class=\"brush: bash; gutter: true; firsts-line: 1\">\n[root@ansible-control~]$ chown -R ansible:ansible \/etc\/ansible\/*\n<\/pre>\n<p>Using the Ansible user we can now create our first hosts file:<\/p>\n<pre class=\"brush: bash; gutter: true; firsts-line: 1\">\n[ansible@ansible-control ~]$ cat \/etc\/ansible\/hosts\n[postgres-servers]\n192.168.22.171\n192.168.22.172\n<\/pre>\n<p>The name in brackets is a so called group name. This means be referencing &#8220;postgres-servers&#8221; in the Ansible commands Ansible resolves the group name to the server names listed for that group. Lets do a basic test to check if we can talk to our clients:<\/p>\n<pre class=\"brush: bash; gutter: true; firsts-line: 1\">\n[ansible@ansible-control ~]$ ansible postgres-servers -a \"\/bin\/echo 11\"\n192.168.22.171 | success | rc=0 &gt;&gt;\n11\n\n192.168.22.172 | success | rc=0 &gt;&gt;\n11\n<\/pre>\n<p>Cool, works. We can run the same command on both clients. If there are more clients you can tell Ansible to use N parallel forks to execute the commands by using the &#8220;-f&#8221; switch (5 is the default):<\/p>\n<pre class=\"brush: bash; gutter: true; firsts-line: 1\">\n[ansible@ansible-control ~]$ ansible postgres-servers -a \"\/bin\/echo 11\" -f 5\n192.168.22.171 | success | rc=0 &gt;&gt;\n11\n\n192.168.22.172 | success | rc=0 &gt;&gt;\n11\n<\/pre>\n<p>You might already guessed it from the naming of the clients that there will be something about PostgreSQL in this post. And, you&#8217;re right \ud83d\ude42 To outline one use case for Ansible we&#8217;ll setup PostgreSQL on two hosts in exactly the same way using Ansible in the next post.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When your infrastructure landscape becomes larger and larger you definitely need a tool which helps you in managing your servers, no matter if p\u1e27ysical or virtual, running in the cloud or not. One tool (many others are around) which assists you in provisioning, configuration management and mass deployment is Ansible. If you look at the [&hellip;]<\/p>\n","protected":false},"author":29,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[229,42],"tags":[150,768,769,77,770],"type_dbi":[],"class_list":["post-7361","post","type-post","status-publish","format-standard","hentry","category-database-administration-monitoring","category-operating-systems","tag-ansible","tag-configuration-management","tag-deployment","tag-postgresql","tag-provisioning"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.2 (Yoast SEO v27.2) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Getting started with Ansible - Preparations - dbi Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.dbi-services.com\/blog\/getting-started-with-ansible-preparations\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Getting started with Ansible - Preparations\" \/>\n<meta property=\"og:description\" content=\"When your infrastructure landscape becomes larger and larger you definitely need a tool which helps you in managing your servers, no matter if p\u1e27ysical or virtual, running in the cloud or not. One tool (many others are around) which assists you in provisioning, configuration management and mass deployment is Ansible. If you look at the [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.dbi-services.com\/blog\/getting-started-with-ansible-preparations\/\" \/>\n<meta property=\"og:site_name\" content=\"dbi Blog\" \/>\n<meta property=\"article:published_time\" content=\"2016-03-17T12:05:01+00:00\" \/>\n<meta name=\"author\" content=\"Daniel Westermann\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@westermanndanie\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Daniel Westermann\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/getting-started-with-ansible-preparations\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/getting-started-with-ansible-preparations\/\"},\"author\":{\"name\":\"Daniel Westermann\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/8d08e9bd996a89bd75c0286cbabf3c66\"},\"headline\":\"Getting started with Ansible &#8211; Preparations\",\"datePublished\":\"2016-03-17T12:05:01+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/getting-started-with-ansible-preparations\/\"},\"wordCount\":532,\"commentCount\":0,\"keywords\":[\"Ansible\",\"Configuration Management\",\"Deployment\",\"PostgreSQL\",\"Provisioning\"],\"articleSection\":[\"Database Administration &amp; Monitoring\",\"Operating systems\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/getting-started-with-ansible-preparations\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/getting-started-with-ansible-preparations\/\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/getting-started-with-ansible-preparations\/\",\"name\":\"Getting started with Ansible - Preparations - dbi Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#website\"},\"datePublished\":\"2016-03-17T12:05:01+00:00\",\"author\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/8d08e9bd996a89bd75c0286cbabf3c66\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/getting-started-with-ansible-preparations\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/getting-started-with-ansible-preparations\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/getting-started-with-ansible-preparations\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Accueil\",\"item\":\"https:\/\/www.dbi-services.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Getting started with Ansible &#8211; Preparations\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#website\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/\",\"name\":\"dbi Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.dbi-services.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/8d08e9bd996a89bd75c0286cbabf3c66\",\"name\":\"Daniel Westermann\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/secure.gravatar.com\/avatar\/31350ceeecb1dd8986339a29bf040d4cd3cd087d410deccd8f55234466d6c317?s=96&d=mm&r=g\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/31350ceeecb1dd8986339a29bf040d4cd3cd087d410deccd8f55234466d6c317?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/31350ceeecb1dd8986339a29bf040d4cd3cd087d410deccd8f55234466d6c317?s=96&d=mm&r=g\",\"caption\":\"Daniel Westermann\"},\"description\":\"Daniel Westermann is Principal Consultant and Technology Leader Open Infrastructure at dbi services. He has more than 15 years of experience in management, engineering and optimization of databases and infrastructures, especially on Oracle and PostgreSQL. Since the beginning of his career, he has specialized in Oracle Technologies and is Oracle Certified Professional 12c and Oracle Certified Expert RAC\/GridInfra. Over time, Daniel has become increasingly interested in open source technologies, becoming \u201cTechnology Leader Open Infrastructure\u201d and PostgreSQL expert. \u00a0Based on community or EnterpriseDB tools, he develops and installs complex high available solutions with PostgreSQL. He is also a certified PostgreSQL Plus 9.0 Professional and a Postgres Advanced Server 9.4 Professional. He is a regular speaker at PostgreSQL conferences in Switzerland and Europe. Today Daniel is also supporting our customers on AWS services such as AWS RDS, database migrations into the cloud, EC2 and automated infrastructure management with AWS SSM (System Manager). He is a certified AWS Solutions Architect Professional. Prior to dbi services, Daniel was Management System Engineer at LC SYSTEMS-Engineering AG in Basel. Before that, he worked as Oracle Developper &amp;\u00a0Project Manager at Delta Energy Solutions AG in Basel (today Powel AG). Daniel holds a diploma in Business Informatics (DHBW, Germany). His branch-related experience mainly covers the pharma industry, the financial sector, energy, lottery and telecommunications.\",\"sameAs\":[\"https:\/\/x.com\/westermanndanie\"],\"url\":\"https:\/\/www.dbi-services.com\/blog\/author\/daniel-westermann\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Getting started with Ansible - Preparations - dbi Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.dbi-services.com\/blog\/getting-started-with-ansible-preparations\/","og_locale":"en_US","og_type":"article","og_title":"Getting started with Ansible - Preparations","og_description":"When your infrastructure landscape becomes larger and larger you definitely need a tool which helps you in managing your servers, no matter if p\u1e27ysical or virtual, running in the cloud or not. One tool (many others are around) which assists you in provisioning, configuration management and mass deployment is Ansible. If you look at the [&hellip;]","og_url":"https:\/\/www.dbi-services.com\/blog\/getting-started-with-ansible-preparations\/","og_site_name":"dbi Blog","article_published_time":"2016-03-17T12:05:01+00:00","author":"Daniel Westermann","twitter_card":"summary_large_image","twitter_creator":"@westermanndanie","twitter_misc":{"Written by":"Daniel Westermann","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.dbi-services.com\/blog\/getting-started-with-ansible-preparations\/#article","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/getting-started-with-ansible-preparations\/"},"author":{"name":"Daniel Westermann","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/8d08e9bd996a89bd75c0286cbabf3c66"},"headline":"Getting started with Ansible &#8211; Preparations","datePublished":"2016-03-17T12:05:01+00:00","mainEntityOfPage":{"@id":"https:\/\/www.dbi-services.com\/blog\/getting-started-with-ansible-preparations\/"},"wordCount":532,"commentCount":0,"keywords":["Ansible","Configuration Management","Deployment","PostgreSQL","Provisioning"],"articleSection":["Database Administration &amp; Monitoring","Operating systems"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.dbi-services.com\/blog\/getting-started-with-ansible-preparations\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.dbi-services.com\/blog\/getting-started-with-ansible-preparations\/","url":"https:\/\/www.dbi-services.com\/blog\/getting-started-with-ansible-preparations\/","name":"Getting started with Ansible - Preparations - dbi Blog","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/#website"},"datePublished":"2016-03-17T12:05:01+00:00","author":{"@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/8d08e9bd996a89bd75c0286cbabf3c66"},"breadcrumb":{"@id":"https:\/\/www.dbi-services.com\/blog\/getting-started-with-ansible-preparations\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.dbi-services.com\/blog\/getting-started-with-ansible-preparations\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.dbi-services.com\/blog\/getting-started-with-ansible-preparations\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Accueil","item":"https:\/\/www.dbi-services.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Getting started with Ansible &#8211; Preparations"}]},{"@type":"WebSite","@id":"https:\/\/www.dbi-services.com\/blog\/#website","url":"https:\/\/www.dbi-services.com\/blog\/","name":"dbi Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.dbi-services.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/8d08e9bd996a89bd75c0286cbabf3c66","name":"Daniel Westermann","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/31350ceeecb1dd8986339a29bf040d4cd3cd087d410deccd8f55234466d6c317?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/31350ceeecb1dd8986339a29bf040d4cd3cd087d410deccd8f55234466d6c317?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/31350ceeecb1dd8986339a29bf040d4cd3cd087d410deccd8f55234466d6c317?s=96&d=mm&r=g","caption":"Daniel Westermann"},"description":"Daniel Westermann is Principal Consultant and Technology Leader Open Infrastructure at dbi services. He has more than 15 years of experience in management, engineering and optimization of databases and infrastructures, especially on Oracle and PostgreSQL. Since the beginning of his career, he has specialized in Oracle Technologies and is Oracle Certified Professional 12c and Oracle Certified Expert RAC\/GridInfra. Over time, Daniel has become increasingly interested in open source technologies, becoming \u201cTechnology Leader Open Infrastructure\u201d and PostgreSQL expert. \u00a0Based on community or EnterpriseDB tools, he develops and installs complex high available solutions with PostgreSQL. He is also a certified PostgreSQL Plus 9.0 Professional and a Postgres Advanced Server 9.4 Professional. He is a regular speaker at PostgreSQL conferences in Switzerland and Europe. Today Daniel is also supporting our customers on AWS services such as AWS RDS, database migrations into the cloud, EC2 and automated infrastructure management with AWS SSM (System Manager). He is a certified AWS Solutions Architect Professional. Prior to dbi services, Daniel was Management System Engineer at LC SYSTEMS-Engineering AG in Basel. Before that, he worked as Oracle Developper &amp;\u00a0Project Manager at Delta Energy Solutions AG in Basel (today Powel AG). Daniel holds a diploma in Business Informatics (DHBW, Germany). His branch-related experience mainly covers the pharma industry, the financial sector, energy, lottery and telecommunications.","sameAs":["https:\/\/x.com\/westermanndanie"],"url":"https:\/\/www.dbi-services.com\/blog\/author\/daniel-westermann\/"}]}},"_links":{"self":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/7361","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/users\/29"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/comments?post=7361"}],"version-history":[{"count":0,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/7361\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/media?parent=7361"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/categories?post=7361"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/tags?post=7361"},{"taxonomy":"type","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/type_dbi?post=7361"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}