{"id":7605,"date":"2013-03-26T10:43:00","date_gmt":"2013-03-26T09:43:00","guid":{"rendered":"https:\/\/blog.trifork.com\/?p=7605"},"modified":"2013-03-26T10:43:00","modified_gmt":"2013-03-26T09:43:00","slug":"ansible-next-generation-configuration-management","status":"publish","type":"post","link":"https:\/\/trifork.nl\/blog\/ansible-next-generation-configuration-management\/","title":{"rendered":"Ansible &#8211; next generation configuration management"},"content":{"rendered":"<p>The popularity of the cloud has taken configuration management to the next level. Tools that help system administrators and developers configure and manage large amounts of servers, like Chef and Puppet, have popped up everywhere. Ansible is the next generation configuration management. Ansible can be used to excute tasks on remote computers via SSH so no agent is required on the remote computer. It was originally created by Michael DeHaan.<br \/>\nI won&#8217;t compare Ansible with <a href=\"https:\/\/puppetlabs.com\/\" target=\"_blank\" rel=\"noopener\">Puppet<\/a> or <a href=\"http:\/\/www.opscode.com\/chef\/\" target=\"_blank\" rel=\"noopener\">Chef<\/a>, you can check the Ansible <a href=\"http:\/\/ansible.cc\/faq.html\" target=\"_blank\" rel=\"noopener\">FAQ<\/a>. But the key differentiators are that Anisble does not require an agent to be installed, its commands can be ordered, can be extended via modules written in any language as long as they return JSON, basically taking the best of both worlds (Puppet and Chef).<\/p>\n<h2>Instalation<\/h2>\n<p>You&#8217;ll want to install Ansible on a central computer from which you can reach all the other computers.<\/p>\n<p>On Fedora, it is already packaged:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nsudo yum install ansible\n<\/pre>\n<p>On Ubuntu, you need to add a repo:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nsudo add-apt-repository ppa:rquillo\/ansible\nsudo apt-get install ansible\n<\/pre>\n<p>On Mac, you can use <a href=\"http:\/\/www.macports.org\/\" target=\"_blank\" rel=\"noopener\">MacPorts<\/a>.<\/p>\n<p>On others, compile it from source https:\/\/github.com\/ansible\/ansible.<\/p>\n<h2>Getting started<\/h2>\n<p>One of the core constructs in Ansible is the notion of an inventory. Ansible uses this inventory to know which computers should be included when executing a module for a given group. An inventory is a very simple file (by default it uses \/etc\/ansible\/hosts) containing groups of computers.<\/p>\n<p>Example:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&#x5B;appservers]\napp1.trifork.nl\napp2.trifork.nl\n<\/pre>\n<p>As part of the inventory you can also initialize variables common to a group. These variables can then be reused when executing tasks for each computer.<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&#x5B;appservers]\napp1.trifork.nl\napp2.trifork.nl\n\n&#x5B;appservers:vars]\ntomcat_version=7\njava_version=7\n<\/pre>\n<p>You can set your own inventory by setting a global environment variable:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nexport ANSIBLE_HOSTS=my-ansible-inventory\n<\/pre>\n<p>You can then start using Ansible right away:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nansible appservers -m ping -u my-user -k\n<\/pre>\n<p>What this does is run module &#8216;ping&#8217; for all computer in the group appservers, it returns:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\napp1.trifork.nl | success &gt;&gt; {\n&quot;changed&quot;: false,\n&quot;ping&quot;: &quot;pong&quot;\n}\n\napp2.trifork.nl | success &gt;&gt; {\n&quot;changed&quot;: false,\n&quot;ping&quot;: &quot;pong&quot;\n}\n<\/pre>\n<p>You see that the module executed successfully on both hosts. We&#8217;ll come back to the &#8216;changed&#8217; output later.<br \/>\n-u tells Ansible that you want to use another user (it uses root by default) to login on the remote computers. -k tells Ansible that you want to provide a password for this user.<br \/>\nIn most cases you&#8217;ll probably want to setup a passwordless connection to the remote computers, ssh-copy-id will help you do that. Or better, you can rely on ssh-agent.<\/p>\n<h2>Gathering facts<\/h2>\n<p>Most of the time when using Ansible, you want to know something about the computer you are executing a task on.<br \/>\nThe &#8216;setup&#8217; module does just that, it gathers facts about a computer.<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nansible appservers -m setup -u tomcat -k\n<\/pre>\n<p>You get a big output (I&#8217;ve removed some of it):<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\napp1.trifork.nl | success &gt;&gt; {\n    &quot;ansible_facts&quot;: {\n        ...\n        &quot;ansible_architecture&quot;: &quot;x86_64&quot;,\n        ...\n        &quot;ansible_distribution&quot;: &quot;Ubuntu&quot;,\n        ...\n        &quot;ansible_domain&quot;: &quot;trifork.nl&quot;,\n        ...\n        &quot;ansible_fqdn&quot;: &quot;app1.trifork.nl&quot;,\n        &quot;ansible_hostname&quot;: &quot;app1&quot;,\n        &quot;ansible_interfaces&quot;: &#x5B;\n            &quot;lo&quot;,\n            &quot;eth0&quot;\n        ],\n        ...\n        &quot;ansible_machine&quot;: &quot;x86_64&quot;,\n        &quot;ansible_memfree_mb&quot;: 1279,\n        &quot;ansible_memtotal_mb&quot;: 8004,\n        &quot;ansible_pkg_mgr&quot;: &quot;apt&quot;,\n        ...\n        &quot;ansible_system&quot;: &quot;Linux&quot;,\n        ...\n    },\n    &quot;changed&quot;: false,\n    &quot;verbose_override&quot;: true\n}\n\napp2.trifork.nl | success &gt;&gt; {\n    &quot;ansible_facts&quot;: {\n        ...\n        &quot;ansible_architecture&quot;: &quot;x86_64&quot;,\n        ...\n        &quot;ansible_distribution&quot;: &quot;Ubuntu&quot;,\n        ...\n        &quot;ansible_domain&quot;: &quot;trifork.nl&quot;,\n        &quot;ansible_fqdn&quot;: &quot;app2.trifork.nl&quot;,\n        &quot;ansible_hostname&quot;: &quot;app2&quot;,\n        &quot;ansible_interfaces&quot;: &#x5B;\n            &quot;lo&quot;,\n            &quot;eth0&quot;\n        ],\n        ...\n        &quot;ansible_machine&quot;: &quot;x86_64&quot;,\n        &quot;ansible_memfree_mb&quot;: 583,\n        &quot;ansible_memtotal_mb&quot;: 2009,\n        &quot;ansible_pkg_mgr&quot;: &quot;apt&quot;,\n        ...\n        &quot;ansible_system&quot;: &quot;Linux&quot;,\n        ...\n    },\n    &quot;changed&quot;: false,\n    &quot;verbose_override&quot;: true\n}\n<\/pre>\n<p>These are Ansible facts, Ansible can also use extra facts gathered by <a href=\"http:\/\/docs.opscode.com\/ohai.html\" target=\"_blank\" rel=\"noopener\">ohai<\/a> or <a href=\"https:\/\/puppetlabs.com\/puppet\/related-projects\/facter\/\" target=\"_blank\" rel=\"noopener\">facter<\/a>.<\/p>\n<p>Let&#8217;s review some of the Ansible facts:<\/p>\n<p><strong>ansible_pkg_mgr<\/strong>: This tells which package manager is in use on the remote Linux computer. This is important if you want to use the &#8216;apt&#8217; or &#8216;yum&#8217; module and want to make your scripts (playbooks) distro-agnositic.<br \/>\n<strong>ansible_distribution<\/strong>: This tells which Linux distribution is installed on the remote computer.<br \/>\n<strong>ansible_architecture<\/strong>: If you want to know which OS architecture it is.<\/p>\n<p>Next time we&#8217;ll use these facts together with <a href=\"http:\/\/ansible.cc\/docs\/modules.html\" target=\"_blank\" rel=\"noopener\">modules<\/a> in a playbook example.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The popularity of the cloud has taken configuration management to the next level. Tools that help system administrators and developers configure and manage large amounts of servers, like Chef and Puppet, have popped up everywhere. Ansible is the next generation configuration management. Ansible can be used to excute tasks on remote computers via SSH so [&hellip;]<\/p>\n","protected":false},"author":83,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"content-type":"","footnotes":""},"categories":[88,10,124],"tags":[332,333,115,220,86,90],"class_list":["post-7605","post","type-post","status-publish","format-standard","hentry","category-devops","category-development","category-system-administration","tag-ansible","tag-chef","tag-cloud","tag-configuration-management","tag-devops","tag-puppet"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Ansible - next generation configuration management - Trifork 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:\/\/trifork.nl\/blog\/ansible-next-generation-configuration-management\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Ansible - next generation configuration management - Trifork Blog\" \/>\n<meta property=\"og:description\" content=\"The popularity of the cloud has taken configuration management to the next level. Tools that help system administrators and developers configure and manage large amounts of servers, like Chef and Puppet, have popped up everywhere. Ansible is the next generation configuration management. Ansible can be used to excute tasks on remote computers via SSH so [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/trifork.nl\/blog\/ansible-next-generation-configuration-management\/\" \/>\n<meta property=\"og:site_name\" content=\"Trifork Blog\" \/>\n<meta property=\"article:published_time\" content=\"2013-03-26T09:43:00+00:00\" \/>\n<meta name=\"author\" content=\"Mohamed El Moussaoui\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Mohamed El Moussaoui\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/trifork.nl\/blog\/ansible-next-generation-configuration-management\/\",\"url\":\"https:\/\/trifork.nl\/blog\/ansible-next-generation-configuration-management\/\",\"name\":\"Ansible - next generation configuration management - Trifork Blog\",\"isPartOf\":{\"@id\":\"https:\/\/trifork.nl\/blog\/#website\"},\"datePublished\":\"2013-03-26T09:43:00+00:00\",\"author\":{\"@id\":\"https:\/\/trifork.nl\/blog\/#\/schema\/person\/e83488f033bd62395bd3eb801ddf8972\"},\"breadcrumb\":{\"@id\":\"https:\/\/trifork.nl\/blog\/ansible-next-generation-configuration-management\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/trifork.nl\/blog\/ansible-next-generation-configuration-management\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/trifork.nl\/blog\/ansible-next-generation-configuration-management\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/trifork.nl\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Ansible &#8211; next generation configuration management\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/trifork.nl\/blog\/#website\",\"url\":\"https:\/\/trifork.nl\/blog\/\",\"name\":\"Trifork Blog\",\"description\":\"Keep updated on the technical solutions Trifork is working on!\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/trifork.nl\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/trifork.nl\/blog\/#\/schema\/person\/e83488f033bd62395bd3eb801ddf8972\",\"name\":\"Mohamed El Moussaoui\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/trifork.nl\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/d239ca3a713280c0c1b58648c249fd57?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/d239ca3a713280c0c1b58648c249fd57?s=96&d=mm&r=g\",\"caption\":\"Mohamed El Moussaoui\"},\"url\":\"https:\/\/trifork.nl\/blog\/author\/mohamedm\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Ansible - next generation configuration management - Trifork 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:\/\/trifork.nl\/blog\/ansible-next-generation-configuration-management\/","og_locale":"en_US","og_type":"article","og_title":"Ansible - next generation configuration management - Trifork Blog","og_description":"The popularity of the cloud has taken configuration management to the next level. Tools that help system administrators and developers configure and manage large amounts of servers, like Chef and Puppet, have popped up everywhere. Ansible is the next generation configuration management. Ansible can be used to excute tasks on remote computers via SSH so [&hellip;]","og_url":"https:\/\/trifork.nl\/blog\/ansible-next-generation-configuration-management\/","og_site_name":"Trifork Blog","article_published_time":"2013-03-26T09:43:00+00:00","author":"Mohamed El Moussaoui","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Mohamed El Moussaoui","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/trifork.nl\/blog\/ansible-next-generation-configuration-management\/","url":"https:\/\/trifork.nl\/blog\/ansible-next-generation-configuration-management\/","name":"Ansible - next generation configuration management - Trifork Blog","isPartOf":{"@id":"https:\/\/trifork.nl\/blog\/#website"},"datePublished":"2013-03-26T09:43:00+00:00","author":{"@id":"https:\/\/trifork.nl\/blog\/#\/schema\/person\/e83488f033bd62395bd3eb801ddf8972"},"breadcrumb":{"@id":"https:\/\/trifork.nl\/blog\/ansible-next-generation-configuration-management\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/trifork.nl\/blog\/ansible-next-generation-configuration-management\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/trifork.nl\/blog\/ansible-next-generation-configuration-management\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/trifork.nl\/blog\/"},{"@type":"ListItem","position":2,"name":"Ansible &#8211; next generation configuration management"}]},{"@type":"WebSite","@id":"https:\/\/trifork.nl\/blog\/#website","url":"https:\/\/trifork.nl\/blog\/","name":"Trifork Blog","description":"Keep updated on the technical solutions Trifork is working on!","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/trifork.nl\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/trifork.nl\/blog\/#\/schema\/person\/e83488f033bd62395bd3eb801ddf8972","name":"Mohamed El Moussaoui","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/trifork.nl\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/d239ca3a713280c0c1b58648c249fd57?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d239ca3a713280c0c1b58648c249fd57?s=96&d=mm&r=g","caption":"Mohamed El Moussaoui"},"url":"https:\/\/trifork.nl\/blog\/author\/mohamedm\/"}]}},"_links":{"self":[{"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/posts\/7605","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/users\/83"}],"replies":[{"embeddable":true,"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/comments?post=7605"}],"version-history":[{"count":0,"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/posts\/7605\/revisions"}],"wp:attachment":[{"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/media?parent=7605"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/categories?post=7605"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/tags?post=7605"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}