0

I try this

- name: Install required packages
 shell: "apt-get instal linux-headers-{{ ansible_kernel }}"

However getting this instead

{"msg": "The task includes an option with an undefined variable. The error was: 'ansible_kernel' is undefined\

I can can see this variable via

ansible -i myinventoryfile myhost -m setup | grep kernel

and also

ansible -i myinventoryfile myhost -m shell -a "uname -r"

how can I get this working ?

0

Works for me.

% 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

Possibly you are not gathering facts, or are otherwise doing something that is unclear from the limited information in your posting.

  • "vagrant+ansible" on linux is the environment in which I do not have "ansible_local" provisioning.I am trying to make remote deployment. – hakkican Mar 29 '18 at 5:26
  • In my custom inventory file "gather_facts: false".This is not the case.It appears to be I forget to define "var=ansible_kernel" part in my ansible role.I add this to "vars/main.yml" it is ok now. Do I need to put this in original message at the top or leave it here.kind of new to this place – hakkican Mar 29 '18 at 7:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.