【问题标题】:How to do the equivalent of `sudo apt-get update && sudo apt-get upgrade -y` using Ansible's `apt` module?如何使用 Ansible 的 apt 模块执行相当于 sudo apt-get update && sudo apt-get upgrade -y 的操作?
【发布时间】:2019-08-29 16:12:54
【问题描述】:

我在配置 Ansible 的 apt 模块时遇到了困难,以便它完全等同于以下命令行:

sudo apt-get update && sudo apt-get upgrade -y

到目前为止我最好的尝试是这样的:

- name: update and upgrade packages
  apt:
    force_apt_get: yes
    name: "*"
    only_upgrade: yes
    state: latest
    update_cache: yes

但是,这会继续安装我之前使用 sudo apt-get remove [name] 删除的软件包。

我如何告诉 Ansible 只升级那些已经安装的包?

我正在使用 Ansible 2.8.4 和 Python 3.7.4。遥控器是 Ubuntu Server 18.4.3。手动运行 apt-get 命令时一切正常。

【问题讨论】:

    标签: ubuntu ansible apt ubuntu-server


    【解决方案1】:

    我必须建议你不要在你的剧本中使用force_apt_get: yes。因为 Ansible 有专门为此目的而设计的 apt 模块。我在下面使用 apt 完成了这项工作。

    在剧本中,您可以像这样更新和升级:

    - name: Update and upgrade apt packages
      become: true
      apt:
        upgrade: yes
        update_cache: yes
    

    此外,您还可以删除不再需要的依赖项。

    - name: Remove useless packages from the cache
      apt:
         autoclean: yes
    
    - name: Remove dependencies that are no longer required
      apt:
         autoremove: yes
    

    【讨论】:

    • 我听从了你的所有建议,但结果还是一样:我刚刚删除的软件包在重新安装之前已经删除了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-09
    • 2013-10-04
    • 1970-01-01
    • 1970-01-01
    • 2016-07-12
    • 2023-01-17
    相关资源
    最近更新 更多