我正在使用Ansible(v2.1.2)配置CentOS 7机器 . 为此,我需要确保在此计算机上安装了给定程序包的存储库中可用的版本,并在需要时安装和升级/降级程序包 . 我以前跑过
- name: install pkg package
yum:
name: "{{ pkg }}"
state: latest
但这只会安装最新版本(在某些版本的Ansible上,甚至不是https://github.com/ansible/ansible-modules-core/issues/4229),而不是降级 .
另一方面,我能做到
- name: install pkg package
yum:
name: "{{ pkg }}"
state: present
- name: sync pkg version with repo
command: yum distro-sync -y "{{ pkg }}"
这就像一个魅力,唯一的不便是Ansible总是将任务显示为 changed
,即使发行版同步实际上没有做任何事情
changed: [fake.host.com] => {"changed": true, "cmd": ["yum", "distro-sync", "-y", "mlocate"], "delta": "0:00:00.994328", "end": "2017-07-21 15:58:50.924873", "invocation": {"module_args": {"_raw_params": "yum distro-sync -y \"mlocate\"", "_uses_shell": false, "chdir": null, "creates": null, "executable": null, "removes": null, "warn": true}, "module_name": "command"}, "rc": 0, "start": "2017-07-21 15:58:49.930545", "stderr": "", "stdout": "Loaded plugins: fastestmirror\nLoading mirror speeds from cached hostfile\n * base: mirror.vorboss.net\n * epel: mirrors.coreix.net\n * extras: mirror.vorboss.net\n * updates: ftp.nluug.nl\nNo packages marked for distribution synchronization", "stdout_lines": ["Loaded plugins: fastestmirror", "Loading mirror speeds from cached hostfile", " * base: mirror.vorboss.net", " * epel: mirrors.coreix.net", " * extras: mirror.vorboss.net", " * updates: ftp.nluug.nl", "No packages marked for distribution synchronization"], "warnings": ["Consider using yum module rather than running yum"]}
更改的消息也会建议使用Ansible YUM module docs,但它似乎没有distro-sync选项 .
当没有更改而不是 changed
时,有没有办法让它显示 ok
?
1 回答
您可以注册发行版同步任务的标准输出并评估它是否实际上对
changed_when
做了任何事情 .我正在使用CentOS 6进行测试,所以'没有标记为分发同步的软件包'可能在您的系统上有所不同 .