Using jobs in Tanzu Salt

You can use jobs in Tanzu Salt to simplify and automate common configuration management tasks and procedures that you or your team performs on a regular basis.

What are jobs in Tanzu Salt?

Jobs are used to run remote execution tasks or apply state files to the nodes (minions) that are managed by Tanzu Salt. Jobs are generally intended for system operations that need to be automated and run many times. You can create jobs to automate common tasks that you perform regularly as you provision, configure, deploy, monitor, and manage nodes in your system. You can also set up jobs to run on a regular schedule, such as jobs that regularly check for and prevent configuration drift.

You can save commonly repeated jobs and gradually build out a rich library of jobs for future reuse by your team. Using jobs for configuration management reduces the time your team spends manually installing, configuring, deploying, updating, and maintaining the nodes in your system.

Examples of common jobs

You could potentially run thousands of different kinds of jobs in Tanzu Salt depending on your intended goals and purpose. After you identify what task you want to accomplish or what problem you need to solve, you can search the available Salt modules to find which modules perform the function you need.

Jobs in Tanzu Salt usually incorporate one or more of the execution modules or state modules that have been developed by the Salt open source community. Salt execution modules are small programs containing Python code that can run on a Salt minion and perform a specific task. Salt state modules are similar to execution modules. Salt state modules are programs containing Python code that can be used inside Salt state files to manage the application of a state to a minion.

The following table shows some of the most commonly used execution and state modules:

Salt module Description
state.apply

A module that applies a state file to a minion. When the state file runs, it checks to see if the minion is in the current desired state. If the minion is not in the current desired state, it runs the commands and modules to put that minion into the desired state.

A highstate applies all states defined in the top file. See state.highstate for more information.

pkg.installed A state module (meaning it is used in state files) that checks whether the correct version of a package is installed. If it is not installed, it installs a package and ensures that it is the correct version of that package. See salt.states.pkg for more information about installing packages with certain operating systems.
file.managed A state module (meaning it is used in state files) that downloads a file from the Salt master and places that file on the targeted minions for later use. See salt.states.file for more information about managing files with Salt.
service.running A state module (meaning it is used in state files) that checks whether a service is running. If the service is not running, it starts the service. See salt.states.service for more information about starting or restarting services with Salt.

See the Salt module index for more a comprehensive list of Salt execution and state modules.

If Salt doesn’t have a module that you need, you can extend Salt by writing your own custom modules in Python. If desired, you can also submit that module upstream to the Salt Project. Officially sponsored by VMware, the Salt Project community includes more than 3,000 contributors working in IT and system administration roles. The Salt community extends Salt by creating a variety of execution and state modules to accomplish the most common tasks or solve the most important problems that system administrators face.

Overview of the jobs workflow

In general, a senior system administrator creates, configures, and saves job settings for later reuse. Then, the senior administrator can authorize a junior administrator to run this job on any nodes (targets) that the junior administrator is authorized to access. When creating a job, the senior administrator defines the job inputs, which refers to the specific job settings or variables the junior administrator can change at runtime.

For example, a senior system administrator might build a job that creates and deploys a virtual machine and installs a base set of applications or services on that machine. This job could be run every time a new virtual machine needs to be deployed to ensure the same set of applications and configurations are applied to every deployment. After creating this basic job, the senior system administrator could give access to a junior administrator run this job on the targets (nodes) they have permission to access. Using the role-based access controls (RBAC) in Tanzu Salt and guided by principle of least privilege, the senior administrator can determine which jobs a junior administrator can run and on which nodes (minions).

Creating and running jobs is a multi-step process that requires using a few different tools and workspaces in Tanzu Salt. The following diagram provides an overview of the overall job workflow:

Diagram explaining jobs workflow

Each step is described in the following articles:

  • How do I create targets?

    Defining targets for your jobs or operations helps to prevent operations from running on nodes that should not run that operation. You can organize your targets using grains, globs, lists, or compounds.

  • How do I create state files and pillar data?

    You can create or upload state files and pillar data in the Tanzu Salt File Server and Pillar workspaces. If you don’t want to use the File Server, Tanzu Salt also supports connecting to an external repository (such as a Git repository) where you can save your state files and pillar data.

  • How do I create jobs?

    As a systems administrator, you can create jobs in Tanzu Salt to run remote execution tasks, apply states, start Salt runners, and more. Jobs are generally intended for system operations that need to be automated and executed multiple times.

  • How do I run jobs and commands?

    After creating jobs and defining your targets in Tanzu Salt, you can then run the jobs against the desired targets. You can run a job or one-off command on an as-needed basis (ad-hoc) or you can schedule a job to run at a future date and time. You can also set jobs to run on a repeating schedule.

  • How do I review job status and job returns?

    After running a job in Tanzu Salt, you can check whether the job is complete and view the job return details in the Activity workspace. You can also use the Activity workspace to pause, stop, or skip jobs that are in progress or scheduled to run in the future. Alternatively, you can view job returns for a specific minion using the Targets workspace. You can also download or export job return data.

check-circle-line exclamation-circle-line close-line
Scroll to top icon