Ansible的yum模块中有两个"状态"选项值"present"和"installed"有什么区别?

kev*_*vmo 17 centos yum ansible epel

我的ansible剧本中有以下任务:

- name: Install EPEL repo.
  yum:
    name: "{{ epel_repo_url }}"
    state: present
    register: result
    until: '"failed" not in result'
    retries: 5
    delay: 10
Run Code Online (Sandbox Code Playgroud)

我可以传递给州的另一个值是"已安装".两者有什么区别?这里提供了一些文档:http://docs.ansible.com/ansible/yum_module.html

Yog*_*rji 16

状态为" 存在 "和" 已安装 "可互换使用.它们都做同样的事情,即它将确保安装你的案例'yum'中的所需包.

状态为" 最新 "表示除了安装之外,如果它不是最新的可用版本,它将继续更新.

无论何时构建堆栈/应用程序或进行生产,始终建议使用" Present "或" Installed "状态.这是因为软件更新,无论是您的应用程序部署还是依赖版本,它与服务器配置无关,并且可能真正破坏您的生产.

您可以在此处阅读并了解更多相关信息.


Zle*_*ni 14

他们做同样的事情,他们是彼此的别名,在yum模块的源代码中看到这个评论:

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

以及如何在代码中使用它们:

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
Run Code Online (Sandbox Code Playgroud)

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


ven*_*mus 5

在 2.x 中installed, 和removed已被弃用,取而代之的是presentabsent,并且在 Ansible 2.9 之后不再可用