Ansible uses "state" commands to manage the current state of resources on a system. There are several state commands available in Ansible, each with their own specific use case. Here are some common state commands in Ansible:
present
: This command is used to ensure that a resource exists on the system. For example, thefile
module in Ansible can be used with thestate=present
option to ensure that a specific file exists on the system.absent
: This command is used to ensure that a resource does not exist on the system. For example, thefile
module in Ansible can be used with thestate=absent
option to ensure that a specific file does not exist on the system.latest
: This command is used to ensure that a package is at the latest version available. For example, theapt
oryum
module in Ansible can be used with thestate=latest
option to ensure that a package is at the latest version available.enabled
: This command is used to ensure that a service is enabled and running. For example, theservice
module in Ansible can be used with thestate=enabled
option to ensure that a service is enabled and running.disabled
: This command is used to ensure that a service is disabled and not running. For example, theservice
module in Ansible can be used with thestate=disabled
option to ensure that a service is disabled and not running.started
: This command is used to ensure that a service is running. For example, theservice
module in Ansible can be used with thestate=started
option to ensure that a service is running.stopped
: This command is used to ensure that a service is stopped. For example, theservice
module in Ansible can be used with thestate=stopped
option to ensure that a service is stopped.reloaded
: This command is used to ensure that a service is reloaded. For example, theservice
module in Ansible can be used with thestate=reloaded
option to ensure that a service is reloaded.
These are some examples of the state commands available in Ansible. Each module has its own set of state commands, and the best way to learn more is to explore the Ansible documentation and try out different commands on your own.