我有像这样在本地主机上运行的 ansible 任务
- name: add docker repository
apt_repository:
repo: "deb [arch=amd64] https://download.docker.com/linux/debian {{ ansible_facts['ansible_distribution_release'] }} stable"
state: present
filename: docker-ce
Run Code Online (Sandbox Code Playgroud)
我希望使用变量ansible_facts['ansible_distribution_release']
来获取操作系统发行版名称,在我的例子中,它应该是buster。但它遇到了这样的错误
“该任务包含一个带有未定义变量的选项。错误是:‘dict object’没有属性‘ansible_distribution_release’
我尝试直接使用{{ ansible_distribution_release }}
,有效
repo: "deb [arch=amd64] https://download.docker.com/linux/debian {{ ansible_distribution_release }} stable"
Run Code Online (Sandbox Code Playgroud)
然后我想我应该只直接访问事实,而不是作为变量 ansible_facts 的键来访问它,但是后来我阅读了官方文档,我看到了这样的用例
{{ ansible_facts['devices']['xvda']['model'] }}
这让我怀疑我对 ansible 变量的理解有问题
我试图不在, ie,ansible_distribution_release
中引用,但没有运气[]
ansible_facts[ansible_distribution_release]
我运行下面的命令
$ ansible localhost -m setup -a "filter=ansible_distribution_release"
localhost | SUCCESS => {
"ansible_facts": {
"ansible_distribution_release": "buster"
},
"changed": false
}
Run Code Online (Sandbox Code Playgroud)
从而证明确实有一个名为ansible_distribution_release
under的属性ansible_facts
。 …
ansible ×1