我正在尝试编写一个仅升级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
我试过转义:
=
字符,以及替换双引号和单引号。任何人都知道如何让这个工作?
您是否有任何具体原因不考虑 ansible 包模块,例如
就 ansible 错误而言,您必须将命令用双引号引起来,因为您在内部使用单引号: