Setting Grain Roles and Using the sys Module

Hands-On Lab

 

Photo of Terrence Cox

Terrence Cox

Senior Vice President of Content

Length

01:00:00

Difficulty

Intermediate

Grains are an important concept when working with Salt and are often confused with Pillars. In this activity, the student will become proficient with extracting pertinent data from Grains associated with a Minion and using that as part of an Execution Module. By the end, the student will understand the importance of Grains and how to use them in your work with Salt environments.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Setting Grain Roles and Using the sys Module

Introduction

As the technical intern at the special-interest publication Apartment 42, you have been tasked with setting up the new Salt infrastructure for their website as they attempt to most their newsletter to the internet sphere. Your boss wants all minions to have a grain for its role in the infrastructure (saltmaster and web). Preform this task with the grain execution module; use the sys execution module to learn about which grains functions will perform this task. Set the role grains. When finished, confirm that the grain has been set by calling it.

You're first tasked with setting this up on a small test environment. Set the salt master so it has the saltmaster role and the minion1 minions so it uses the web role. Note you are also being graded on the use of the sys module.

Solution

  1. Begin by logging in to the Salt Master lab server using the credentials provided on the hands-on lab page:

    ssh cloud_user@PUBLIC_IP_ADDRESS

Set the Role Grains for the Salt Master and Minion1

  1. List the functions available for the grains execution module.

    sudo salt 'salt' sys.list_functions grains
  2. View the documentation for the set function.

    sudo salt 'salt' sys.doc grains.set
  3. Set the salt role to "saltmaster".

    sudo salt 'salt' grains.set 'role' saltmaster
  4. Set the minion1 role to "web".

    sudo salt 'minion1' grains.set 'role' web

Verify the Role Grains for the Salt Master and Minion1

  1. Once again review the functions available for the grains execution module.

    sudo salt 'salt' sys.list_functions grains
  2. View the documentation for multiple functions that might be the desired function.

    sudo salt 'salt' sys.doc grains.fetch grains.get grains.item grains.ls
  3. Verify the role for salt.

    sudo salt 'salt' grains.fetch role
  4. Verify the role for minion1.

    sudo salt 'minion1' grains.get role

Conclusion

Congratulations — you've completed this hands-on lab!