【发布时间】:2023-02-22 17:44:46
【问题描述】:
我不是 Ansible 的专家,我试图通过 Ansible 安装一个巧克力包,只有在不存在的情况下。我试图通过使用 chocolatey 中的事实来确定是否安装了 Git 来实现这一点。如果 Git 实际上不存在,请运行任务来安装它:
- name: Gather facts from chocolatey
win_chocolatey_facts:
- name: Install git
win_chocolatey:
name: git.install
when: ansible_chocolatey['packages'] != "git.install"
这是 chocolatey facts 的输出,我可以在其中看到我的机器上当前安装的软件包:
"ansible_facts": {
"ansible_chocolatey": {
"config": {
......
},
"feature": {
....
},
"outdated": [
{
.....
},
],
"packages": [
{
"package": "chocolatey-compatibility.extension",
"version": "1.0.0"
},
{
"package": "chocolatey-core.extension",
"version": "1.4.0"
},
{
"package": "chocolatey-dotnetfx.extension",
"version": "1.0.1"
},
{
"package": "ruby",
"version": "3.1.3.1"
},
.....
.....
我得到的错误是:
fatal: [ip-x.x.x.x.eu-west-2.compute.internal]: FAILED! => {"msg": "The conditional check 'ansible_chocolatey['packages'] != "git.install"' failed.
The error was: error while evaluating conditional (ansible_chocolatey['packages'] != "git.install" is undefined\n\n...
我可以帮助实现这一目标吗?
如果一台机器上没有 Git 包,我希望安装它,如果已经安装了 Git,我会跳过这个任务
【问题讨论】:
标签: ansible ansible-facts chocolatey