What is the difference between two "state" option values, "present" and "installed", available in Ansible's yum module?

State as 'Present' and 'Installed' are used interchangeably. They both do the same thing i.e. it will ensure that a desired package in your case 'yum' is installed.

Whereas State as 'Latest' means in addition to installation, it will go ahead and update if it is not of the latest available version.

Whenever you are building your stack/app or working on production, it is always advisable to use 'Present' or 'Installed' state. This is because a software update, whether it’s your app’s deploy, or a dependency version bump, it has nothing to do with server configuration, and could really break your production.

You can read and understand more about it here.


They do the same thing, they are aliases to eachother, see this comment in the source code of the yum module:

# removed==absent, installed==present, these are accepted as aliases

And how they are used in the code:

if state in ['installed', 'present']:
    if disable_gpg_check:
        yum_basecmd.append('--nogpgcheck')
    res = install(module, pkgs, repoq, yum_basecmd, conf_file, en_repos, dis_repos)
elif state in ['removed', 'absent']:
    res = remove(module, pkgs, repoq, yum_basecmd, conf_file, en_repos, dis_repos)
elif state == 'latest':
    if disable_gpg_check:
        yum_basecmd.append('--nogpgcheck')
    res = latest(module, pkgs, repoq, yum_basecmd, conf_file, en_repos, dis_repos)
else:
    # should be caught by AnsibleModule argument_spec
    module.fail_json(msg="we should never get here unless this all"
            " failed", changed=False, results='', errors='unexpected state')

return res

https://github.com/ansible/ansible-modules-core/blob/devel/packaging/os/yum.py


In 2.x installed and removed are deprecated in favor of present and absent and no longer available after Ansible 2.9