<?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>Introduction to Ansible Part 2 Archives -</title>
	<atom:link href="https://barriersec.com/category/linux-system-administration/introduction-to-ansible-part-2/feed/" rel="self" type="application/rss+xml" />
	<link>https://barriersec.com/category/linux-system-administration/introduction-to-ansible-part-2/</link>
	<description></description>
	<lastBuildDate>Mon, 14 Sep 2020 03:17:22 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.2.15</generator>

<image>
	<url>https://barriersec.com/wp-content/uploads/cropped-Monochrome-on-Transparent-32x32.png</url>
	<title>Introduction to Ansible Part 2 Archives -</title>
	<link>https://barriersec.com/category/linux-system-administration/introduction-to-ansible-part-2/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Introduction to Ansible : Part 2</title>
		<link>https://barriersec.com/2018/05/introduction-ansible-part-2/</link>
		
		<dc:creator><![CDATA[goutham madhwaraj]]></dc:creator>
		<pubDate>Thu, 24 May 2018 14:39:13 +0000</pubDate>
				<category><![CDATA[Introduction to Ansible Part 2]]></category>
		<category><![CDATA[Linux System Administration]]></category>
		<category><![CDATA[ansible]]></category>
		<category><![CDATA[ansible roles]]></category>
		<category><![CDATA[ansible2]]></category>
		<category><![CDATA[devops]]></category>
		<category><![CDATA[introduction to ansible]]></category>
		<guid isPermaLink="false">https://barriersec.com/?p=122</guid>

					<description><![CDATA[<p>In the previous post, we have described basic introduction of Ansible and its advantages . In this post lets build&#8230;</p>
<p>The post <a rel="nofollow" href="https://barriersec.com/2018/05/introduction-ansible-part-2/">Introduction to Ansible : Part 2</a> appeared first on <a rel="nofollow" href="https://barriersec.com"></a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>In the previous post, we have described basic introduction of Ansible and its advantages . In this post lets build a skeleton of the project hierarchy we follow . I will explain what each of these structure does and how it would benefit us.</p>
<p>Now before we dive  into the structure, Ansible uses YAML syntax inside its file called playbook(playbook means simply a file with set of tasks bundled together)  . If you are not comfortable with YAML syntax or if you want to skim it through please refer Ansible documentation. They have the best explanation out there. <strong>http://docs.ansible.com/ansible/latest/reference_appendices/YAMLSyntax.html</strong></p>
<p>now lets create our first basic ansible playbook.</p>
<p>Create a file named test.yml inside project folder,And paste this content.</p>
<p><strong>&#8212;</strong></p>
<p><strong>&#8211; hosts: remoteMachines</strong><br />
<strong>   tasks:</strong><br />
<strong>      &#8211; shell: echo &#8220;Hi!&#8221;</strong></p>
<p>Save the file . Before running this append this line to the host under remoteMachines in the hosts file we created in the previous tutorial.</p>
<p>like this ,</p>
<p style="text-align: center;"><strong>192.168.1.112 ansible_user=sshuser1</strong></p>
<p style="text-align: center;"><strong>192.168.1.113 ansible_user=sshuser2</strong></p>
<p>This line specifies this user is used to SSH into the remote Host.(by default it takes the current user of the ansible server machine)</p>
<p>&nbsp;</p>
<p>and to run the playbook we just created , use the following command :</p>
<p style="text-align: center;"><strong>&gt; ansible-playbook  test.yml</strong></p>
<p>this should return &#8220;Hi!&#8221; from both the remote machine output. And in the playbook we just created, <em><strong>hosts</strong> </em>specifies the hosts we want to run the tasks on. It has a single task which uses the shell module to run echo &#8220;Hi!&#8221; command.</p>
<p>Now lets assume a scenario in which we have many common tasks to be run on multiple playbooks. To address such scenario , we will follow a specific structure and in order to reuse tasks spread across multiple playbooks, we will use a feature called &#8220;roles&#8221;.</p>
<p>Inside the project folder create a folder called as &#8220;roles&#8221;. Inside roles directory we will create another folder this folder is the name of role we want to use.(ex: webserver).</p>
<p style="text-align: center;">Inside webserver folder we will create these folders and files respectively. hierarchy as follows,<br />
<strong>Roles &gt; Webserver &gt; defaults &gt; main.yml</strong></p>
<p style="text-align: center;"><strong>Roles &gt; Webserver &gt; tasks &gt; main.yml</strong></p>
<p style="text-align: center;"><strong>Roles &gt; Webserver &gt; handlers &gt; main.yml</strong></p>
<p style="text-align: center;"><strong>Roles &gt; Webserver &gt; templates </strong></p>
<p>Inside <strong>defaults</strong> folder ,we will find variables and default values in format of &#8220;name:value&#8221; pair inside main.yml file, these are extensively used in playbooks , templates and are placed to increase re usability.</p>
<p>Inside <strong>tasks</strong> folder , we will find set of tasks associated to the role inside main.yml file .</p>
<p>Inside <strong>handlers</strong> folder, we will find different handlers associated with the tasks. Handlers are similar to tasks . only difference is handlers are invoked only by another task.</p>
<p>Inside <strong>templates </strong>folder, we will find templates , which contains changing  values inside configuration files and these can be replaced by values inside defaults folder. They are processed by Jinja 2  template language.</p>
<p>Now in order to run this role, create a file named play.yml file inside project root folder. and place the following content and save</p>
<p><strong> &#8211; hosts: remoteMachines<br />
roles:<br />
&#8211; webserver</strong></p>
<p>As we can see there is a granularity of different type of functionalities and reusability of tasks can be achieved by the concept of roles.</p>
<p>In the next tutorial , we will look at how to use this hierarchy to write a functional role and execute this playbook. Thank you!</p>
<p>&nbsp;</p>
<p>The post <a rel="nofollow" href="https://barriersec.com/2018/05/introduction-ansible-part-2/">Introduction to Ansible : Part 2</a> appeared first on <a rel="nofollow" href="https://barriersec.com"></a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
