{"id":736,"date":"2018-06-06T10:17:06","date_gmt":"2018-06-06T10:17:06","guid":{"rendered":"https:\/\/www.nicktailor.com\/?p=736"},"modified":"2018-06-06T13:33:42","modified_gmt":"2018-06-06T13:33:42","slug":"how-to-setup-anisble-for-to-manage-windows-hosts-on-ubuntu-16-04","status":"publish","type":"post","link":"https:\/\/nicktailor.com\/tech-blog\/how-to-setup-anisble-for-to-manage-windows-hosts-on-ubuntu-16-04\/","title":{"rendered":"How to setup Anisble on Ubuntu 16.04"},"content":{"rendered":"<p><strong>Installation<br \/>\n<\/strong><\/p>\n<p>Type the following\u00a0<a href=\"https:\/\/www.cyberciti.biz\/tips\/linux-debian-package-management-cheat-sheet.html\">apt-get command<\/a>\u00a0or\u00a0<a href=\"https:\/\/www.cyberciti.biz\/faq\/ubuntu-lts-debian-linux-apt-command-examples\/\">apt command<\/a>:<br \/>\n$ sudo apt-get update<br \/>\n$ sudo apt-get upgrade<br \/>\n$ sudo apt-get install software-properties-common<br \/>\nNext add ppa:ansible\/ansible to your system\u2019s Software Source:<br \/>\n$ sudo apt-add-repository ppa:ansible\/ansible<\/p>\n<table width=\"607\">\n<tbody>\n<tr>\n<td width=\"607\">\u00a0Ansible is a radically simple IT automation platform that makes your applications and systems easier to deploy. Avoid writing scripts or custom code to deploy and update your applications\u2014 automate in a language that approaches plain English, using SSH, with no agents to install on remote systems.<\/p>\n<p>&nbsp;<\/p>\n<p>http:\/\/ansible.com\/<\/p>\n<p>More info: https:\/\/launchpad.net\/~ansible\/+archive\/ubuntu\/ansible<\/p>\n<p>Press <strong>[ENTER]<\/strong> to continue or Ctrl-c to cancel adding it.<\/p>\n<p>gpg: keybox &#8216;\/tmp\/tmp6t9bsfxg\/pubring.gpg&#8217; created<\/p>\n<p>gpg: \/tmp\/tmp6t9bsfxg\/trustdb.gpg: trustdb created<\/p>\n<p>gpg: key 93C4A3FD7BB9C367: public key &#8220;Launchpad PPA for Ansible, Inc.&#8221; imported<\/p>\n<p>gpg: Total number processed: 1<\/p>\n<p>gpg:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 imported: 1<\/p>\n<p>OK<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Update your repos:<br \/>\n$ sudo apt-get update<br \/>\nSample outputs:<\/p>\n<p><span style=\"font-weight: 300;\">To install the latest version of ansible, enter:<\/span><\/p>\n<table width=\"607\">\n<tbody>\n<tr>\n<td width=\"607\">Ign:1 http:\/\/dl.google.com\/linux\/chrome\/deb stable InRelease<\/p>\n<p>Hit:2 http:\/\/dl.google.com\/linux\/chrome\/deb stable Release<\/p>\n<p>Get:4 http:\/\/in.archive.ubuntu.com\/ubuntu artful InRelease <strong>[237 kB]<\/strong><\/p>\n<p>Hit:5 http:\/\/security.ubuntu.com\/ubuntu artful-security InRelease<\/p>\n<p>Get:6 http:\/\/ppa.launchpad.net\/ansible\/ansible\/ubuntu artful InRelease <strong>[15.9 kB]<\/strong><\/p>\n<p>Get:7 http:\/\/ppa.launchpad.net\/ansible\/ansible\/ubuntu artful\/main amd64 Packages <strong>[560 B]<\/strong><\/p>\n<p>Get:8 http:\/\/in.archive.ubuntu.com\/ubuntu artful-updates InRelease <strong>[65.4 kB]<\/strong><\/p>\n<p>Hit:9 http:\/\/in.archive.ubuntu.com\/ubuntu artful-backports InRelease<\/p>\n<p>Get:10 http:\/\/ppa.launchpad.net\/ansible\/ansible\/ubuntu artful\/main i386 Packages <strong>[560 B]<\/strong><\/p>\n<p>Get:11 http:\/\/ppa.launchpad.net\/ansible\/ansible\/ubuntu artful\/main Translation-en <strong>[340 B]<\/strong><\/p>\n<p>Fetched 319 kB in 5s (62.3 kB\/s)<\/p>\n<p>Reading package lists&#8230; Done<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>$ sudo apt-get install ansible<\/p>\n<p><span style=\"font-weight: 300;\">Type the following command:<\/span><strong>Finding out Ansible version<\/strong><\/p>\n<p>$ ansible &#8211;version<br \/>\nSample outputs:<\/p>\n<table width=\"607\">\n<tbody>\n<tr>\n<td width=\"607\">ansible 2.4.0.0<\/p>\n<p>config file <strong>=<\/strong> \/etc\/ansible\/ansible.cfg<\/p>\n<p>configured module search path <strong>=<\/strong> <strong>[u&#8217;\/home\/vivek\/.ansible\/plugins\/modules&#8217;, u&#8217;\/usr\/share\/ansible\/plugins\/modules&#8217;]<\/strong><\/p>\n<p>ansible python module location <strong>=<\/strong> \/usr\/lib\/python2.7\/dist-packages\/ansible<\/p>\n<p>executable location <strong>=<\/strong> \/usr\/bin\/ansible<\/p>\n<p>python version <strong>=<\/strong> 2.7.14 (default, Sep 23 2017, 22:06:14) <strong>[GCC 7.2.0]<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Creating your hosts file<\/strong><\/p>\n<p>Ansible needs to know your remote server names or IP address. This information is stored in a file called hosts. The default is \/etc\/ansible\/hosts. You can edit this one or create a new one in your $HOME directory:<br \/>\n$ sudo vi \/etc\/ansible\/hosts<br \/>\nOr<br \/>\n$ vi $HOME\/hosts<br \/>\nAppend your server\u2019s DNS or IP address:<\/p>\n<p>[webservers]<\/p>\n<p>server1.nicktailor.com<\/p>\n<p>192.168.0.21<\/p>\n<p>192.168.0.25<\/p>\n<p>&nbsp;<\/p>\n<p>[devservers]<\/p>\n<p>192.168.0.22<\/p>\n<p>192.168.0.23<\/p>\n<p>192.168.0.24<\/p>\n<p>I have two groups. The first one named as webserver and other is called devservers.<\/p>\n<p><strong>Setting up ssh keys<\/strong><\/p>\n<p>You\u00a0must configure ssh keys between your machine and remote servers\u00a0specified in ~\/hosts file:<br \/>\n$ ssh-keygen -t rsa -b 4096 -C &#8220;My ansisble key&#8221;<br \/>\nUse scp or ssh-copy-id command to copy your public key file (e.g., $HOME\/.ssh\/id_rsa.pub) to your account on the remote server\/host:<br \/>\n$ ssh-copy-id -i $HOME\/.ssh\/id_rsa.pub root@server1.cyberciti.biz<br \/>\n$ ssh-copy-id -i $HOME\/.ssh\/id_rsa.pub root@192.168.0.22<br \/>\n$ ssh-copy-id -i $HOME\/.ssh\/id_rsa.pub root@192.168.0.23<br \/>\n$ ssh-copy-id -i $HOME\/.ssh\/id_rsa.pub root@192.168.0.24<br \/>\n$ eval $(ssh-agent)<br \/>\n$ ssh-add<br \/>\nNow ansible can talk to all remote servers using ssh command.<\/p>\n<p><strong>Send ping server to all servers<\/strong><\/p>\n<p>Just type the following command:<br \/>\n$ ansible -i ~\/hosts -m ping all<br \/>\nSample outputs:<\/p>\n<p>192.168.0.22 | SUCCESS =&gt; {<\/p>\n<p>&#8220;changed&#8221;: false,<\/p>\n<p>&#8220;failed&#8221;: false,<\/p>\n<p>&#8220;ping&#8221;: &#8220;pong&#8221;<\/p>\n<p>}<\/p>\n<p>192.168.0.23 | SUCCESS =&gt; {<\/p>\n<p>&#8220;changed&#8221;: false,<\/p>\n<p>&#8220;failed&#8221;: false,<\/p>\n<p>&#8220;ping&#8221;: &#8220;pong&#8221;<\/p>\n<p>}<\/p>\n<p>192.168.0.24 | SUCCESS =&gt; {<\/p>\n<p>&#8220;changed&#8221;: false,<\/p>\n<p>&#8220;failed&#8221;: false,<\/p>\n<p>&#8220;ping&#8221;: &#8220;pong&#8221;<\/p>\n<p>}<\/p>\n<p><strong>Find out uptime for all hosts<\/strong><\/p>\n<p>$ ansible -i hosts -m shell -a &#8216;uptime&#8217; all<br \/>\nSample outputs:<\/p>\n<table width=\"600\">\n<tbody>\n<tr>\n<td width=\"600\">do-de.public | SUCCESS | rc<strong>=<\/strong>0<\/p>\n<p>10:37:02 up 1 day,\u00a0 8:39,\u00a0 1 user,\u00a0 load average: 0.95, 0.27, 0.12<\/p>\n<p>&nbsp;<\/p>\n<p>do-blr-vpn | SUCCESS | rc<strong>=<\/strong>0<\/p>\n<p>16:07:11 up 1 day,\u00a0 8:43,\u00a0 1 user,\u00a0 load average: 0.01, 0.01, 0.00<\/p>\n<p>&nbsp;<\/p>\n<p>ln.gfs01 | SUCCESS | rc<strong>=<\/strong>0<\/p>\n<p>10:37:17 up 22 days,\u00a0 5:30,\u00a0 1 user,\u00a0 load average: 0.18, 0.12, 0.05<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Where,<\/p>\n<ol>\n<li><strong>-i ~\/hosts<\/strong>: Specify inventory host path. You can setup shell variable and skip the -i option. For e.g.:\u00a0<strong>export ANSIBLE_HOSTS=~\/hosts<\/strong><\/li>\n<li><strong>-m shell<\/strong>: Module name to execute such as shell, apt, yum and so on<\/li>\n<li><strong>-a &#8216;uptime&#8217;<\/strong>: Module arguments. For example, shell module will accept Unix\/Linux command names. The apt module will accept options to update remote boxes using apt-get\/apt command and so on.<\/li>\n<li><strong>all<\/strong>: The all means \u201call hosts.\u201d You can speificy group name such as devservers (ansible -i hosts -m shell -a &#8216;uptime&#8217; dbservers) or host names too.<\/li>\n<\/ol>\n<p><strong>Update all Debian\/Ubuntu server using apt module<\/strong><\/p>\n<p>Run the following command:<br \/>\n$ ansible -i ~\/hosts -m apt -a &#8216;update_cache=yes upgrade=dist&#8217; dbservers<\/p>\n<p><strong>Writing your first playbook<\/strong><\/p>\n<p>You can combine all modules in a text file as follows in yml format i.e. create a file named update.yml:<\/p>\n<p>&#8212;<\/p>\n<p>&#8211; hosts: dbservers<\/p>\n<p>tasks:<\/p>\n<p>&#8211; name: Updating host using apt<\/p>\n<p>apt:<\/p>\n<p>update_cache: yes<\/p>\n<p><span style=\"font-weight: 300;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 upgrade: dist<\/span><\/p>\n<p><span style=\"font-weight: 300;\">Fig.01: Ansible playbook in action<\/span>Now you can run it as follows:<br \/>\n$ ansible-playbook -i ~\/hosts update.yml<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Installation Type the following\u00a0apt-get command\u00a0or\u00a0apt command: $ sudo apt-get update $ sudo apt-get upgrade $ sudo apt-get install software-properties-common Next add ppa:ansible\/ansible to your system\u2019s Software Source: $ sudo apt-add-repository ppa:ansible\/ansible \u00a0Ansible is a radically simple IT automation platform that makes your applications and systems easier to deploy. Avoid writing scripts or custom code to deploy and update your applications\u2014<a href=\"https:\/\/nicktailor.com\/tech-blog\/how-to-setup-anisble-for-to-manage-windows-hosts-on-ubuntu-16-04\/\" class=\"read-more\">Read More &#8230;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[51],"tags":[],"class_list":["post-736","post","type-post","status-publish","format-standard","hentry","category-ansible"],"_links":{"self":[{"href":"https:\/\/nicktailor.com\/tech-blog\/wp-json\/wp\/v2\/posts\/736","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nicktailor.com\/tech-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nicktailor.com\/tech-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nicktailor.com\/tech-blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nicktailor.com\/tech-blog\/wp-json\/wp\/v2\/comments?post=736"}],"version-history":[{"count":9,"href":"https:\/\/nicktailor.com\/tech-blog\/wp-json\/wp\/v2\/posts\/736\/revisions"}],"predecessor-version":[{"id":747,"href":"https:\/\/nicktailor.com\/tech-blog\/wp-json\/wp\/v2\/posts\/736\/revisions\/747"}],"wp:attachment":[{"href":"https:\/\/nicktailor.com\/tech-blog\/wp-json\/wp\/v2\/media?parent=736"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nicktailor.com\/tech-blog\/wp-json\/wp\/v2\/categories?post=736"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nicktailor.com\/tech-blog\/wp-json\/wp\/v2\/tags?post=736"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}