What triggers a “changed: true” when installing a package?
我有几个使用
相关的剧本部分:
1 2 3 | - name: install logstash on debian apt: deb=/tmp/logstash.deb when: ansible_os_family =="Debian" |
两台机器的详细输出是:
1 2 3 4 5 6 7 8 9 10 | TASK: [install logstash on debian] ******************************************** changed: [eu5.example.com] => {"changed": true,"stderr":"","stdout":"(Reading database ... 45337 files and directories currently installed.) Preparing to unpack /tmp/logstash.deb ... Unpacking logstash (1:2.0.0-beta3-1) over (1:2.0.0-beta3-1) ... Setting up logstash (1:2.0.0-beta3-1) ... Processing triggers for systemd (215-17+deb8u2) ... "} TASK: [install logstash on debian] ******************************************** ok: [eu2.example.com] => {"changed": false,"stderr":"","stdout":""} |
触发
-
每次都要运行
apt 命令,无论是否安装了包(在这种情况下eu5 的行为是正常的,eu2 不是) - 或者检查软件包是否已安装并且是否已跳过(在这种情况下,上面的OK / not OK行为被切换)
直接安装:
1 2 3 4 5 6 | [root@eu2:~]# dpkg -i /tmp/logstash.deb (Reading database ... 232343 files and directories currently installed.) Preparing to unpack /tmp/logstash.deb ... Unpacking logstash (1:2.0.0-beta3-1) over (1:2.0.0-beta3-1) ... Setting up logstash (1:2.0.0-beta3-1) ... Processing triggers for systemd (227-2) ... |
这表明每次都会重新安装软件包(因此
无论何时安装,升级或删除软件包,
1 2 3 4 5 6 | - command: dpkg -s logstash register: logstash_available ignore_errors: True - name: install logstash on debian apt: deb=/tmp/logstash.deb when: logstash_available.rc != 0 |