Chef configuration manager : role creation
Roles are stored in a roles/ directory, usually within your Chef repository. If the directory doesn't exist, you can create it.
Create the Role File
Now, create a new role file. You can name the role file anything, but it’s common to use a name that describes the purpose of the role. For example, let's create a role called rolename.
touch roles/rolename.json
Edit the Role File
Open the rolename.json file and define the role. You'll include your recipe within the run_list section of the role definition.
Example rolename.json:
{ "name": "ROLE NAME", "description": "please write down something here, the tomorrow you will apreciate ;)", "run_list": [ "RECIPE 1", "RECIPE 2", "RECIPE 3" ], "default_attributes": {}, "override_attributes": {} }
- "name": The name of the role (e.g., rolename).
- "description": A short description of the role.
- "run_list": The list of recipes to be run. Here, you specify the recipes.
- "default_attributes" and "override_attributes": Optional sections where you can specify any attributes you want to set for the role.
Upload the Role to the Chef Server
Once you have created and saved the role file, you need to upload it to the Chef server using the knife command:
knife role from file roles/filename.json
Assign the Role to Your Nodes
Now that the role is created and uploaded, you can assign it to your nodes. To apply this role to a node, use the knife command to update the node's run list:
knife node run_list add NODE_NAME 'ROLE NAME'
Replace NODE_NAME with the actual name of the node you want to assign the role to.
Verify the Role Assignment
After applying the role, you can check if the role was successfully assigned to the node:
knife node show NODE_NAME
This will show you the details of the node, including the run list, which should now include the rolename role.