24

I have the following task in my ansible playbook:

- name: Install EPEL repo.
  yum:
    name: "{{ epel_repo_url }}"
    state: present
    register: result
    until: '"failed" not in result'
    retries: 5
    delay: 10

Another value I can pass to state is "installed". What is the difference between the two? Some documentation available here: https://docs.ansible.com/ansible/latest/collections/ansible/builtin/yum_module.html

Ian Kemp
  • 28,293
  • 19
  • 112
  • 138
kevmo
  • 677
  • 1
  • 8
  • 20

3 Answers3

23

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.

Community
  • 1
  • 1
Yogesh D
  • 1,558
  • 14
  • 29
21

They do the same thing, i.e. they are aliases to each other, 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

venimus
  • 5,907
  • 2
  • 28
  • 38
Zlemini
  • 4,827
  • 2
  • 21
  • 23
4

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

venimus
  • 5,907
  • 2
  • 28
  • 38