我试试这个
- name: Install required packages
shell: "apt-get instal linux-headers-{{ ansible_kernel }}"
然而得到这个
{"msg": "The task includes an option with an undefined variable. The error was: 'ansible_kernel' is undefined\
我可以通过查看这个变量
ansible -i myinventoryfile myhost -m setup | grep kernel
并且
ansible -i myinventoryfile myhost -m shell -a "uname -r"
我怎样才能让它工作?
答案1
对我有用。
% cat facts.yml
#!/usr/bin/env ansible-playbook
- name: test
hosts: somehost.example.edu
tasks:
- debug: var=ansible_kernel
- shell: "echo {{ ansible_kernel }} > /tmp/thisisverybaddonotuse"
% ./facts.yml
PLAY [test] ***
TASK [Gathering Facts] ***
ok: [somehost.example.edu]
TASK [debug] ***
ok: [somehost.example.edu] => {
"ansible_kernel": "3.10.0-693.21.1.el7.x86_64"
}
TASK [command] ***
changed: [somehost.example.edu]
PLAY RECAP ***
somehost.example.edu : ok=3 changed=1 unreachable=0 failed=0
% ssh somehost.example.edu "cat /tmp/thisisverybaddonotuse"
3.10.0-693.21.1.el7.x86_64
您可能没有收集事实,或者正在做一些从您发布的有限信息中不清楚的事情。