私はこれを試してみます
- 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
事実を収集していない場合もあり、投稿した制限された情報だけでは明確でないことをしている場合もあります。