{"id":21675,"date":"2015-06-29T15:21:55","date_gmt":"2015-06-29T09:51:55","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=21675"},"modified":"2015-07-06T13:45:13","modified_gmt":"2015-07-06T08:15:13","slug":"ansible-configuration-management-system","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/ansible-configuration-management-system\/","title":{"rendered":"Ansible &#8211; Configuration Management System"},"content":{"rendered":"<p><strong>Purpose:<\/strong> We have seen various instances of manual <a href=\"http:\/\/www.tothenew.com\/devops-aws\">configuration on multiple servers<\/a> which are similar and repetitive. When it comes to automate such tasks an easy process comes in mind &#8211; Configuration Management. There are several such tools available for this purpose. Ansible is one such tool that can be used for configuration management tasks, continuous deployment tasks and more.<\/p>\n<p><strong>Scope: <\/strong>This blog covers basics of Ansible, Installation and platform(s) supported by it along with one use case.<\/p>\n<p><strong>What is Ansible<br \/>\n<\/strong><br \/>\nAnsible is a lightweight, open source configuration management system which has an Agentless architecture. It mean that the nodes do not require to install and run background daemons to connect with main control node. This type of architecture reduces the pressure on the network by preventing the nodes to poll control node.<\/p>\n<p><strong>Setup<\/strong><br \/>\nFor the demo I have launched three <strong>ubuntu<\/strong> <a href=\"http:\/\/www.tothenew.com\/devops-aws\">AWS ec2 instances<\/a>. One of them will be control node and other two will be managed nodes. We have to install ansible only on control node.<\/p>\n<h3>Installation steps<\/h3>\n<p>We can install ansible in two ways. Either, use apt\/yum for a stable version or install from source to get development version of Ansible which has advantage of new features when they are implemented.<\/p>\n<p>Run following commands to install ansible from source in control node<\/p>\n<p>[js] apt-get install git<br \/>\n git clone git:\/\/github.com\/ansible\/ansible.git &#8211;recursive<br \/>\n cd .\/ansible<br \/>\n source .\/hacking\/env-setup[\/js]<\/p>\n<p>Also install python modules(paramiko,PyYAML,Jinja2,httplib2) using pip command used by ansible<\/p>\n<p><strong>Supported platform<\/strong><\/p>\n<p><strong>Control node<\/strong>&#8211;<br \/>\n1. Python 2.6 or higher<br \/>\n2. Windows -not supported<br \/>\n3. OS supported: Almost all Linux and Unix distributions<\/p>\n<p><strong>Managed Nodes<\/strong>&#8211;<br \/>\n1. Python 2.4 or later.<br \/>\n2. Windows nodes -from version 1.7<\/p>\n<p><strong>Configuring Inventory File -Default Location -&#8216;\/etc\/ansible\/hosts&#8217;<\/strong><\/p>\n<p>It is used to define which servers ansible will be managing. Since, we are running instances in same VPC it is advisable to use private ip&#8217;s.<\/p>\n<p>We can also logically group our servers in inventory file as follows:<\/p>\n<p>[webservers]<br \/>\n172.1.2.3<br \/>\n172.1.2.4<\/p>\n<p>[dbservers]<br \/>\n172.1.2.5<\/p>\n<p>We can all these grouped servers in our ansible playbook as hosts:webservers.<\/p>\n<p>Ansible uses SSH keys for authentication between control node and managed nodes. Use &#8216;ssh-keygen&#8217; to generate public key. Copy the public key generated in &#8216;\/root\/.ssh\/id_rsa.pub&#8217; to all managed nodes (location:\/root\/.ssh\/authorized_keys) you want ansible to connect to.<\/p>\n<p><strong>Test the connection<\/strong><\/p>\n<p>From the control machine we will try pinging all the hosts mentioned in \/etc\/ansible\/hosts file<\/p>\n<p>[js]ansible all -m ping[\/js]<\/p>\n<p>all &#8211; Use all defined servers from the inventory file<br \/>\n-m ping &#8211; Use the &#8220;ping&#8221; module, which simply runs the ping command and returns the results<\/p>\n<p>Output:<br \/>\n<img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-21966\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/06\/Ping_success.png\" alt=\"Ping_success\" width=\"468\" height=\"161\" \/><\/p>\n<p><strong>Writing Playbook<\/strong><\/p>\n<p>After configuring inventory file, we can run tasks against the hosts defined in inventory file. These tasks are defined in ansible playbooks which are plain english yaml scripts. By default, Ansible run all the tasks parrallelly in all the nodes. We can also configure serial execution of tasks.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-21959\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/06\/Playbook1.png\" alt=\"Playbook\" width=\"722\" height=\"164\" \/><\/p>\n<p><strong>Output on running ansible playbook on control node<\/strong><br \/>\n<img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-21961\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/06\/Screenshot-from-2015-06-29-102130.png\" alt=\"Screenshot from 2015-06-29 10:21:30\" width=\"672\" height=\"382\" \/><\/p>\n<p><strong>Login to hosts machines for verification<\/strong><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-21962\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/06\/Verify1.png\" alt=\"Verify1\" width=\"979\" height=\"236\" \/><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-21963\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/06\/Verify2.png\" alt=\"Verify2\" width=\"345\" height=\"100\" \/><\/p>\n<p>This approach can be used for Continous Deployment setup where the latest version of war can be pulled from a repository like nexus and can be copied to web servers like jetty.<\/p>\n<p>Ansible also provides a dashboard(<strong>Ansible Tower<\/strong>) to manage hosts. It is free to use for up to 30 days beyond which license is required.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Purpose: We have seen various instances of manual configuration on multiple servers which are similar and repetitive. When it comes to automate such tasks an easy process comes in mind &#8211; Configuration Management. There are several such tools available for this purpose. Ansible is one such tool that can be used for configuration management tasks, [&hellip;]<\/p>\n","protected":false},"author":214,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":2},"categories":[1174,1],"tags":[1933],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/21675"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/214"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=21675"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/21675\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=21675"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=21675"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=21675"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}