AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 1055193
Accepted
Nstevens
Nstevens
Asked: 2021-02-27 04:42:12 +0800 CST2021-02-27 04:42:12 +0800 CST 2021-02-27 04:42:12 +0800 CST

如何用ansible升级单个包?

  • 772

我正在尝试编写一个仅升级linux-generic软件包但无法找到使其实际工作的魔法咒语的 ansible 剧本。通过这个游戏,我得到了parameters are mutually exclusive: deb|package|upgrade谷歌建议的错误,这upgrade: full不是针对单个包的:

  - name: Check if linux-generic is installed
    command: dpkg -l linux-generic
    register: pkg_chk

  - name: update kernel if installed
    when: pkg_chk.rc == 0
    apt:
      update_cache: yes
      autoremove  : yes
      autoclean   : no
      upgrade     : full
      dpkg_options: 'force-confold,force-confdef'
      name        : linux-generic

删除upgrade: full运行播放...

TASK [update kernel if installed] **********************************************************
ok: [vivaldi.fammed.wisc.edu]

但是,当我登录到机器并运行aptitude full-upgrade它时,显示 ansible 没有做任何事情:

# aptitude full-upgrade
The following NEW packages will be installed:
  linux-headers-4.4.0-203{a} linux-headers-4.4.0-203-generic{a}
  linux-image-4.4.0-203-generic{a} linux-modules-4.4.0-203-generic{a}
  linux-modules-extra-4.4.0-203-generic{a}

好的,所以我想我只是将command:模块扔给它并使用裸apt命令,但是命令字符串存在一些问题,我没有正确转义。

  - name: upgrade linux-generic
    when: pkg_chk.rc == 0
      command: apt-get install -y --only-upgrade -o Dpkg::Options::='force-confdef' -o Dpkg::Options::='force-confold' linux-generic
      register: install_chk

  - name: autoremove linux-generic
    when: install_chk.rc == 0
      command: apt-get -y autoremove -o Dpkg::Options::='force-confdef' -o Dpkg::Options::='force-confold'
      register: auto_chk

这会产生这个错误:

Syntax Error while loading YAML.
  mapping values are not allowed in this context
    The error appears to be in '/usr/src/ansible/tests/upgrade-kernel-only.yml': line 24, column 12, but may
    be elsewhere in the file depending on the exact syntax problem.
    
    The offending line appears to be:
    
        when: pkg_chk.rc == 0
          command: apt-get install -y --only-upgrade -o Dpkg::Options::='force-confdef' -o Dpkg::Options::='force-confold' linux-generic
               ^ here

我试过转义: =字符,以及替换双引号和单引号。任何人都知道如何让这个工作?

debian ansible
  • 1 1 个回答
  • 2594 Views

1 个回答

  • Voted
  1. Best Answer
    basekat
    2021-02-27T05:34:02+08:002021-02-27T05:34:02+08:00

    您是否有任何具体原因不考虑 ansible 包模块,例如

    - name: Install linux-generic
      package:
        name: linux-generic
        state: present
    

    就 ansible 错误而言,您必须将命令用双引号引起来,因为您在内部使用单引号:

     - name: upgrade linux-generic
        when: pkg_chk.rc == 0
          command: "apt-get install -y --only-upgrade -o Dpkg::Options::='force-confdef' -o Dpkg::Options::='force-confold' linux-generic"
          register: install_chk
    
      - name: autoremove linux-generic
        when: install_chk.rc == 0
          command: "apt-get -y autoremove -o Dpkg::Options::='force-confdef' -o Dpkg::Options::='force-confold'"
          register: auto_chk
    
    • 2

相关问题

  • 关闭 FTP

  • 如何在同一台电脑上从 putty 连接 debian vmware

  • debian- 文件到包的映射

  • Debian Ubuntu 网络管理器错误 [关闭]

  • 为本地网络中的名称解析添加自定义 dns 条目

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve