<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ansible Archives - Linux Windows and android Tutorials</title>
	<atom:link href="https://www.osradar.com/tag/ansible/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.osradar.com</link>
	<description>tutorials and news and Seurity</description>
	<lastBuildDate>Mon, 16 Sep 2019 19:41:45 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.8.12</generator>
	<item>
		<title>Install ElasticSearch via Ansible</title>
		<link>https://www.osradar.com/install-elasticsearch-via-ansible/</link>
					<comments>https://www.osradar.com/install-elasticsearch-via-ansible/#respond</comments>
		
		<dc:creator><![CDATA[osradar_editor]]></dc:creator>
		<pubDate>Mon, 16 Sep 2019 19:41:45 +0000</pubDate>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[ansible]]></category>
		<category><![CDATA[Elasticsearch]]></category>
		<guid isPermaLink="false">https://www.osradar.com/?p=11307</guid>

					<description><![CDATA[<p>The whole idea of this post is obvious. I have already covered the same objective in a standard fashion but this is about perform the installation via ansible automation. If you don&#8217;t have an understanding on Ansible Directory Structure &#8211; I really recommend to check my other post &#8211;  where I highlighted each key areas [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://www.osradar.com/install-elasticsearch-via-ansible/">Install ElasticSearch via Ansible</a> appeared first on <a rel="nofollow" href="https://www.osradar.com">Linux  Windows and android  Tutorials</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>The whole idea of this post is obvious. I have already covered the same objective in a standard fashion but this is about perform the installation via ansible automation. If you don&#8217;t have an understanding on Ansible Directory Structure &#8211; I really recommend to check my other <a href="https://www.osradar.com/getting-understand-ansible-structure/">post</a> &#8211;  where I highlighted each key areas that needed to get familiar.</p>
<h4><strong>Inventory File</strong></h4>
<p>In the example, I am going to deploy Three nodes of ElasticSearch &#8211; one represent MASTER role, while other two as DATA role.</p>
<pre><strong>[elastic_master]</strong>
es-0001 ansible_host=172.17.0.10
<strong>
[elastic_data]</strong>
es-0002 ansible_host=172.17.0.11
es-0003 ansible_host=172.17.0.12
</pre>
<p>&nbsp;</p>
<h4><strong>prod.yaml</strong></h4>
<pre>- hosts: elastic_master <span style="color: #008000;">&lt;------------ following actions will be performed against any host listed in <strong>elastic_master</strong> alias which found to be in inventory file</span>
  remote_user: root <span style="color: #008000;">&lt;---------------- to execute the command as root</span>
  become: true
  pre_tasks:
    - name: "Installing basic packages"
      action: yum <span style="color: #008000;">&lt;---------------- calls the yum module and any key that goes with <strong>with_items</strong> will be installed</span>
              name={{ item }}
              state=installed
      with_items:
        - unzip
      when: ansible_os_family == "RedHat" <span style="color: #008000;">&lt;---------------- a condition such that instruct the ansible <strong>pre_tasks</strong> should only suppose to be executed on a Fedora based distribution</span>
  roles:
   - { role: elastic_master_install }


- hosts: elastic_data
  remote_user: root
  become: true
  pre_tasks:
    - name: "Installing basic packages"
      action: yum
              name={{ item }}
              state=installed
      with_items:
        - unzip
      when: ansible_os_family == "RedHat"
  roles:
   - { role: elastic_data_install }</pre>
<p>&nbsp;</p>
<h4><strong>Default File</strong></h4>
<p>As we already covered this variables will be used when files which are in Jinga format are being copied under the Template DIrectory.</p>
<pre># vim roles/elastic_master_install/defaults</pre>
<pre>cluster_name: clusterName
node_master_true: "true"
node_data_true: "false"
node_ingest_true: "false"
path_to_log: /data/elk/logs
path_to_data: /data/elk/data
http_port: 9200
transport_tcp_port: 9300
discovery_zen_ping_unicast_hosts: '["172.17.0.10"]'

### - jvm config
init_heap_size: "-Xms8g"
max_heap_size: "-Xmx8g"
</pre>
<p>&nbsp;</p>
<p>&nbsp;</p>
<h4><strong>Template file Example</strong></h4>
<p>This is how a basic elasticsearch.yaml looks like in Jinja fromat.</p>
<pre># vim roles/elastic_master_install/templates/elasticsearch.yml.j2</pre>
<pre>cluster.name: {{cluster_name}}
node.name: {{inventory_hostname}}
node.master: {{node_master_true}}
node.data: {{node_data_true}}
node.ingest: {{node_ingest_true}}
path.data: {{path_to_data}}
path.logs: {{path_to_log}}
network.host: {{ansible_host}}
</pre>
<p>&nbsp;</p>
<h4><strong>Task File</strong></h4>
<p>This is where we can define all the task that are part of the respective role, in this case task that needed to execute setting up Elasticsearch</p>
<pre># vim roles/elastic_master_install/tasks/main.yml</pre>
<pre>- name: Creating elk user...
  user:
    name: elk
    comment: "elk User"
    createopt: yes
    opt: /opt/elk/
    uid: 1999
    shell: /bin/bash
  become: true

- name: Copying &amp; untar ElasticSearch5.5..
  unarchive: 
    src: /root/Ansible/ElasticSearch5/roles/elastic_master_install/Files/elasticsearch-5.5.0.tar.gz
    dest: /opt/elk/
    owner: elk
    group: elk
    mode: 0755
  become: true

- name: Creating necessary directories..
  file:
    path: /data/elk/{{ item }}
    state: directory
    owner: elk
    group: elk
    mode: 0775
    recurse: yes
  with_items:
     - [data, logs, run]
  become: true

- name: Copying the main config file...
  template: src=elasticsearch.yml.j2 dest={{elasticsearch_config_dir}}/elasticsearch.yml owner=elk group=elk mode=0644 
  become: true
</pre>
<p>&nbsp;</p>
<p>Please note that I have only added files for Role &#8220;<em>elastic_master_install</em>&#8221; =&gt; <strong>Task</strong>/<strong>Template</strong>/<strong>Default</strong>. However, as in the prod.yaml there is another role called &#8220;<em>elastic_data_install</em>&#8221; which you also need to work on as did in above last three steps.</p>
<p>When you have the Directory Structure ready, you can initiate the Ansible by;</p>
<pre># ansible-playbook -i inventory prod.yaml</pre>
<p>&nbsp;</p>
<p><em><strong>&#8220;I hope this has been informative for you&#8221;</strong></em></p>
<p>The post <a rel="nofollow" href="https://www.osradar.com/install-elasticsearch-via-ansible/">Install ElasticSearch via Ansible</a> appeared first on <a rel="nofollow" href="https://www.osradar.com">Linux  Windows and android  Tutorials</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.osradar.com/install-elasticsearch-via-ansible/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Getting Understand Ansible Structure</title>
		<link>https://www.osradar.com/getting-understand-ansible-structure/</link>
					<comments>https://www.osradar.com/getting-understand-ansible-structure/#respond</comments>
		
		<dc:creator><![CDATA[osradar_editor]]></dc:creator>
		<pubDate>Mon, 04 Mar 2019 12:37:52 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[ansible]]></category>
		<guid isPermaLink="false">https://www.osradar.com/?p=11197</guid>

					<description><![CDATA[<p>Getting understand about the directory structure that needed to setup is really important as it helps to ease of things that we can work upon on Ansible. However, different people might follow bit of differ in the structure what we would follow here, but its about each once preference. End of the day, Structure is [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://www.osradar.com/getting-understand-ansible-structure/">Getting Understand Ansible Structure</a> appeared first on <a rel="nofollow" href="https://www.osradar.com">Linux  Windows and android  Tutorials</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Getting understand about the directory structure that needed to setup is really important as it helps to ease of things that we can work upon on Ansible. However, different people might follow bit of differ in the structure what we would follow here, but its about each once preference. End of the day, Structure is about to help us getting thing done in Ansible easy.</p>
<p><a href="https://www.osradar.com/how-to-install-ansible-on-ubuntu-18-04/">How to install Ansible</a></p>
<p><img loading="lazy" class="alignnone wp-image-11220 size-full" src="https://www.osradar.com/wp-content/uploads/2019/02/Ansible-structure-1-e1551369097715.png" alt="" width="2066" height="1054" srcset="https://www.osradar.com/wp-content/uploads/2019/02/Ansible-structure-1-e1551369097715.png 2066w, https://www.osradar.com/wp-content/uploads/2019/02/Ansible-structure-1-e1551369097715-300x153.png 300w, https://www.osradar.com/wp-content/uploads/2019/02/Ansible-structure-1-e1551369097715-768x392.png 768w, https://www.osradar.com/wp-content/uploads/2019/02/Ansible-structure-1-e1551369097715-1024x522.png 1024w, https://www.osradar.com/wp-content/uploads/2019/02/Ansible-structure-1-e1551369097715-696x355.png 696w, https://www.osradar.com/wp-content/uploads/2019/02/Ansible-structure-1-e1551369097715-1068x545.png 1068w, https://www.osradar.com/wp-content/uploads/2019/02/Ansible-structure-1-e1551369097715-823x420.png 823w, https://www.osradar.com/wp-content/uploads/2019/02/Ansible-structure-1-e1551369097715-1920x980.png 1920w" sizes="(max-width: 2066px) 100vw, 2066px" /></p>
<h4><strong>Project Root Directory:</strong></h4>
<p>This is the top level hierarchy where everything in your ansible work should go upon. It can have any name.</p>
<h4><strong>Inventory File:</strong></h4>
<p>This file should be listed each of the server nodes that the Ansible should work on. Note that prior ssh KEY being copy is mandatory.</p>
<p><img loading="lazy" class="alignnone size-full wp-image-11241" src="https://www.osradar.com/wp-content/uploads/2019/03/inventory.png" alt="" width="475" height="225" srcset="https://www.osradar.com/wp-content/uploads/2019/03/inventory.png 475w, https://www.osradar.com/wp-content/uploads/2019/03/inventory-300x142.png 300w" sizes="(max-width: 475px) 100vw, 475px" /></p>
<ul>
<li>[<strong>web_hosts</strong>] whatever inside this square brackets is a just alias that represent group of hosts. And that group of hosts will be invoke by the &#8220;<em><strong>Prod.yml</strong></em>&#8221; file and once it does, it send the instruction that are listed in this same yaml file. These instruction should be kind of basics, such as system updates, hostname change, etc..</li>
<li>hostnames are just  yet another aliases and they don&#8217;t require any DNS entries nor hostname configured inside OS level. But they come handy when we want to call them later rather mentioning their respective IP addresses.</li>
</ul>
<h4><strong>Prod.yml:</strong></h4>
<p><img loading="lazy" class="alignnone size-full wp-image-11239" src="https://www.osradar.com/wp-content/uploads/2019/03/prodyaml.png" alt="" width="485" height="304" srcset="https://www.osradar.com/wp-content/uploads/2019/03/prodyaml.png 485w, https://www.osradar.com/wp-content/uploads/2019/03/prodyaml-300x188.png 300w" sizes="(max-width: 485px) 100vw, 485px" /></p>
<p>This is what holding the entire work-flow that suppose to be executed by Ansible. It calls aliases listed in &#8220;Inventory FIle&#8221;<strong> [ &#8211; hosts: node_master ]</strong> and by doing so we have the option to select order in which the hosts that needed to configured. Then it&#8217;s best practice to call the individual Roles here with their respective directory aliases so then each specific roles&#8217; set of instruction will be call upon within their sub-directories rather than listed inside this main Prod.yaml file. But, as I already explained above, yet you can call some basic instruction task here under the <strong>[ KEY &#8220;<em>pre_tasks</em>&#8221; ]</strong>. When I say basic tasks, its like general things like update system via <strong>`yum update` </strong>or change hostname and etc..</p>
<h4><strong>Roles Directory:</strong></h4>
<p>This is where you can have Role specific sub-directories and the idea is that each of them then represent it&#8217;s own instruction set. For example, think about you want to install <strong>apahe</strong> and <strong>mysql</strong> via ansible. Then, you can have one directory, lets say &#8220;apache_role&#8221;, whose having what needed to be done on apache and on the other hand other sub-directory, called &#8220;mysql_role&#8221;, will have mysql own specific instruction. As we already covered in<em><strong> &#8220;Prod.yml&#8221;</strong></em> , we can call these sub-directories by their directory alias  when needed.</p>
<h4><strong>Tasks Directories:</strong></h4>
<p>Inside each Role Directory you can have another set of sub-directories each calling task specific instruction. In very basic Task hold a single YAML file which calls every single instruction that needed to be executed on this role, for example, install apache, configuration changes, service restarts, etc..</p>
<h4><strong>Default Directory:</strong></h4>
<p>This is where role specific environment variable are listed within a YAML file.</p>
<h4><strong>Template Directory:</strong></h4>
<p>This is what holds the sample configuration files and they suppose to be in &#8220;Jinja&#8221; format which actually holds configuration data in a variable manner so then when these configuration files are instructed to being copied, those variable are then get replaced by its own parameter that are found in the Default Directory YAML file.</p>
<p>&nbsp;</p>
<p>OK, Now you should have a clear idea on defining your Ansible structure, else you should try to go through couple of times on each points what I explained above until yourself familiar the concept. In my next post, I will be taking real-world scenario on where we could apply Ansible automation.</p>
<p><em><strong>&#8220;I hope this has been informative for you&#8221;</strong></em></p>
<p>The post <a rel="nofollow" href="https://www.osradar.com/getting-understand-ansible-structure/">Getting Understand Ansible Structure</a> appeared first on <a rel="nofollow" href="https://www.osradar.com">Linux  Windows and android  Tutorials</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.osradar.com/getting-understand-ansible-structure/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to install Ansible on Ubuntu 18.04?</title>
		<link>https://www.osradar.com/how-to-install-ansible-on-ubuntu-18-04/</link>
					<comments>https://www.osradar.com/how-to-install-ansible-on-ubuntu-18-04/#respond</comments>
		
		<dc:creator><![CDATA[Mel]]></dc:creator>
		<pubDate>Thu, 12 Jul 2018 13:17:50 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Unix]]></category>
		<category><![CDATA[ansible]]></category>
		<category><![CDATA[Automatization]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[ubuntu]]></category>
		<guid isPermaLink="false">https://www.osradar.com/?p=4657</guid>

					<description><![CDATA[<p>Ansible is a free software platform to configure and manage computers automatically. In other words, it allows you to automate all the tedious and repetitive tasks that system administrators encounter. Ansible is an open source project implemented in Python and has a modular architecture that can handle virtually any operating system, cloud environment and system [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://www.osradar.com/how-to-install-ansible-on-ubuntu-18-04/">How to install Ansible on Ubuntu 18.04?</a> appeared first on <a rel="nofollow" href="https://www.osradar.com">Linux  Windows and android  Tutorials</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><strong>Ansible</strong> is a free software platform to configure and manage computers automatically. In other words, <strong>it allows you to automate all the tedious and repetitive tasks</strong> that system administrators encounter.</p>
<p><strong>Ansible</strong> is an open source project implemented in Python and has a modular architecture that can handle virtually any operating system, cloud environment and system management tool or framework.</p>
<p>It is included as part of the Linux Fedora distribution, inherited from Red Hat Inc. and is also available for Red Hat Enterprise Linux, CentOS and Scientific Linux through the Enterprise Linux Extras Packages (EPELs) as well as other operating systems, for example, Ubuntu and Debian.</p>
<h2>Advantages and features</h2>
<p>One of Ansible&#8217;s thanks to the competition is that you d<strong>on&#8217;t have to install Agents or Servers</strong>. Just install ansible on your machine and you&#8217;re ready to go.</p>
<p>It does not require cumbersome and complicated configurations, its documentation is quite extensive and its configuration files explicit.</p>
<p>Another of its advantages is that it has an API and allows the development of plugins to extend its functionality.</p>
<h2>Installing Ansible</h2>
<p>Installing ansible is relatively easy as it is packaged for many of the most popular GNU/LINUX distributions. In the case of ubuntu 18.04 we have a PPA repository at our disposal that is ready to make the work even easier.</p>
<p>First of all we log in as a super user. Write in a terminal:</p>
<p><strong>               sudo -i</strong></p>
<p>Next we proceed to update the system, something always recommended to obtain even more security in our server:</p>
<figure id="attachment_4664" aria-describedby="caption-attachment-4664" style="width: 1368px" class="wp-caption alignnone"><img loading="lazy" class="size-full wp-image-4664" src="https://www.osradar.com/wp-content/uploads/2018/07/1-1.png" alt="1.- Upgrading the system" width="1368" height="710" srcset="https://www.osradar.com/wp-content/uploads/2018/07/1-1.png 1368w, https://www.osradar.com/wp-content/uploads/2018/07/1-1-300x156.png 300w, https://www.osradar.com/wp-content/uploads/2018/07/1-1-768x399.png 768w, https://www.osradar.com/wp-content/uploads/2018/07/1-1-1024x531.png 1024w, https://www.osradar.com/wp-content/uploads/2018/07/1-1-696x361.png 696w, https://www.osradar.com/wp-content/uploads/2018/07/1-1-1068x554.png 1068w, https://www.osradar.com/wp-content/uploads/2018/07/1-1-809x420.png 809w" sizes="(max-width: 1368px) 100vw, 1368px" /><figcaption id="caption-attachment-4664" class="wp-caption-text">1.- Upgrading the system</figcaption></figure>
<p>The next step is to install the package software-properties-common:</p>
<p><strong>                apt install software-properties-common</strong></p>
<figure id="attachment_4667" aria-describedby="caption-attachment-4667" style="width: 1368px" class="wp-caption alignnone"><img loading="lazy" class="size-full wp-image-4667" src="https://www.osradar.com/wp-content/uploads/2018/07/2-1.png" alt="2.- Installing required packages" width="1368" height="710" srcset="https://www.osradar.com/wp-content/uploads/2018/07/2-1.png 1368w, https://www.osradar.com/wp-content/uploads/2018/07/2-1-300x156.png 300w, https://www.osradar.com/wp-content/uploads/2018/07/2-1-768x399.png 768w, https://www.osradar.com/wp-content/uploads/2018/07/2-1-1024x531.png 1024w, https://www.osradar.com/wp-content/uploads/2018/07/2-1-696x361.png 696w, https://www.osradar.com/wp-content/uploads/2018/07/2-1-1068x554.png 1068w, https://www.osradar.com/wp-content/uploads/2018/07/2-1-809x420.png 809w" sizes="(max-width: 1368px) 100vw, 1368px" /><figcaption id="caption-attachment-4667" class="wp-caption-text">2.- Installing required packages</figcaption></figure>
<p>At the end of the installation, we have to add the PPA repository with the latest available version of Ansible.</p>
<p><strong>               apt-add-repository ppa:ansible/ansible</strong></p>
<figure id="attachment_4666" aria-describedby="caption-attachment-4666" style="width: 1368px" class="wp-caption alignnone"><img loading="lazy" class="size-full wp-image-4666" src="https://www.osradar.com/wp-content/uploads/2018/07/3-1.png" alt="apt-add-repository ppa:ansible/ansible" width="1368" height="710" srcset="https://www.osradar.com/wp-content/uploads/2018/07/3-1.png 1368w, https://www.osradar.com/wp-content/uploads/2018/07/3-1-300x156.png 300w, https://www.osradar.com/wp-content/uploads/2018/07/3-1-768x399.png 768w, https://www.osradar.com/wp-content/uploads/2018/07/3-1-1024x531.png 1024w, https://www.osradar.com/wp-content/uploads/2018/07/3-1-696x361.png 696w, https://www.osradar.com/wp-content/uploads/2018/07/3-1-1068x554.png 1068w, https://www.osradar.com/wp-content/uploads/2018/07/3-1-809x420.png 809w" sizes="(max-width: 1368px) 100vw, 1368px" /><figcaption id="caption-attachment-4666" class="wp-caption-text">3.- Adding PPA</figcaption></figure>
<p>The next thing to do is to install the package that contains the program:</p>
<p><strong>              apt install ansible</strong></p>
<figure id="attachment_4670" aria-describedby="caption-attachment-4670" style="width: 1368px" class="wp-caption alignnone"><img loading="lazy" class="size-full wp-image-4670" src="https://www.osradar.com/wp-content/uploads/2018/07/Screenshot-from-2018-07-05-16-57-23.png" alt="4.- Installing the main package" width="1368" height="710" srcset="https://www.osradar.com/wp-content/uploads/2018/07/Screenshot-from-2018-07-05-16-57-23.png 1368w, https://www.osradar.com/wp-content/uploads/2018/07/Screenshot-from-2018-07-05-16-57-23-300x156.png 300w, https://www.osradar.com/wp-content/uploads/2018/07/Screenshot-from-2018-07-05-16-57-23-768x399.png 768w, https://www.osradar.com/wp-content/uploads/2018/07/Screenshot-from-2018-07-05-16-57-23-1024x531.png 1024w, https://www.osradar.com/wp-content/uploads/2018/07/Screenshot-from-2018-07-05-16-57-23-696x361.png 696w, https://www.osradar.com/wp-content/uploads/2018/07/Screenshot-from-2018-07-05-16-57-23-1068x554.png 1068w, https://www.osradar.com/wp-content/uploads/2018/07/Screenshot-from-2018-07-05-16-57-23-809x420.png 809w" sizes="(max-width: 1368px) 100vw, 1368px" /><figcaption id="caption-attachment-4670" class="wp-caption-text">4.- Installing the main package</figcaption></figure>
<p>And now, that&#8217;s it.</p>
<h2><strong>Getting Started with Ansible</strong></h2>
<p>It is easy to take the first steps with Ansible, to demonstrate its use, we must have at least two machines, one that will be the main one and the other that will act as a node.</p>
<p>When Ansible is installed in one of the machines, we transform it into the main one. Remembering that there is no server as such, nor agents to configure.</p>
<p>The main machine cannot have Windows as its operating system, and must have python 2.6 or higher for effective installation.</p>
<p>For this tutorial the main machine has these features:</p>
<ul>
<li>RAM Memory: 512mb</li>
<li>OS: Ubuntu server 18.04</li>
<li>IP Address: 192.168.250.5</li>
<li>Hard Drive: 20gb</li>
<li>Hostname: osradar1</li>
</ul>
<p>And the second machine:</p>
<ul>
<li>RAM Memory: 512mb</li>
<li>OS: Ubuntu server 18.04</li>
<li>IP Address: 192.168.250.6</li>
<li>Hard Drive: 20gb</li>
<li>Hostname: osradar2</li>
</ul>
<p>Once we know this, we proceed to start the configuration process in order to execute the first command.</p>
<p>First of all we must create or modify the file /etc/ansible/hosts which is where the computers of our network are defined as well as the possibility of attaching them to groups. In this file we must place the address of the other node. To edit it, proceed to execute:</p>
<p><strong>              nano /etc/ansible/hosts</strong></p>
<figure id="attachment_4675" aria-describedby="caption-attachment-4675" style="width: 1368px" class="wp-caption alignnone"><img loading="lazy" class="size-full wp-image-4675" src="https://www.osradar.com/wp-content/uploads/2018/07/5-1.png" alt="5.-Editing the file hosts" width="1368" height="710" srcset="https://www.osradar.com/wp-content/uploads/2018/07/5-1.png 1368w, https://www.osradar.com/wp-content/uploads/2018/07/5-1-300x156.png 300w, https://www.osradar.com/wp-content/uploads/2018/07/5-1-768x399.png 768w, https://www.osradar.com/wp-content/uploads/2018/07/5-1-1024x531.png 1024w, https://www.osradar.com/wp-content/uploads/2018/07/5-1-696x361.png 696w, https://www.osradar.com/wp-content/uploads/2018/07/5-1-1068x554.png 1068w, https://www.osradar.com/wp-content/uploads/2018/07/5-1-809x420.png 809w" sizes="(max-width: 1368px) 100vw, 1368px" /><figcaption id="caption-attachment-4675" class="wp-caption-text">5.-Editing the file hosts</figcaption></figure>
<p>Now we must make sure that we have SSH key authentication with the node. Write in a terminal:</p>
<p><strong>              ssh-keygen</strong></p>
<figure id="attachment_4676" aria-describedby="caption-attachment-4676" style="width: 1368px" class="wp-caption alignnone"><img loading="lazy" class="size-full wp-image-4676" src="https://www.osradar.com/wp-content/uploads/2018/07/6-1.png" alt="6.- SSH-Keygen" width="1368" height="710" srcset="https://www.osradar.com/wp-content/uploads/2018/07/6-1.png 1368w, https://www.osradar.com/wp-content/uploads/2018/07/6-1-300x156.png 300w, https://www.osradar.com/wp-content/uploads/2018/07/6-1-768x399.png 768w, https://www.osradar.com/wp-content/uploads/2018/07/6-1-1024x531.png 1024w, https://www.osradar.com/wp-content/uploads/2018/07/6-1-696x361.png 696w, https://www.osradar.com/wp-content/uploads/2018/07/6-1-1068x554.png 1068w, https://www.osradar.com/wp-content/uploads/2018/07/6-1-809x420.png 809w" sizes="(max-width: 1368px) 100vw, 1368px" /><figcaption id="caption-attachment-4676" class="wp-caption-text">6.- SSH-Keygen</figcaption></figure>
<p>Next, copy the public key to the node.</p>
<p><strong>               ssh-copy-id -i ~/.ssh/id_rsa.pub angelo@192.168.250.6</strong></p>
<figure id="attachment_4683" aria-describedby="caption-attachment-4683" style="width: 1368px" class="wp-caption alignnone"><img loading="lazy" class="size-full wp-image-4683" src="https://www.osradar.com/wp-content/uploads/2018/07/7-1.png" alt="7.- Copying ssh key" width="1368" height="710" srcset="https://www.osradar.com/wp-content/uploads/2018/07/7-1.png 1368w, https://www.osradar.com/wp-content/uploads/2018/07/7-1-300x156.png 300w, https://www.osradar.com/wp-content/uploads/2018/07/7-1-768x399.png 768w, https://www.osradar.com/wp-content/uploads/2018/07/7-1-1024x531.png 1024w, https://www.osradar.com/wp-content/uploads/2018/07/7-1-696x361.png 696w, https://www.osradar.com/wp-content/uploads/2018/07/7-1-1068x554.png 1068w, https://www.osradar.com/wp-content/uploads/2018/07/7-1-809x420.png 809w" sizes="(max-width: 1368px) 100vw, 1368px" /><figcaption id="caption-attachment-4683" class="wp-caption-text">7.- Copying ssh key</figcaption></figure>
<p>Now we can try to perform our first command from the main machine to the node to test the installation.</p>
<p><strong>          ansible all -m ping -u angelo</strong></p>
<figure id="attachment_4685" aria-describedby="caption-attachment-4685" style="width: 1368px" class="wp-caption alignnone"><img loading="lazy" class="size-full wp-image-4685" src="https://www.osradar.com/wp-content/uploads/2018/07/8.png" alt="8.- First command success" width="1368" height="710" srcset="https://www.osradar.com/wp-content/uploads/2018/07/8.png 1368w, https://www.osradar.com/wp-content/uploads/2018/07/8-300x156.png 300w, https://www.osradar.com/wp-content/uploads/2018/07/8-768x399.png 768w, https://www.osradar.com/wp-content/uploads/2018/07/8-1024x531.png 1024w, https://www.osradar.com/wp-content/uploads/2018/07/8-696x361.png 696w, https://www.osradar.com/wp-content/uploads/2018/07/8-1068x554.png 1068w, https://www.osradar.com/wp-content/uploads/2018/07/8-809x420.png 809w" sizes="(max-width: 1368px) 100vw, 1368px" /><figcaption id="caption-attachment-4685" class="wp-caption-text">8.- First command success</figcaption></figure>
<p>We can also log in with the root user. Important if we want to execute tasks that require super user.</p>
<p><strong>               ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.250.6</strong></p>
<p>Or any user.</p>
<h2>Working with Playbooks</h2>
<p>Playbooks are configuration files that allow us to deploy various tasks to different nodes, describing the steps to follow. Its writing is based on YAML and its format is.yml</p>
<p>For this tutorial a playbook will be made to install LAMP on the other node.</p>
<p>We create a playbook called lamp.yml and copy the following text into it:</p>
<p><strong>                 nano lamp.yml</strong></p>
<p><strong>&#8212;</strong><br />
<strong>&#8211; hosts: all</strong><br />
<strong>user: root</strong></p>
<p><strong>tasks:</strong></p>
<p><strong>-name: General | Installing packages</strong><br />
<strong>action: apt pkg={{ item }} state=installed</strong><br />
<strong>with_items:</strong><br />
<strong>&#8211; php7.2</strong><br />
<strong>&#8211; apache2</strong><br />
<strong>&#8211; mariadb-server</strong><br />
<strong>&#8211; mariadb-client</strong><br />
<strong>&#8211; php7.2-mysql</strong><br />
<strong>&#8211; php-apcu</strong><br />
<strong>&#8211; php7.2-xmlrpc</strong><br />
<strong>&#8211; php7.2-soap</strong><br />
<strong>&#8211; php7.2-gd</strong><br />
<strong>&#8211; unzip</strong><br />
<strong>&#8211; python-mysqldb</strong></p>
<p><strong>&#8211; name: Apache2 |Enabling modules</strong><br />
<strong>action: command a2enmod rewrite vhost_alias</strong></p>
<p><strong>&#8211; name: Restart Apache</strong><br />
<strong>action: service name=apache2 state=restarted</strong></p>
<figure id="attachment_4689" aria-describedby="caption-attachment-4689" style="width: 1368px" class="wp-caption alignnone"><img loading="lazy" class="size-full wp-image-4689" src="https://www.osradar.com/wp-content/uploads/2018/07/9-2.png" alt="9.- Creating the playbook" width="1368" height="710" srcset="https://www.osradar.com/wp-content/uploads/2018/07/9-2.png 1368w, https://www.osradar.com/wp-content/uploads/2018/07/9-2-300x156.png 300w, https://www.osradar.com/wp-content/uploads/2018/07/9-2-768x399.png 768w, https://www.osradar.com/wp-content/uploads/2018/07/9-2-1024x531.png 1024w, https://www.osradar.com/wp-content/uploads/2018/07/9-2-696x361.png 696w, https://www.osradar.com/wp-content/uploads/2018/07/9-2-1068x554.png 1068w, https://www.osradar.com/wp-content/uploads/2018/07/9-2-809x420.png 809w" sizes="(max-width: 1368px) 100vw, 1368px" /><figcaption id="caption-attachment-4689" class="wp-caption-text">9.- Creating the playbook</figcaption></figure>
<p>Some components of the file are explained:</p>
<ul>
<li>hosts: to whom the playbook is addressed. It can be one, or a group, or in this case all.</li>
<li>user: user that will execute it. As we know to install lamp we must be root user.</li>
<li>tasks: are the instructions to be executed on the node machine. It may be one or more as in this case. The first one installs the packages, the second one enables the apache modules and the third one restarts the services.</li>
</ul>
<p>Remember that the /etc/ansible/hosts file can be used to create groups of nodes to speed up the selection process even more.</p>
<p>We proceed to run the playbook with the following command:</p>
<p><strong>             ansible-playbook lamp.yml</strong></p>
<figure id="attachment_4690" aria-describedby="caption-attachment-4690" style="width: 1368px" class="wp-caption alignnone"><img loading="lazy" class="size-full wp-image-4690" src="https://www.osradar.com/wp-content/uploads/2018/07/10.png" alt="10.- Running playbook" width="1368" height="710" srcset="https://www.osradar.com/wp-content/uploads/2018/07/10.png 1368w, https://www.osradar.com/wp-content/uploads/2018/07/10-300x156.png 300w, https://www.osradar.com/wp-content/uploads/2018/07/10-768x399.png 768w, https://www.osradar.com/wp-content/uploads/2018/07/10-1024x531.png 1024w, https://www.osradar.com/wp-content/uploads/2018/07/10-696x361.png 696w, https://www.osradar.com/wp-content/uploads/2018/07/10-1068x554.png 1068w, https://www.osradar.com/wp-content/uploads/2018/07/10-809x420.png 809w" sizes="(max-width: 1368px) 100vw, 1368px" /><figcaption id="caption-attachment-4690" class="wp-caption-text">10.- Running playbook</figcaption></figure>
<figure id="attachment_4691" aria-describedby="caption-attachment-4691" style="width: 1368px" class="wp-caption alignnone"><img loading="lazy" class="size-full wp-image-4691" src="https://www.osradar.com/wp-content/uploads/2018/07/11.png" alt="11.- Running the playbook" width="1368" height="710" srcset="https://www.osradar.com/wp-content/uploads/2018/07/11.png 1368w, https://www.osradar.com/wp-content/uploads/2018/07/11-300x156.png 300w, https://www.osradar.com/wp-content/uploads/2018/07/11-768x399.png 768w, https://www.osradar.com/wp-content/uploads/2018/07/11-1024x531.png 1024w, https://www.osradar.com/wp-content/uploads/2018/07/11-696x361.png 696w, https://www.osradar.com/wp-content/uploads/2018/07/11-1068x554.png 1068w, https://www.osradar.com/wp-content/uploads/2018/07/11-809x420.png 809w" sizes="(max-width: 1368px) 100vw, 1368px" /><figcaption id="caption-attachment-4691" class="wp-caption-text">11.- Running the playbook</figcaption></figure>
<p>As we can see, the 4 tasks were executed correctly.</p>
<p>This is just an outline of the great potential of Ansible that comes to give an open and simple solution to the world of process automation and tasks within any network.</p>
<p>Please share this article through your social networks.</p>
<p>The post <a rel="nofollow" href="https://www.osradar.com/how-to-install-ansible-on-ubuntu-18-04/">How to install Ansible on Ubuntu 18.04?</a> appeared first on <a rel="nofollow" href="https://www.osradar.com">Linux  Windows and android  Tutorials</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.osradar.com/how-to-install-ansible-on-ubuntu-18-04/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
