<?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>create Role in Chef Archives - scmGalaxy</title>
	<atom:link href="https://www.scmgalaxy.com/tutorials/tag/create-role-in-chef/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.scmgalaxy.com/tutorials/tag/create-role-in-chef/</link>
	<description>A Platform for Software Engineers</description>
	<lastBuildDate>Sat, 27 Feb 2021 09:50:34 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1</generator>
	<item>
		<title>How to Implement Chef roles using Chef server ?</title>
		<link>https://www.scmgalaxy.com/tutorials/implement-chef-roles-using-chef-server/</link>
					<comments>https://www.scmgalaxy.com/tutorials/implement-chef-roles-using-chef-server/#respond</comments>
		
		<dc:creator><![CDATA[scmgalaxy K]]></dc:creator>
		<pubDate>Thu, 24 Sep 2015 14:57:08 +0000</pubDate>
				<category><![CDATA[Chef]]></category>
		<category><![CDATA[Chef Guide]]></category>
		<category><![CDATA[Chef roles]]></category>
		<category><![CDATA[Chef server]]></category>
		<category><![CDATA[Chef Tutorial]]></category>
		<category><![CDATA[create Role in Chef]]></category>
		<category><![CDATA[Guide]]></category>
		<category><![CDATA[How]]></category>
		<category><![CDATA[How to Implement Chef roles]]></category>
		<category><![CDATA[Implement]]></category>
		<category><![CDATA[Process]]></category>
		<category><![CDATA[Roles in Chef]]></category>
		<category><![CDATA[Steps]]></category>
		<category><![CDATA[Tutorials]]></category>
		<guid isPermaLink="false">http://www.scmgalaxy.com/tutorials/2015/09/24/implement-chef-roles-using-chef-server/</guid>

					<description><![CDATA[<p>What is Role? A role is a way to define certain patterns and processes that exist across nodes in an [&#8230;]</p>
<p>The post <a href="https://www.scmgalaxy.com/tutorials/implement-chef-roles-using-chef-server/">How to Implement Chef roles using Chef server ?</a> appeared first on <a href="https://www.scmgalaxy.com/tutorials">scmGalaxy</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><img fetchpriority="high" decoding="async" class="size-full wp-image-3345 aligncenter" src="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2015/09/chef-roles-using-chef-serve.png" alt="implement-chef-roles-using-chef-server" width="600" height="400" srcset="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2015/09/chef-roles-using-chef-serve.png 600w, https://www.scmgalaxy.com/tutorials/wp-content/uploads/2015/09/chef-roles-using-chef-serve-300x200.png 300w" sizes="(max-width: 600px) 100vw, 600px" /></p>
<p><strong>What is Role?</strong></p>
<p>A role is a way to define certain patterns and processes that exist across nodes in an organization as belonging to a single job function. Each role consists of zero (or more) attributes and a run-list. Each node can have zero (or more) roles assigned to it. When a role is run against a node, the configuration details of that node are compared against the attributes of the role, and then the contents of that role’s run-list are applied to the node’s configuration details. When a chef-client runs, it merges its own attributes and run-lists with those contained within each assigned role.</p>
<p><strong>How to use Roles in Chef?</strong></p>
<ol>
<li>Create a Role and add the cookbooks into it.</li>
<li>Assign the role into each node or bootstrap new nodes using roles</li>
<li>The the run list</li>
</ol>
<p><strong>How to create Role?</strong></p>
<p><strong>Method 1: In Chef Server directly</strong></p>
<pre><code>&gt; knife role create client1</code></pre>
<p>&amp;</p>
<p>Add the run list e.g. &#8220;recipe[nginx]&#8221; under &#8220;run_list&#8221;</p>
<p>Save &amp; exit</p>
<p>The role will be created in Chef Server.</p>
<p>Example</p>
<pre><code>{ "name": "client1", "description": "", "json_class": "Chef::Role", "default_attributes": { }, "override_attributes": { }, "chef_type": "role", "run_list": [ "recipe[nginx]", "recipe[phpapp::web]" ], "env_run_lists": { } } </code></pre>
<p><strong>Let&#8217;s download the role from the Chef server so we have it locally in a Chef repository.</strong></p>
<p>&gt; knife role show client1 -d -Fjson &gt; roles/client1.json</p>
<p><strong>Now, Lets bootstrap the node using knife with roles</strong></p>
<pre>&gt; knife bootstrap --run-list "role[client1]" --sudo hostname</pre>
<p><strong>How to edit the roles in chef Server?</strong></p>
<pre>&gt; knife role edit client1</pre>
<p><strong>Method 2: In local repo under chef-repo folder</strong></p>
<pre><code>&gt; vi webserver.rb</code></pre>
<p>example &#8211;</p>
<pre><code>name "web_server" description "Role for web servers" run_list(   "role[base]",   "recipe{web_server]" ) </code></pre>
<p>&amp; Then upload to chef server using following commands.</p>
<pre>&gt; knife role from file path/to/role/file</pre>
<p><strong>How Assigning Roles to Nodes?</strong></p>
<pre><code>&gt; knife node list</code></pre>
<pre><code>&gt; knife node edit node_name</code></pre>
<p>This will bring up the node&#8217;s definition file, which will allow us to add a role to its run_list:</p>
<pre><code>{ "name": "client1", "chef_environment": "_default", "normal": { "tags": [  ] 	}, "run_list": [ 	"recipe[nginx]" ] } </code></pre>
<p>For instance, we can replace our recipe with our role in this file:</p>
<pre><code>{ "name": "client1", "chef_environment": "_default", "normal": { "tags": [ ] }, "run_list": [ "role[web_server]" ] } </code></pre>
<p><strong>How to bootstrap node using role?</strong></p>
<pre><code>&gt; knife bootstrap {{address}} --ssh-user {{user}} --ssh-password '{{password}}' --sudo --use-sudo-password --node-name node1 --run-list 'role[production]'</code></pre>
<pre><code>&gt; knife bootstrap --run-list "role[phpapp-web]" --sudo hostname</code></pre>
<p><strong>How to run roles against nodes?</strong></p>
<p>You can run chef-client on multiple nodes via knife ssh command like, To query for all nodes that have the webserver role and then use SSH to run the command sudo chef-client, enter:</p>
<pre><code>&gt; knife ssh "role:webserver" "sudo chef-client"</code></pre>
<p>To find the uptime of all of web servers running Ubuntu on the Amazon EC2 platform, enter:</p>
<pre><code>&gt; knife ssh "role:web" "uptime" -x ubuntu -a ec2.public_hostname</code></pre>
<p><strong>Reference</strong></p>
<p><a href="http://docs.chef.io/roles.html" target="_blank" rel="noopener">http://docs.chef.io/roles.html</a></p>
<p><a href="https://docs.chef.io/knife_ssh.html" target="_blank" rel="noopener">https://docs.chef.io/knife_ssh.html</a></p>
<p><a href="https://docs.chef.io/knife_role.html" target="_blank" rel="noopener">https://docs.chef.io/knife_role.html</a></p>
<p>The post <a href="https://www.scmgalaxy.com/tutorials/implement-chef-roles-using-chef-server/">How to Implement Chef roles using Chef server ?</a> appeared first on <a href="https://www.scmgalaxy.com/tutorials">scmGalaxy</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.scmgalaxy.com/tutorials/implement-chef-roles-using-chef-server/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
